You are on page 1of 21

EXP11_1 INPUT #include<iostream.h> #include<conio.

h> class student { int rollno; char name[20]; public: void accepts() { cout<<"Student:"<<endl; cout<<"Enter Roll no:\t"; cin>>rollno; cout<<"Enter name:\t"; cin>>name; } void displays() {

cout<<"Student:"<<endl; cout<<"\nRoll no:\t"<<rollno; cout<<"\nName\t"<<name; } }; class teacher {

char name[20],subject[20]; public: void acceptt() { cout<<endl<<"Teacher:"<<endl; cout<<"Enter name"; cin>>name; cout<<"Enter subject"; cin>>subject; } void displayt() { cout<<endl<<"Teacher:"<<endl; cout<<"\nName"<<name; cout<<"\nSubject"<<subject; } }; class info:public student,public teacher { public: void displayi() { cout<<"Info ="<<endl; } }; void main() {

clrscr(); info i; i.accepts(); i.acceptt(); i.displayi(); i.displays(); i.displayt(); getch(); } OUTPUT Student: Enter Roll no: 162 Enter name: ashj

Teacher: Enter namekkj Enter subjecthjas Info = Student:

Roll no:

162

Name ashj Teacher:

Namekkj Subjecthjas

EXP11_2 INPUT #include<iostream.h> #include<conio.h> class employee { char emp_id[20],name[20]; public: void accepte() { cout<<"Enter Employee Id:\t"; cin>>emp_id; cout<<"Enter Employee name"; cin>>name; } void displaye() { cout<<"\nEmployee Id:\t"<<emp_id; cout<<"\nEmployee name"<<name; } }; class emp_union { char member_id[20]; public: void acceptu() {

cout<<"Enter Member Id:\t"; cin>>member_id; } void displayu() { cout<<"\nMember Id:\t"<<member_id; } }; class emp_info:public employee,public emp_union { long int salary; public: void accepti() { cout<<"Enter Basic Salary:\t"; cin>>salary; } void displayi() { cout<<"\nBasic salary:\t"<<salary; } }; void main() { clrscr(); emp_info i; i.accepte();

i.acceptu(); i.accepti(); i.displaye(); i.displayu(); i.displayi(); getch(); } OUTPUT Enter Employee Id: M23

Enter Employee nameABC Enter Member Id: Enter Basic Salary: 1623 1234

Employee Id: M23 Employee nameABC Member Id: 1623

Basic salary: 1234

EXP11_3 INPUT #include<iostream.h> #include<conio.h> #include<string.h> class magazine { public: char nm[20],dm[20]; int pm; void acceptm() { cout<<"\nMAGAZINE:"<<endl; cout<<"Enter name "; cin>>nm; cout<<"Enter duration "; cin>>dm; strupr(dm); cout<<"Enter price"; cin>>pm; } void displaym() { cout<<"\nMAGAZINE:"<<endl;

cout<<"\nname "<<nm; cout<<"\nduration "<<dm;

cout<<"\nprice"<<pm;

} }; class newspaper { public: char nn[20],dn[20]; int pn; void acceptn() { cout<<"NEWSPAPER:"<<endl; cout<<"Enter name "; cin>>nn; cout<<"Enter duration "; cin>>dn; strupr(dn); cout<<"Enter price"; cin>>pn; } void displayn() {

cout<<"\nNEWSPAPER:"<<endl; cout<<"\nname "<<nn; cout<<"\nduration "<<dn; cout<<"\nprice"<<pn;

} }; class journal { public: char nj[20],dj[20]; int pj;

void acceptj() { cout<<"JOURNAL:"<<endl; cout<<"Enter name "; cin>>nj; cout<<"Enter duration "; cin>>dj; strupr(dj); cout<<"Enter price"; cin>>pj; } void displayj() { cout<<"\nJOURNAL:"<<endl; cout<<"\nname "<<nj; cout<<"\nduration "<<dj; cout<<"\nprice"<<pj; }

}; class periodical:public newspaper,public journal,public magazine { public: magazine m[2]; newspaper n[2]; journal j[2]; int i; void accept() { for(i=0;i<2;i++) { m[i].acceptm(); } for(i=0;i<2;i++) { n[i].acceptn(); } for(i=0;i<2;i++) { j[i].acceptj(); } } void display() { for(i=0;i<2;i++) {

if(strcmp(m[i].dm,"DAILY")==0) { m[i].displaym(); } } for(i=0;i<2;i++) { if(strcmp(n[i].dn,"DAILY")==0) { n[i].displayn(); } } for(i=0;i<2;i++) { if(strcmp(j[i].dj,"DAILY")==0) { j[i].displayj(); } } } }; void main() { clrscr(); periodical p; p.accept(); p.display();

getch(); } OUTPUT

