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

Class Student

week09/examples/firstclass.cpp:4–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <cstring>
3
4class Student
5{
6 public:
7 char name[4];
8 int born;
9 bool male;
10 void setName(const char * s)
11 {
12 if (s == NULL)
13 {
14 std::cerr << "The input is NULL." << std::endl;
15 return;
16 }
17 size_t len = sizeof(name) - 1;
18 strncpy(name, s, len);
19 name[len] = '\0';
20 }
21 void setBorn(int b)
22 {
23 if (b >= 1990 && b <= 2020 )
24 born = b;
25 else
26 std::cerr << "The input b is " << b << ", and should be in [1990, 2020]." << std::endl;
27 }
28 void setGender(bool isMale)
29 {
30 male = isMale;
31 }
32 void printInfo()
33 {
34 std::cout << "Name: " << name << std::endl;
35 std::cout << "Born in " << born << std::endl;
36 std::cout << "Gender: " << (male ? "Male" : "Female") << std::endl;
37 }
38};
39
40int main()
41{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected