Listing 19.8 demonstrates the members of the vectorclass that have been discussed so
far. You will see that the standard stringclass is used in this listing to simplify the
handling of strings. For more details about the stringclass, check your compiler’s
documentation.
LISTING19.8 Vector Creation and Element Access
0: #include <iostream>
1: #include <string>
2: #include <vector>
3: using namespace std;
4:
5: class Student
6: {
7: public:
8: Student();
9: Student(const string& name, const int age);
10: Student(const Student& rhs);
11: ~Student();
12:
13: void SetName(const string& name);
14: string GetName() const;
15: void SetAge(const int age);
16: int GetAge() const;
17:
18: Student& operator=(const Student& rhs);
19:
20: private:
21: string itsName;
22: int itsAge;
23: };
24:
25: Student::Student()
26: : itsName(“New Student”), itsAge(16)
27: {}
28:
29: Student::Student(const string& name, const int age)
30: : itsName(name), itsAge(age)
31: {}
32:
33: Student::Student(const Student& rhs)
34: : itsName(rhs.GetName()), itsAge(rhs.GetAge())
35: {}
36:
37: Student::~Student()
38: {}
39:
40: void Student::SetName(const string& name)
41: {
696 Day 19