MAGAZINE: Enter name ABC Enter duration Daily Enter price123

MAGAZINE: Enter name DEF Enter duration WeeklY Enter price234 NEWSPAPER: Enter name GHI Enter duration Daily Enter price3 NEWSPAPER: Enter name JKL Enter duration daily Enter price2 JOURNAL: Enter name MNO Enter duration Month;y Enter price567 JOURNAL: Enter name PQR

Enter duration Weekly Enter price345

MAGAZINE:

name ABC duration DAILY price123 NEWSPAPER:

name GHI duration DAILY price3 NEWSPAPER:

name JKL duration DAILY price2

EXP11_4 INPUT #include<iostream.h> #include<conio.h> class acc { long int accno; char name[20]; public: void accepta() { cout<<"Enter Account Number"; cin>>accno; cout<<"Enter Name"; cin>>name; } void displaya() { cout<<"\nAccount Number"<<accno; cout<<"\nName"<<name; } }; class saving:virtual public acc { long int bals; public: void accepts()

{ cout<<"Enter Balance"; cin>>bals; } void displays() { cout<<"\nBalance"<<bals; } };

class current:virtual public acc { long int balc; public: void acceptc() { cout<<"Enter Balance"; cin>>balc; } void displayc() { cout<<"\nBalance"<<balc; } };

class fd:public saving,public current {

long int bald,d; public: void acceptd() { cout<<"Enter Balance"; cin>>bald; cout<<"Enter the time duration"; cin>>d; } void displayd() { cout<<"\nBalance"<<bald; cout<<"\nTime Duration"<<d; } }; void main() { int i; fd f; clrscr(); f.accepta(); cout<<"1 for savings account\n2 for current account\n3for fixed deposit account"; cin>>i; switch(i) { case 1: f.accepts();

f.displaya(); f.displays(); break; case 2: f.acceptc(); f.displaya(); f.displayc(); break; case 3: f.acceptd(); f.displaya(); f.displayd(); break; default: break; } getch();

} OUTPUT Enter Account Number12345 Enter Nameabc 1 for savings account 2 for current account 3for fixed deposit account3 Enter Balance45668 Enter the time duration67

Account Number12345 Nameabc Balance45668 Time Duration67

EXP11_5 INPUT #include<iostream.h> #include<conio.h> class employee { char name[20],id[20]; public: void accepte() { cout<<"Enter Name and ID"; cin>>name>>id; } void displaye() { cout<<"\nName"<<name<<"ID"<<id; } }; class worker:public virtual employee { long int salary ; public: void acceptw() { cout<<"Enter Salary"; cin>>salary; }

void displayw() { cout<<"\nSalary"<<salary; } }; class manager:public virtual employee { long int allowance; public: void acceptm() { cout<<"Enter allowance"; cin>>allowance; } void displaym() { cout<<"\nAllowance"<<allowance; } }; void main() { int i; clrscr(); worker w; manager m; w.accepte(); cout<<"Enter 1 for worker\n2 for manager";

cin>>i; switch(i) { case 1: w.acceptw(); w.displaye(); w.displayw(); break; case 2: m.acceptm(); m.displaye(); m.displaym(); break; default: break; } getch(); } OUTPUT Enter Name and IDabc 12 Enter 1 for worker 2 for manager1 Enter Salary12345

NameabcID12 Salary12345