Sei sulla pagina 1di 14

Q.1 Develop an object oriented program in c++ to read the following information from the keyboard.

a)employee name

employee code

designation

years of experience

age

b)Construct an object oriented data base to carry out the following methods:

i)Build a master table

ii)List a table

iii)Insert a new entry

iv)Edit an entry

v)Delete old entry

vi)Search for a record that to be printed

Ansclass employee

public:

int age,yoe,ec;

char desi[20],en[20];

void get()

cout<<"\nEnter employee name:";

cin>>en;

cout<<"Enter age of employee=";

cin>>age;

cout<<"Enter employee code=";


cin>>ec;

cout<<"Enter designation of employee:";

cin>>desi;

cout<<"Enter years of experience:";

cin>>yoe;

void disp()

{ cout<< "Employee name is:"<<en<<endl;

cout<<"Age of employee is="<<age<<endl;

cout<<"Employee code is="<<ec<<endl;

cout<<"Designation of employee is:"<<desi<<endl;

cout<<"Years of experience is:"<<yoe<<endl;

};

int main()

{ employee E[100];

int n;

cout<<"Enter number of employee=";

cin>>n;

for(int i=1;i<=n;i++)

{ E[i].get();

E[i].disp(); }
}

b) class B1

{ public:

char en[30],desi[30];

void get1();

void disp1();

};

class B2

{ public:

int age,yoe ;

void get2();

void disp2();

};

class derived:public B1,public B2

{ int ec;

public:

derived()
{

ec=0;

void get();

void disp();

};

void B1::get1()

cout<<"Enter Employee name:\n";

cin>>en;

cout<<"Enter designation of employee:";

cin>>desi;

void B2::get2()

cout<<"Enter age of employee";

cin>>age;

cout<<"Enter years of experience=";

cin>>yoe;

void derived::get()

B1::get1();

B2::get2();

cout<<"Enter Employee code number=";


cin>>ec;

void B1::disp1()

cout<<en<<"\t"<<desi<<"\t";

void B2::disp2()

cout<<"\t"<<age<<"\t"<<yoe;

void derived::disp()

B1::disp1();

B2::disp2();

cout<<"\t\t"<<ec<<"\n";

int main()

{derived obj[50],temp;

int i,j,no,ch;

char ans,key[30];

j=-1;

do

{cout <<"\nMenu\n1.Build master


table\n2.Display\n3.Insert\n4.Delete\n5.Edit\n<<Search\n7.Exit\n";

cout<<"Enter your choice";

cin>>ch;
switch(ch)

case 1:

do

{j++;

obj[j].get();

cout<<"Do you want to enter another entry\n";

cin>>ans;

}while(ans=='y'||ans=='Y');

break;

case2:

cout<<"-----------------------------\n";

for(i=0;i<=j;i++)

obj[i].disp();

break;

case 3:

cout<<"Enter index where you want to insert\n";

cin>>no;

if(no<=j+1)

obj[j+1]=obj[no];

obj[no].get();
cout<<"Record inserted successfully";

j++;

else

cout<<"Error";

break;

case 4:

if(j!=-1)

cout<<"Enter index to delete record";

cin>>no;

if(no<=j)

for(i=no;i<=j;i++)

temp=obj[i];

obj[i]=obj[i+1];

j--;

else

cout<<"\nerror";

else

cout<<"\n No record to delete";


break;

case 5:

if(j!=1)

cout<<"\n Enter index to update:";

cin>>no;

if(no<=j)

obj[no].get();

cout<<"\n Record updated successfully";

else

cout<<"Such record is not in table";

else

{cout<<"Error....";}

break;

case 6:

cout<<"Enter name of employee to search in record";

cin>>key;

for(i=0;i<=j;i++)

if(strcmp(obj[i].en,key)==0)
{

cout<<"\n Record to reset:";

obj[i].disp();

break;

break;

}while(ch<7);

Q.2 Develop an oops program in C++ to create a library information system containing the following for
all books in library.

Accession number

Name of the author

Title of the book

Year of publication

Publisher’s name

Cost of book

Construct the database with suitable member function for intialising and destroying the data.
Ans class book

public:

int an,yop,cb;

char na[20],tb[20],p[20];

void get()

{ int n;

cout<<"Enter number of books=";

cin>>n;

for(int i=1;i<=n;i++)

cout<<"\nEnter author's name :";

cin>>na;

cout<<"Enter title of book=";

cin>>tb;

cout<<"Enter publisher's name =";

cin>>p;

cout<<"Enter accession number of book:";

cin>>an;

cout<<"Enter year of publication:";

cin>>yop;

cout<<"Enter cost of book:";

cin>>cb;

}
void disp()

{ cout<< "Author's name is:"<<na<<endl;

cout<<"Title of book is="<<tb<<endl;

cout<<"Publisher's name is="<<p<<endl;

cout<<"Book accession number is:"<<an<<endl;

cout<<"Year of publication is:"<<yop<<endl;

cout<<"Cost of book is:"<<cb<<endl;

};

int main()

{ book *b;

b=new book;

b->get();

b->disp();

delete b;

}
Q.3 Explain the following with syntactic rule?

i)Public inheritence

ii)Protected inheritance

iii)private inheritance

Ans Public Inheritence

*Each public member in the base class is public in the derived class.

* Each protected member in the base class is protected in the derived class.

* Each private member in the base class remains private in the derived class.

Class base class_name{

Class derived_class_name:public base_class_name

Private Inheritence

*Each public member in the base class is private in the derived class.

*Each protected member in the base class is private in the derived class.
*Each private member in the base class remains private in the base class and hence it is only visible in
the base class.

Class base class_name{

Class derived_class_name:private base_class_name

Protected Inheritence

*Each public member in the base class is protected in the derived class.

*Each protected member in the base class is protected in the derived class.

*Each private member in the base class remains private in the base class and hence visible only in the
base class.

Class base class_name{

Class derived_class_name:protected base_class_name

Submitted by:-

Deepanshu Bansal

164024

G-2 group,2k16

Potrebbero piacerti anche