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

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.

Assume that a bank maintains two kinds of accounts, are called as saving account and current account. The saving account provides compound interest and withdrawal facilities but no cheque book facility. The current account provides cheque book facility but no interest. Current account holders should also maintain a minimum balance and if the balance falls below the level, a service charge is imposed. Create a class account that stores customer name, account number and type of account. From this derive the classes cur_acct and sav_acct to make them more specific to their requirements. Include necessary member functions in order to achieve the following tasks: a.Include constructor for all the three classes. b.Accept deposit amount from the customer and update the balance. c.Display the balance. d.Compute and deposit interest. e.Permit withdrawal and update the balance. f. Check for minimum balance, impose penalty, necessary and update the balance.