Home / utk / cs102 / fa16 / labf / code_snippets / simple_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
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

class student {
	public:
		//Mutators
		void set_firstname(const string&);
		void set_lastname (const string&);
		void set_age      (const unsigned int&);

		//Accessors
		string       get_firstname() const;
		string       get_lastname () const;
		unsigned int get_age      () const;
		
	private:
		string first_name, last_name;
		unsigned int age;
};

int main() {
	student s1, s2;

	s1.set_firstname("Clara");
	s1.set_lastname ("Nguyen");

	s2.set_firstname("Caleb");
	s2.set_lastname ("Williamson");

	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_age(const unsigned int& value) {
	age = value;
}

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

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

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