-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoop3.cpp
47 lines (43 loc) · 1.27 KB
/
oop3.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
/* The OOP Concepts Notes */
#include <iostream>
using namespace std;
//1. Classes are to be declared outside main()
class Employee
{
// By default, the members are private if not specified
// Class needs to be terminated with ;
public:
string Name;
int Age;
int Basic_Salary;
//constructor function to initialize the class members
Employee(string name, int age, int sal)
{
Name = name;
Age = age;
Basic_Salary = sal;
}
// method inside a class that prints out its values
void show_details()
{
int pf = Basic_Salary * (0.15);
int HRA = Basic_Salary * (0.1);
int SplAllowance = Basic_Salary * (0.3);
int Total = Basic_Salary + HRA + SplAllowance;
cout << "Name : " << Name << endl;
cout << "Age : " << Age << endl;
cout << "Salary : " << Basic_Salary << endl;
cout << "Provident Fund :" << pf << endl;
cout << "H.R.A : " << HRA << endl;
cout << "Special Allowance :" << SplAllowance << endl;
cout << "Total Salary :" << Total << endl;
}
};
int main()
{
// creating an object of the class.
Employee emp1 = Employee("Sreenivas", 57, 23456);
// calling public function of class.
emp1.show_details();
return 0;
}