Download - oops-Program 10-mdu

Transcript
Page 1: oops-Program 10-mdu

7/31/2019 oops-Program 10-mdu

http://slidepdf.com/reader/full/oops-program-10-mdu 1/6

C++ programing Lab

File name: program10.cppPROGRAM NO. 10

Objective: Make a class Employee with a name and salary. Make a class Manager

inherits from Employee. Add an instance variable, named department of type string.Supply a method to string that prints the manager name, department and salary. Make aclass executive inherits from manager. Supply a method to string that prints the string.“Executive “followed by the information stored in the manager super class object.Supply a test program that tests these classes and methods.

#include<iostream> //header fileusing namespace std;class employee //class() definition{

public:char name[100];int salary;void get(){cout<<"enter name and salary of employee:"; //display statementcin>>name>>salary;}};class manager: public employee{

public:char department[100];void in(){cout<<"enter the depatment of manager:";cin>>department;}void out(){cout<<"manager name:\n"<<name<<"\n"<<"his dept:\n"<<department<<"\n"<<"hissalary:"<<"\n"<<salary<<"\n";}};class executive:public manager {

public:void output(){cout<<"executive ";out();}};int main() //main() function{

SBIT/CSE/IV/C++ PROGRAMING/CSE-206-F CSE/10/409

Page 2: oops-Program 10-mdu

7/31/2019 oops-Program 10-mdu

http://slidepdf.com/reader/full/oops-program-10-mdu 2/6

C++ programing Lab

executive e;e.get();e.in();e.output();

return 0;} //end of main()

OUTPUT

SBIT/CSE/IV/C++ PROGRAMING/CSE-206-F CSE/10/409

Page 3: oops-Program 10-mdu

7/31/2019 oops-Program 10-mdu

http://slidepdf.com/reader/full/oops-program-10-mdu 3/6

Page 4: oops-Program 10-mdu

7/31/2019 oops-Program 10-mdu

http://slidepdf.com/reader/full/oops-program-10-mdu 4/6

C++ programing Lab

the toy store the age of the patients. List the information about all the pediatric patients (less than twelve years in age).

#include<iostream> //header fileusing namespace std;struct hospital //structure{char name[10];int dd_a;int mm_a;int yy_a;int dd_d;int mm_d;

int yy_d;};class patient //class declaration{

public:struct hospital h;void getdata();void display();};class age:public patient{

public:int age;void getdata();void display();};void age::getdata(){cout<<"Enter the name of the patient : ";cin>>h.name;cout<<"Enter the age of the patient : ";cin>>age;cout<<"Enter the date-month-year of addmission : ";cin>>h.dd_a>>h.mm_a>>h.yy_a;cout<<"Enter the date-month-year of discharge : ";cin>>h.dd_d>>h.mm_d>>h.yy_d;}void age::display(){cout<<"\nThe name of the patient : ";

puts(h.name);cout<<"\nThe date of addmission : "<<h.dd_a<<"-"<<h.mm_a<<"-"<<h.yy_a;cout<<"\nThe date of discharge : "<<h.dd_d<<"-"<<h.mm_d<<"-"<<h.yy_d;cout<<"\nThe age of the patient : "<<age;if(age<=12){SBIT/CSE/IV/C++ PROGRAMING/CSE-206-F CSE/10/409

Page 5: oops-Program 10-mdu

7/31/2019 oops-Program 10-mdu

http://slidepdf.com/reader/full/oops-program-10-mdu 5/6

C++ programing Lab

cout<<"\nPatient is pediatric !!!";}else{

cout<<"\npatient is greater than 12";}}int main() //main() function{age a;a.getdata();a.display();return 0;} //end of main()

OUTPUT

SBIT/CSE/IV/C++ PROGRAMING/CSE-206-F CSE/10/409

Page 6: oops-Program 10-mdu

7/31/2019 oops-Program 10-mdu

http://slidepdf.com/reader/full/oops-program-10-mdu 6/6

C++ programing Lab

SBIT/CSE/IV/C++ PROGRAMING/CSE-206-F CSE/10/409


Top Related