-
Notifications
You must be signed in to change notification settings - Fork 0
/
02_inheritance.cpp
58 lines (49 loc) · 1.34 KB
/
02_inheritance.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
#include <iostream>
#include <string>
using namespace std;
class Person {
public:
Person(string n, string c) : name(n), nat_code(c) {}
string get_name() { return name; }
string get_nat_code() { return nat_code; }
private:
string name;
string nat_code;
};
class Student : public Person {
public:
Student(string n, string c, string sid)
: Person(n, c), student_id(sid) {}
string get_id() { return student_id; }
private:
string student_id;
};
class Employee : public Person {
public:
Employee(string n, string c, string ec, int bs)
: Person(n, c), emp_code(ec), base_salary(bs) {}
string get_emp_code() { return emp_code; }
int calc_salary(int hours_worked) {
int hourly_pay = base_salary / 240;
return base_salary + (hours_worked - 240) * hourly_pay * 1.4;
}
private:
string emp_code;
int base_salary;
};
class Prefessor : public Employee {
public:
Prefessor(string n, string c, string ec, int bs, int ut)
: Employee(n, c, ec, bs), units_taught(ut) {}
int calc_salary(int hours_worked) {
int extra_units = units_taught - 10;
return Employee::calc_salary(hours_worked) + extra_units * 50000;
}
private:
int units_taught;
};
int main() {
Prefessor f("ghodrat", "333333", "1235", 800000, 13);
cout << f.get_name() << endl;
cout << f.calc_salary(263) << endl;
}