MCPcopy Create free account
hub / github.com/ShiqiYu/CPP / Student

Class Student

week09/examples/array.cpp:6–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4using namespace std;
5
6class 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
57void Student::setGender(bool isMale)
58{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected