Create two base classes Learning_Info( Roll_No, Stud_Name, Class, Percentage) and Earning_Info(No_of_hours_worked, Charges_per_hour). Derive a class Earn_Learn_info from above two classes. Write necessary member functions to accept and display Student information. Calculate total money earned by the student. (Use constructor in derived class)
//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<conio.h>
#include<iostream.h>
class info
{
protected:
int rno,per; //rno=roll no , per=percentage
char name[10],clas[10]; //name=name , clas=class
public:
info() // constructor
{
cout<<"\nEnter Roll no: ";
cin>>rno;
cout<<"\nEnter name: ";
cin>>name;
cout<<"\nEnter class: ";
cin>>clas;
cout<<"\nEnter percentage: ";
cin>>per;
}
};
class einfo
{
protected:
int noh,cph; // noh=no of hours , cph= cost per hour
public:
einfo()
{
cout<<"\nEnter no of hours worked: ";
cin>>noh;
cout<<"\nEnter cost per hour: ";
cin>>cph;
}
};
class earn:public info,public einfo // inherit class earn from 2 classes
{
protected:
int s;
public:
earn():info(),einfo()
{
cout<<"\nRoll no : "<<rno;
cout<<"\nname of student : "<<name;
cout<<"\nclass of student : "<<clas;
cout<<"\npercentage of student : "<<per;
cout<<"\nno of hours worked : "<<noh;
cout<<"\ncost per hour : "<<cph;
}
void cal()
{
s=0; //s=salary
s=noh*cph;
cout<<"\nTotal salary of student : "<<s;
}
};
int main()
{
earn e; //creating instance of class earn
e.cal(); //calling member function
getch();
return(0);
}
0 Comments