0% found this document useful (0 votes)
155 views

Assignment - 8

The document contains 4 assignments involving C++ classes - the first creates an Employee class to calculate gross salary, the second creates a Teacher class to store and display teacher details, the third creates Train and Route classes to accept train details and display schedules, and the fourth creates a Marksheet class to calculate grades from subject marks.

Uploaded by

Dhara raheja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views

Assignment - 8

The document contains 4 assignments involving C++ classes - the first creates an Employee class to calculate gross salary, the second creates a Teacher class to store and display teacher details, the third creates Train and Route classes to accept train details and display schedules, and the fourth creates a Marksheet class to calculate grades from subject marks.

Uploaded by

Dhara raheja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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:

   int eid; //eid=employee id

   float bsal,hra,da,gsal; //bsal=basic salary , hra=HRA , da=DA , gsal=Gross


salary

   char name[10]; //name=name of employee

   void accept()

   {

    cout<<"Enter employee id: ";

      cin>>eid;

      cout<<"Enter employee name: ";

      cin>>name;

      cout<<"Enter basic salary: ";

      cin>>bsal;

   }

   void disp()

   {

       cout.precision(2);  //manipulator
       cout.left;

       cout<<"employee id: "<<setw(20)<<eid<<endl;

       cout<<"employee name: "<<setw(20)<<name<<endl;

       cout<<"basic salary: "<<bsal<<endl;

       cout<<"HRA: "<<hra<<endl;

       cout<<"DA: "<<da<<endl;

       cout<<"Gross salary: "<<gsal<<endl;

   }

   void cal()  //calculate gross salary

   {

      hra=((30.0/100)*bsal);

      da=((20.0/100)*bsal);

      gsal=bsal+hra+da;

   }

};

int main()

   emp e; //creating instance of class emp

   e.accept(); //calling member functions

   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

   char pname[10],city[10]; //tname=tname , no=ph no

   int no;

   public:

   void accept()

   {

    cout<<"Enter teacher name: ";

      cin>>pname;

      cout<<"Enter teacher city: ";

      cin>>city;

      cout<<"Enter phone number: ";

      cin>>no;

   }

   void disp()

   {

      cout<<"\nteacher name: "<<pname;

      cout<<"\nteacher city: "<<city;

      cout.width(10);

      cout.fill('*');

      cout.right;

      cout<<"\nteacher phone number: "<<setw(10)<<no;

   }

};

int main()

   teacher t; //creating instance of class person


   t.accept(); //calling member functions

   t.disp();

   getch();

   return(0);

3. Create a C++ class Train with data members as Train_No,Train_Name,No_of


Seats,Source_Station,Destination_Station. Write necessary member functions for the
following:
i.
Accept details of n trains.
ii.
Display all train details.
iii.
Display details of train from specified starting and ending station by user.

#include<onio.h>

#include<iostream.h>

class train

   protected:

   int tno;

   char name[10]; // tno=train no , name=train name

   public:

   void acc()

   {

    //accept information realted to train

   cout<<"\nEnter train no: ";

   cin>>tno;

   cout<<"\nEnter train name: ";

   cin>>name;

   }

};

class route: public train //inheriate class route 

{
   public:

   int rid;

   char s[10],d[10]; // rid= train id , s=source , d=destination

   void ac()

   {

      cout<<"\nEnter train id: ";

      cin>>rid;

      cout<<"\nEnter train source: ";

      cin>>s;

      cout<<"\nEnter destination: ";

      cin>>d;

   }

};

class reser: public route  //inheriate class reser

public:

   int  nos,fare,dd,mm,yyyy; //nos=no of seats , dd=date mm=month yyyy=year

   char clas[10];

   void a()

   {

      cout<<"\nEnter no of seats: ";

      cin>>nos;

      cout<<"\nEnter train class: ";

      cin>>clas;

      cout<<"\nEnter date(dd mm yyyy): ";

      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<<"\ntrain destination\t: \t"<<d;

      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;

   reser r[20]; //create instance of reser

   cout<<"Enter how many details you want to enter: ";

   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();
}

You might also like