1999 :
2.b. Define a class Teacher with the following class specification:
Private members:
Name | 20 characters |
Subject | 10 characters |
Basic, DA, HRA | float |
Salary | float |
Calculate( ) function computes the salary and returns it. Salary is sum of Basic, DA and HRA
Public members:
ReadData( ): Function accepts the data values and invoke the calculate function.
DisplayData( ):Function prints the data on the screen.
class Teacher
{
char Name[20]; char subject[10];
float Basic,DA,HRA,Salary;
float Calculate( )
{
Salary=Basic+DA+HRA; return Salary;
}
public: void ReadData( )
{
cout<<"\nEnter Basic, Dearness Allowance and “
cout<<” House Rent Allowance: ";
cin>>Basic>>DA>>HRA; Calculate();
}
void DisplayData( )
{
cout<<"\nThe Basic : "<<Basic;
cout<<"\nThe Dearness Allowance: "<<DA;
cout<<"\nThe House Rent Allowance: "<<HRA;
cout<<"\nThe Salary: "<<Salary;
}
};
1998 Annual:
2.b. Define a class student with the following specifications:
Private members of class student:
Admno | integer |
Sname | 20 character |
English | float |
Math | float |
Science | float |
Total | float |
Ctotal( ) | A function to calculate English + |
math + science with float return type
Public member functions of class student:
Takedata( ):Function to accept values for admno,sname, English, math, science and invoke ctotal to calculate total.
Showdata( ):Function to display all the data members on the screen.
class student
{
int Admno;
char Sname[20];
float English,Math,Science,Total;
float Ctotal()
{
Total=English+math+science; return Total;
}
public: void Takedata()
{
cout<<”\nEnter the admission number,name of the student: “;
cin>>Admno; gets(sname);
cout<<”\nEnter English, Maths, Science Marks: “;
cin>>English>>Math>>Science; Ctotal( );
}
void Showdata( )
{
cout<<”\nThe admission number of the student: “<<Admno;
cout<<”\nThe name of the student: “<<Sname;
cout<<”\nEnglish , Maths and Science Marks are…”;
cout<< English<<”\t”<<math<<”\t”<<science<<”\n”;
cout<<”\nTotal marks of the student: “<<Total;
};