Chapter – 4. CLASSES AND OBJECTS

Calculate( ) that calculates overall percentage marks and returns the percentage Public Members of the Student are:
Readmarks reads mark and invoke the calculate function
Displaymarks prints the data.

Ans:

class Student
{
int roll_no;
char name[20];
char class_st[8];
int marks[5];
float percentage;
float calculate( )
{
percentage=(marks[0]+marks[1]+marks[2]+marks[3]+marks[4])/5; return percentage;
}
public: void Readmarks( )
{
cout<<”\nEnter any 5 subject marks;
cin>>marks[0]>>marks[1]>>marks[2]>>marks[3]>>marks[4]; calculate( );
}
void Displaymarks( )
{
cout<<”\nThe Roll Number of the Student: “<<roll_no;
cout<<”\nThe Name of the Student: “<<name;
cout<<”\nThe class of the Student: “<<class_st;
cout<<”\n5 subject marks of the student…\n”;
cout<<marks[0]<<”\t”<<marks[1]<<”\t”<<marks[2]<<”\t”;
cout<<marks[3]<<”\t”<<marks[4]<<”\n”;
cout<<”Percentage =”<<percentage;
}
};

2001:

2.b. Declare a class to represent bank account of 10 customers with the following data members. Name of the depositor, account number, type of account (S for Savings and C for Current), Balance amount. The class also contains member functions to do the following:

  1. To initialize data members.
  2. To deposit money
  3. To withdraw money after checking the balance (minimum balance is Rs.1000)
  4. To display the data members.

[Note:You are also required to give detailed function definitions.]