-
Notifications
You must be signed in to change notification settings - Fork 16
/
student.h
80 lines (60 loc) · 1.81 KB
/
student.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <string>
namespace summercamp {
class Person
{
public:
Person(const std::string& name="admin",int age=0)
:_name(name),_age(age){}
virtual ~Person(){}
virtual std::string type()const{return "Person";}
virtual std::string introduction()const{
return type()+"[name:"+_name+", age:"
+std::to_string(age())+"]";
}
std::string& name(){return _name;}
const std::string& name()const{return _name;}
int& age(){return _age;}
int age()const{return _age;}
protected:
std::string _name;
int _age;
};
class SchoolInterface
{
public:
SchoolInterface(std::string name="manager")
: managerName(name){
}
virtual const std::string& getSchoolName()const=0;
std::string managerName;
};
class Student : public Person,public SchoolInterface
{
public:
Student(const std::string& name="admin",int age=0,
const std::string& manager="manager",
const std::string& school="none") : Person(name,age), SchoolInterface(manager),_school(school){}
virtual const std::string& getSchoolName()const {return _school;}
std::string& school(){return _school;}
const std::string& school()const{return _school;}
virtual std::string type()const{return "Student";}
virtual std::string introduction()const{
return type()+"[name:"+_name+
", age:"+std::to_string(age())+
", manager:"+managerName+
", school:"+school()+"]";
}
operator std::string()const{return introduction();}
protected:
std::string _school;
};
inline std::ostream& operator<<(std::ostream& os,const Student& student)
{
os<<student.introduction();
return os;
}
}//end of namespace
#endif // STUDENT_H