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