| 4 | using namespace std; |
| 5 | |
| 6 | class Student |
| 7 | { |
| 8 | private: |
| 9 | char * name; |
| 10 | int born; |
| 11 | bool male; |
| 12 | public: |
| 13 | Student() |
| 14 | { |
| 15 | name = new char[1024]{0}; |
| 16 | born = 0; |
| 17 | male = false; |
| 18 | cout << "Constructor: Person()" << endl; |
| 19 | } |
| 20 | Student(const char * initName, int initBorn, bool isMale) |
| 21 | { |
| 22 | name = new char[1024]; |
| 23 | setName(initName); |
| 24 | born = initBorn; |
| 25 | male = isMale; |
| 26 | cout << "Constructor: Person(const char, int , bool)" << endl; |
| 27 | } |
| 28 | ~Student() |
| 29 | { |
| 30 | cout << "To destroy object: " << name << endl; |
| 31 | delete [] name; |
| 32 | } |
| 33 | |
| 34 | void setName(const char * s) |
| 35 | { |
| 36 | if (s == NULL) |
| 37 | { |
| 38 | std::cerr << "The input is NULL." << std::endl; |
| 39 | return; |
| 40 | } |
| 41 | size_t len = 1024 - 1; |
| 42 | strncpy(name, s, len); |
| 43 | name[len] = '\0'; |
| 44 | } |
| 45 | void setBorn(int b) |
| 46 | { |
| 47 | if (b >= 1990 && b <= 2020 ) |
| 48 | born = b; |
| 49 | else |
| 50 | std::cerr << "The input b is " << b << ", and should be in [1990, 2020]." << std::endl; |
| 51 | } |
| 52 | // the declarations, the definitions are out of the class |
| 53 | void setGender(bool isMale); |
| 54 | void printInfo(); |
| 55 | }; |
| 56 | |
| 57 | void Student::setGender(bool isMale) |
| 58 | { |
nothing calls this directly
no outgoing calls
no test coverage detected