Anda di halaman 1dari 6

C++ programing Lab

File name: program10.cpp

PROGRAM 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 a class 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 file using namespace std; class employee //class() definition { public: char name[100]; int salary; void get() { cout<<"enter name and salary of employee:"; //display statement cin>>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"<<"his salary:"<<"\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

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

C++ programing Lab

File name: program9.cpp

PROGRAM NO. 9
Objective: A hospital wants to create a database regarding its indoor patients. The information to store include a) Name of the patient b) Date of admission c) Date of discharge Create a structure to store the date (year, month and date as its members). Create a base class to store the above information. The member function should include functions to enter information and display a list of all the patients in the database. Create a derived class to store the age of the patients. List the information about all
SBIT/CSE/IV/C++ PROGRAMING/CSE-206-F CSE/10/409

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 file using 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

C++ programing Lab

cout<<"\nPatient is pediatric !!!"; } else { cout<<"\npatient is greater than 12"; } } int main() { age a; a.getdata(); a.display(); return 0; }

//main() function

//end of main()

OUTPUT

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

CSE/10/409

C++ programing Lab

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

CSE/10/409

Anda mungkin juga menyukai