2022 South China Normal University C + + programming (918) postgraduate examination final points tips phase I

Posted by bing_crosby on Sat, 11 Dec 2021 14:09:38 +0100

preface

Thanks to your love, I'm not a big man. Maybe many people don't understand why I want to share these materials selflessly. Isn't this helping competitors? In fact, it's not so. Because of your concern, I'll make my ideas public. Many mistakes I haven't made will be found and kindly pointed out to me at the same time, Everyone's correction every time is a promotion for me. If I don't post a blog, I may still adhere to the wrong idea of many knowledge points. Maybe I don't know why the score is so low after the test. Maybe it's the school's pressure on the score. I'm also half a programmer. I practiced in a factory for half a year and was busy with business development every day, The demand is always endless, and I want to do research in the direction I am interested in, so I resigned for the postgraduate entrance examination. I hope to go back to the campus, which is not so busy with business, and calm down to study. Of course, I prepared late, so it may also be cannon fodder, ~ far from it, in fact, programmers are naturally interested in open source and resent making wheels repeatedly. Then when reviewing, I found that I was not satisfied with the information, so I decided to do it myself.

choice question

In fact, the difficulty of 918 multiple-choice questions is increasing year by year, and the score is 45 points, which is nearly one third of the total score. Therefore, it is recommended that you pay more attention to it and watch it twice [918c + + summary of selection and blank filling questions] click , if you have time, you can draw your own mind map and connect the knowledge points. I think at least 18 of the 45 points are the discrimination of concepts, so I think the most effective way is to open the directory, look at each subheading and ask yourself what this is. What you can't remember is what you need to review. This stage may be more troublesome, But this should be the most effective way to solve the 18 points (I feel this is faster than brushing the question!!!), The second is to brush the questions, that is, to look at the above summary. I feel that if it is difficult this year, it may be in the following directions. If you feel that you can add in the comments:

  • Pointer and reference: in fact, this is also the difficulty of c + + foundation
EX: 
int &a[3]; // error
int &*p;   // error
int &&r;   // error
  • Pointers and constants: this one is written separately in our book, but it's disgusting to combine them together
EX:
const int *p    //Pointer to an integer constant whose value cannot be modified
int *const p    //Integer constant pointer, which cannot point to other variables, but the value can be modified
const int *const p  //A constant pointer to an integer constant. It cannot point to other vectors and cannot be modified
  • Friend: there is little space in the book, but it's easy to get confused, so we should pay attention to it
  • Operator overloading: concepts are difficult to remember and easy to miss
//Operator overloaded functions can be member functions or global functions of the overloaded class
//Overloading of an operator cannot change the number of operands of an operator.
//When a unary operator is overloaded into a member function, the function has no formal parameters
//If an overloaded function is designed as a member function of a class, its number of formal parameters is 1 less than the number of operands of the operator
  • Inheritance: it's not difficult, it's a required test site. Just remember this picture

    Pithy formula: the private permission will never change, the public inheritance right will not change, the protection inheritance will be protected, and the private inheritance will be private.
  • Dynamic binding and static binding: this book doesn't say much, but it belongs to virtual function and is one of the necessary test points. Therefore, it is suggested to understand these two points well
  • Multiple inheritance: This is not mentioned, but it belongs to the test site of inheritance. You can pay attention to it
  • Virtual basic class: it's not in this book, but the syllabus clearly stipulates that this is the test site. It's here in syllabus 8.4, so it must be learned

I want to say that the virtual keyword is required for the definition of virtual base class, but it does not necessarily need to use virtual functions. Don't confuse keywords with virtual functions

Programming problem

For programming problems, we basically take a file operation test every year, so we can also focus on this part. If we memorize the file operation, this 10 points will be given. Secondly, what I want to say is some of my personal views. I think we can have a lot of room to play when we write programming problems by handwriting. At the same time, teachers can see the quality of a person writing code, Because everyone has different ideas in writing code. In the face of the same problem, some people can use recursion or other better methods to solve it, while others can only be violent (this person is myself). Of course, this will not determine your score, but what I want to say is that so many people need to read the code one by one, If you use a common method, the teacher can see it at a glance. It's OK. If your code is long, the person who changes the paper needs to read your logic carefully. Finally, if it is still wrong, it is estimated to be zero. Therefore, I think programming specification is a good way to solve this problem. First, annotation is a very good thing (although I don't usually write, it's not cold to get points in the exam) , write the purpose of each function through comments, and then write the purpose before each judgment statement and loop statement, which can improve the efficiency of the examiner. Maybe he sees your purpose right, and he doesn't see the small defects in the code. Second, I think the more important point in the programming specification is unified naming. I also mentioned the naming rules in my previous blog, [naming method of small hump] click This is the naming rule of the company during my internship. You can refer to it. Finally, I take the first programming problem in 2021 as an example

#include <iostream>

using namespace std;
//1. Program to find out five different numbers a, B, C, D, e satisfying ABCD*E=DCBA
//Different from each other A B C D E

//purpose: bdifferent this function is used to judge whether ABCD is different
bool bdifferent(int aryList[4]){
    /*
    Here, the array is used to represent nArr[0] represents A, nArr[1] represents B, nArr[2] represents C, and nArr[3] represents D
    The most simple way is used in the code to see whether ABCD is different from each other. Another idea is provided here, but the time complexity is not as high as the most simple one
    for(int i=0;i<4;i++){
        int j=0;
        for(j=i;j<4;j++){
            if(aryList[i]==aryList[j]){
            return true
            }
        }
    }
    return false
    */
 	
    if(aryList[0]==aryList[1]||aryList[0]==aryList[2]||aryList[0]==aryList[3]||aryList[1]==aryList[2]||aryList[1]==aryList[3]||aryList[2]==aryList[3])  return true;
    return false;
}
//purpose: print ABCDE
void aryprint(int aryList[4],int nE){
    cout<<"ABCDE Is:"<<endl;
    for(int i=0;i<4;i++){
        cout<<aryList[i]<<" ";
    }
    cout<<nE<<endl;
}

int main()
{
    int aryList[4];//Create an array to store ABCD
    for(int i=1000;i<9999;i++){//Loop to get all four digits
        int y = 3;//Used to conveniently represent the array. The subscript arrList[3] represents D
        int nTmp1 = i;//Gets the current four digits
        //purpose: this loop is used to put the last digit of i into the array, and then divide nTmp1 by ten until all four digits are put into the array
        while(nTmp1!=0){
            aryList[y]=nTmp1%10;
            nTmp1/=10;
            y--;
        }
        //purpose: judge whether the current array ABCD is different. If it is the same, continue to enter the next cycle. If it is different, continue to execute the following code
        if(bdifferent(aryList)){
            continue;
        }
        //purpose: put the numbers in nTmp3 in reverse order. The number of nTmp3 represents DCBA
        int nTmp2 = i;
        int nTmp3 = 0;
        while(nTmp2!=0){
            int nNum=nTmp2%10;
            nTmp2/=10;
            nTmp3 = nTmp3*10 + nNum;
        }
        //purpose: simulate ABCD*E=DCBA
        for(int e=1;e<=9;e++){
            if((i*e)==nTmp3){
                aryprint(aryList,e);
                break;
            }

        }
    }
    return 0;
}



last

The above content is the first issue. If it is useful to you, please do the second issue
Launch a vote. In the next blog, do you want to see the analysis of test papers in 19 years or the summary of 918 programming questions

Topics: C++ Back-end