Assignment - 8
Assignment - 8
1. Write a C++ program to create a class Employee which contains data members as
Emp_Id, Emp_Name, Basic_Salary, HRA, DA, Gross_Salary. Write member functions to
accept Employee information. Calculate and display Gross salary of an employee.
(DA=25% of Basic salary and HRA = 40% of Basic salary) (Use appropriate
manipulators
to display employee information in given format :- Emp_Id and Emp_Name should be
left
justified and Basic_Salary, HRA, DA, Gross salary Right justified with a precision
of
three digits)
#include<conio.h>
#include<iostream.h>
#include<iomanip.h> //manipulator
class emp
public:
void accept()
{
cin>>eid;
cin>>name;
cin>>bsal;
}
void disp()
{
cout.precision(2); //manipulator
cout.left;
cout<<"HRA: "<<hra<<endl;
cout<<"DA: "<<da<<endl;
}
{
hra=((30.0/100)*bsal);
da=((20.0/100)*bsal);
gsal=bsal+hra+da;
}
};
int main()
e.cal();
e.disp();
getch();
return(0);
2. Write a C++ program to create a class Teacher which contains data members as
Teacher_Name, Teacher_City, Teacher_Contact_Number. Write member functions to
accept and display five teachers information. Design User defined Manipulator to
print
Teacher_Contact_Number. (For Contact Number set right justification, maximum width
to
10 and fill remaining spaces with ‘*’)
#include<iostream.h>
#include<conio.h>
#include<iomanip.h> //manipulator
class teacher
int no;
public:
void accept()
{
cin>>pname;
cin>>city;
cin>>no;
}
void disp()
{
cout.width(10);
cout.fill('*');
cout.right;
}
};
int main()
t.disp();
getch();
return(0);
#include<onio.h>
#include<iostream.h>
class train
protected:
int tno;
public:
void acc()
{
cin>>tno;
cin>>name;
}
};
{
public:
int rid;
void ac()
{
cin>>rid;
cin>>s;
cin>>d;
}
};
public:
char clas[10];
void a()
{
cin>>nos;
cin>>clas;
cin>>dd>>mm>>yyyy;
}
void dis()
{
// displaying all information
cout<<"\ntrain no\t\t:\t"<<tno;
cout<<"\ntrain name\t\t:\t"<<name;
cout<<"\ntrain id\t\t:\t"<<rid;
cout<<"\ntrain source\t\t:\t"<<s;
cout<<"\nno of seats\t\t:\t"<<nos;
cout<<"\ntrain class\t\t:\t"<<clas;
cout<<"\ntrain date\t\t:\t"<<dd<<"/"<<mm<<"/"<<yyyy<<"\n";
}
};
int main()
int i,s;
cin>>s;
for(i=0;i<s;i++)
{
r[i].acc();
r[i].ac();
r[i].a();
}
for(i=0;i<s;i++)
{
r[i].dis();
}
getch();
return(0);
}
4. Create a C++ class Marksheet with data members Seat_No., Student_Name, Class,
Subject_Name, Int_Marks, Ext_Marks, Total, Grand_Total, Percentage, Grade. Write
member function to accept Student information for 4 subjects. Calculate Total,
Grand_Total, Percentage, Grade and display Marksheet. (Use user defined
manipulator)
#include<iostream.h>
#include<conio.h>
#include<string.h>
class student
{
int rno,ns,s;
float per;
char name[20];
int *m;
public:
student(int no,char *nm,int nos)
{
rno=no;
strcpy(name,nm);
ns=nos;
m=new int[ns];
}
void get();
void cal();
void disp();
};
void student::get()
{
for(int i=0;i<ns;i++)
{
cout<<“\n\nEnter the subject “<<i+1<<” Marks” ;
cin>>m[i];
}
}
void student::cal()
{
s=0;
for(int i=0;i<ns;i++)
{
s=s+m[i];
}
per=s/ns;
}
void student::disp()
{
cal();
cout<<“\n\nRoll no: “<<rno;
cout<<“\n\nName: “<<name;
for(int i=0;i<ns;i++)
{
cout<<“\n\nMarks of “<<i+1<<” Subject: “<<m[i];
}
cout<<“\n\npercentage: “<<per;
}
void main()
{
int no,nos;
char nm[20];
clrscr();
cout<<“\nEnter roll no name no of subject:\n”;
cin>>no>>nm>>nos;
student st(no,nm,nos);
st.get();
st.disp();
getch();
}