-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointer_to_object.cpp
52 lines (52 loc) · 1.03 KB
/
pointer_to_object.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
//write a cpp programme to declare an employee class.e\Employee class should have the member function to get employee details using pointer to object
#include<iostream>
using namespace std;
class employee
{
protected:
string name,compname;
char a[30],b[30];
int i,c,size,age;
public:
void getdetails();
};
void employee::getdetails()
{
cout<<"enter name of employee";
getline(cin,name);
cout<<"enter your age";
cin>>age;
getchar();
cout<<"enter company name";
getline(cin,compname);
}
class salary:public employee{
private:
float sal,annualsal;
public:
void getsal();
void disp();
};
void salary::getsal(){
cout<<"enter salary";
cin>>sal;
annualsal=sal*12;
}
void salary::disp()
{
cout<<"name of employee"<<name<<endl;
cout<<"age is"<<age<<endl;
cout<<"company name is"<<compname<<endl;
cout<<"annual slary is"<<annualsal<<endl;
}
int main()
{
int i;
salary *ptr=new salary[10];
for(i=1;i<=10;i++)
{
ptr[i].getdetails();
ptr[i].getsal();
ptr[i].disp();
}
}