Home / utk / cs102 / fa16 / labf / code_snippets / student_class_example.cpp
Directory Listing
misc
circle.cpp
class_demonstration.cpp
layout.cpp
simple_class_example.cpp
student_class_example.cpp
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
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

class student {
	public:
		//Set Functions (Mutator)
		void set_firstname(const string&);
		void set_lastname (const string&);
		void set_year     (const int&);
		void set_age      (const unsigned int&);
		void set_gender   (const string&);

		//Get Functions (Accessors)
		string       get_firstname() const;
		string       get_lastname()  const;
		int          get_year()      const;
		unsigned int get_age()       const;
		string       get_gender()    const;

	private:
		string first_name, last_name, gender;
		int year;
		unsigned int age;
};

int main() {
	student s1, s2;
	s1.set_firstname("Clara");
	s1.set_lastname("Nguyen");

	s2.set_firstname("Bill");
	s2.set_lastname("Gates");

	cout << s1.get_lastname() << ", " << s1.get_firstname() << endl;
	cout << s2.get_lastname() << ", " << s2.get_firstname() << endl;
}

void student::set_firstname(const string& value) {
	first_name = value;
}

void student::set_lastname(const string& value) {
	last_name = value;
}

void student::set_year(const int& value) {
	year = value;
}

void student::set_age(const unsigned int& value) {
	age = value;
}

void student::set_gender(const string& value) {
	gender = value;
}

string student::get_firstname() const {
	return first_name;
}

string student::get_lastname() const {
	return last_name;
}

int student::get_year() const {
	return year;
}

unsigned int student::get_age() const {
	return age;
}

string student::get_gender() const {
	return gender;
}