-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqsn2b.txt
More file actions
67 lines (55 loc) · 1.97 KB
/
Copy pathqsn2b.txt
File metadata and controls
67 lines (55 loc) · 1.97 KB
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
#include <iostream>
#include <string>
using namespace std;
class Person {
public:
Person(int age, string firstname, string lastname) {
this->age = age;
this->firstname = firstname;
this->lastname = lastname;
}
void getValues() {
cout << "Age: " << age << endl;
cout << "First name: " << firstname << endl;
cout << "Last name: " << lastname << endl;
}
void setValues(int age, string firstname, string lastname) {
this->age = age;
this->firstname = firstname;
this->lastname = lastname;
}
private:
int age;
string firstname;
string lastname;
};
class Student : public Person {
public:
Student(int age, string firstname, string lastname, string institution, int year, string registration_number)
: Person(age, firstname, lastname) {
this->institution = institution;
this->year = year;
this->registration_number = registration_number;
}
void getValues() {
Person::getValues();
cout << "Institution: " << institution << endl;
cout << "Year of study: " << year << endl;
cout << "Registration number: " << registration_number << endl;
}
void setValues(int age, string firstname, string lastname, string institution, int year, string registration_number) {
Person::setValues(age, firstname, lastname);
this->institution = institution;
this->year = year;
this->registration_number = registration_number;
}
private:
string institution;
int year;
string registration_number;
};
int main() {
Student my_student(20, "Jake", "Mutuma", "University of ABC", 2, "12345");
my_student.getValues(); // Output values of student
return 0;
}