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

Define a class to represent a Bank Account. Include the following members: Data Members: i. Name of the depositor ii. Account number iii. Type of account iv. Balance amount in the account Member Functions: 1. To Input initial values 2. To deposit an amount 3. To withdraw an amount after checking the balance 4. To display name and balance Also write constructor for this class that takes four arguments. It should also handle type of account as savings by default

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.