Sunteți pe pagina 1din 5

PROGRAMS ON INHERITANCE:

1.Write a c++ program to generate manager details.


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
const int len=25;
class employee{
private:
char name[len];
unsigned long enumb;
public:
void getdata()
{
cout<<"\nenter name:\n";
gets(name);
cout<<"\nenter employee number:\n";
cin>>enumb;
}
void putdata()
{
cout<<"\nNAME:"<<name<<"\t"<<"emp number:"<<enumb<<"\t"<<"Basic
salary:"<<basic;
}
protected:
float basic;
void getbasic()
{
cout<<"\nenter basic:\n";
cin>>basic;
}
};
class manager:public employee
{
private:
char title[len];
public:
void getdat()
{
getdata();
getbasic();
cout<<"\nenter title\n";
gets(title);
cout<<"\n";
}
void putdat()
{

putdata();
cout<<"\tTitle:"<<title<<"\n";
}
};
void main()
{
int a,c;
int const size=10;
manager b[size];
for(int i=0;i<size;i++)
{
cout<<"would you like entry details press 0 to continue ?\n";
cin>>a;
if(a==0)
{
cout<<"MANAGER "<<(i+1)<<":\n";
b[i].getdat();
c=i;
}
else
break;
}
for(i=0;i<=c;i++)
{
cout<<"\nManager"<<(i+1)<<"details:\n";
b[i].putdat();
}
}

2.Write a c++ program to display the annual report of a college.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
int const len=25;
class person{
char name[len];
int age;
public:
void readper();
void disper()
{
cout<<"NAME:"<<name<<"\n";
cout<<"AGE:"<<age<<"\n";
}
};
void person::readper()
{
cout<<"enter name of the person:"<<"\n";
gets(name);
cout<<"\nenter age:\n";
cin>>age;
}
class student:public person
{
int rollno;
float average;
public:
void readstu()
{
readper();
cout<<"\nenter roll number\n";
cin>>rollno;
cout<<"\nenter average marks\n";
cin>>average;
}
void dispstu()
{
cout<<"\nROLL NUMBER:"<<rollno<<"\n";
}
float getaverage(void)
{
return average;
}
};
class gradstudent:public student
{
char sub[len];
char work;
public:

void readit(void);
void dispsub(void)
{
cout<<"SUBJECT:"<<sub;
}
char workstat(void)
{
return work;
}
};
void gradstudent::readit()
{
readstu();
cout<<"\nenter main subject\n";
gets(sub);
cout<<"\nWorking?(Y/N):\n";
cin>>work;
}
void main()
{
const int size=3;
gradstudent grad[size];
int year=0,nw=0,now=0,div1=0,tot=0;
float topscore=0,score,number,nwperc,wperc;
cout<<"\nEnter year\n";
cin>>year;
for(int i=0;i<3;i++)
{
cout<<"\nEnter details for graduate\n"<<(i+1)<<"\n";
grad[i].readit();
tot++;
if((grad[i].workstat()=='y')||(grad[i].workstat()=='Y'))
nw++;
else
now++;
score=grad[i].getaverage();
if(score>topscore)
{
topscore=score;
number=i;
}
if(score>=60)
div1++;
}
i=number;
cout<<"\n"<<"\t\tREPORT FOR THE YEAR"<<year<<"\n";
cout<<"WORKING GRADUATES:"<<nw;
cout<<"\tNON-WORKING GRADUATES:"<<now<<"\n";
cout<<"\tDetails of top scorer\n";
grad[i].disper();

grad[i].dispsub();
nwperc=((float)now/tot)*100;
wperc=((float)div1/tot)*100;
cout<<"Average Marks:"<<grad[i].getaverage()<<"\n";
cout<<nwperc<<"% of the graduates this year are non working
and\n"<<wperc<<"% are first divisioners\n";
}

S-ar putea să vă placă și