Define a class student with the following specification Private members of class student admno integer sname 20 character eng. math, science float total float Public member function of class student ctotal() a function to calculate eng + math + science with float return type. Takedata() Function to accept values for admno, sname, eng, science Showdata() Function to display all the data members on the screen




   #include<iostream>
using namespace std;
class student
{
private:
    int admno;
    char sname[20];
    float eng,math,science;
    float total;
public:
    void get_data()
    {
        cout<<"enter the addmission number and name of student : " <<endl;
        cin>>admno>>sname;
        cout <<"enter the marks of student in english , maths , science :"<<endl;
        cin>>eng>>math>>science;
    }
    int ctotal();
    void show_data();

};

int student :: ctotal()
{
    int total_marks=eng+math+science;
    return total_marks;

}

void student :: show_data()
{
    cout<<"total marks of student "<<sname;
    cout<<" is "<<ctotal() <<" and his admission no. is "<<admno<<endl;
}

int main()
{
    student s1,s2;

    s1.get_data();
    cout<<"Detail of 1st student is as follow :"<<endl;
    s1.ctotal();
    s1.show_data();
    s2.get_data();

    cout<<"Detail of 2nd student is as follow :"<<endl;
    s2.ctotal();
    s2.show_data();
}

output :
enter the addmission number and name of student : 32442 Rahul enter the marks of student in english , maths , science : 89 80 71 Detail of 1st student is as follow : total marks of student Rahul is 240 and his admission no. is 32442
enter the addmission number and name of student : 1231 Rohit enter the marks of student in english , maths , science : 60 70 80 Detail of 2nd student is as follow : total marks of student Rohit is 210 and his admission no. is 1231


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