Develop a mark sheet in C++ for university examination with following data: a) Students’ name b) Enrolment no c) roll no d) Theory marks in 5 subjects e) Practical marks in five subjects f) grade Overload << and >> operator .Grade should be calculated for each subject. Use Constructor overloading. Roll no should be auto generated

 


#include<iostream>
#include<ctime>
using namespace std;
class marksheet
{
        char student_name[20];
        long int enroll;
        int rollno;
        int s[4];
        int p[4],t[4];

    public:

        marksheet(){};

        marksheet(char sn , long int en ,int rn)
        {
            student_name[20] = sn;
            enroll=en;
            rollno=rn;
        }

        void theory();
        void practical();
        void sum();
        void grade();
        friend istream & operator >>(istream &,marksheet &);
        friend ostream & operator <<(ostream &,marksheet &);
};

istream & operator >>(istream& in , marksheet &m)
{
    cout<<"enter the student name "<<endl;
    in>>m.student_name;

    cout<<"Enter theory marks of 5 subjects out of 70 : "<<endl;
    for (int i = 0i < 5i++)
    {
        in>>m.s[i];
    }

    cout<<"Enter practical marks of 5 subjects out of 30 : "<<endl;
    for (int i = 0i < 5i++)
    {
        in>>m.p[i];
    }

    cout<<"Enter enrollment no. :"<<endl;
    in>>m.enroll;
    return (in);
}

void marksheet :: sum()
{
   for (int i = 0i < 5i++)
   {
       t[i]=s[i]+p[i];
       cout<<"totol marks    : "<<t[i]<<endl;
   }

}

void marksheet :: grade ()
{
    for (int i = 0i < 5i++)
    {
        if(t[i]>=80)
        // ch='A';
        cout<<"grade = A"<<endl;
        else if(t[i]>=60)
        // ch='B';
        cout<<"grade = B"<<endl;
        else if(t[i]>=40)
        // ch='C';
        cout<<"grade = C"<<endl;
        else if(t[i]>=33)
        // ch='D';
        cout<<"grade = D"<<endl;
        else if(t[i]<33)
        // ch='f';
        cout<<"grade : FAIL"<<endl;
    }

}


ostream & operator <<(ostream & out , marksheet &m)
{
    m.rollno=rand()%100;
    out<<"student name    : "<<m.student_name<<endl;
    out<<"roll no         : "<<m.rollno<<endl;
    out<<"Enroll no.      : "<<m.enroll<<endl;
    return(out);
}

int main()
{
    srand(time(NULL));
    marksheet ms;
    cin>>ms;
    cout<<"\n\n*****************STUDENT INFO******************\n"<<endl;
    cout<<ms;
    ms.sum();
    ms.grade();
}

output :

enter the student name Rahul Enter theory marks of 5 subjects out of 70 : 20 30 40 50 60 Enter practical marks of 5 subjects out of 30 : 25 26 27 28 29 Enter enrollment no. : 27 roll no : 17 Enroll no. : 27
totol marks : 45 totol marks : 56 totol marks : 67 totol marks : 78 totol marks : 89 grade = c grade = C grade = B grade = B grade = A

Comments

Popular Post

Create a base class called shape .Use this class to store two double type values that could be used to compute the area of figures, Derive two specific classes called triangle and rectangle from the base shape .Add to the base class, a member function get_data() to initialise base class data members and another member function display_area() to compute and display the area of figures. Make display_area () as a virtual function and redefine this function in the derived class to suit their requirements. Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively and display the area. Area of rectangle = x*y Area of triangle = ½*x*y

Define a class in C++ with following description: Private Members A data member Flight number of type integer A data member Destination of type string A data member Distance of type float A data member Fuel of type float A member function CALFUEL() to calculate the value of Fuel as per the following criteria Distance Fuel <=1000 500 more than 1000 and <=2000 1100 more than 2000 2200 Public Members A function FEEDINFO() to allow user to enter values for Flight Number, Destination, Distance & call function CALFUEL() to calculate the quantity of Fuel. A function SHOWINFO() to allow user to view the content of all the data members.

Write the definition for a class called complex that has floating point data members for storing real and imaginary parts. The class has the following member functions: void set(float, float) to set the specified value in object void disp() to display complex number object complex sum(complex) to sum two complex numbers & return complex number 1. Write the definitions for each of the above member functions. 2. Write main function to create three complex number objects. Set the value in two objects and call sum() to calculate sum and assign it in third object. Display all complex numbers.

Create a base class called shape .Use this class to store two double type values that could be used to compute the area of figures, Derive two specific classes called triangle and rectangle from the base shape .Add to the base class, a member function get_data() to initialise base class data members and another member function display_area() to compute and display the area of figures. Make display_area () as a virtual function and redefine this function in the derived class to suit their requirements. Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively and display the area. Area of rectangle = x*y Area of triangle = ½*x*y