There is an Admission class that assigns the admission id and registration number to the Student. The student’s general information i.e. name, email, and contact number is initialized through another class. The student's result is controlled by another class that returns the student's cgpa based on his/her score in all tgpa’s.
Create 5 objects of students, input and display their name, registration number, section, cgpa using any possible type of Inheritance.
#include <iostream>
#include <string>
using namespace std;
class Admission
{
int admID;
int regNum;
public:
Admission(int _admID=0, int _regNum=0)
:admID(_admID), regNum(_regNum){}
void DisplayAdm()
{
cout << "\nThe admission id is " << admID
<< "\nThe registration number is " << regNum;
}
};
class Result
{
float cgpa;
public:
Result(float _cgpa=0):cgpa(_cgpa){}
void CountCGPA()
{
float tmp;
float sum=0;
int count = 0;
cout << "\nPlease, enter all your cgpa (0 - stop entering):";
do
{
cin >> tmp;
if (tmp > 0)
{
count++;
sum += tmp;
}
} while (tmp > 0);
cgpa = sum / count;
}
void DisplayRes()
{
cout << "The student's result is " << cgpa;
}
};
class Student:public Admission,public Result
{
string name;
string email;
int contNum;
public:
Student(string _name="", string _email="", int _contNum=0,
int _admID = 0, int _regNum = 0)
:Admission(_admID,_regNum), Result(),name(_name), email(_email), contNum(_contNum){}
void Display()
{
cout << "\nName is " << name
<< "\nEmail is " << email
<< "\nContact number is " << contNum;
}
};
int main()
{
Student arr[5] = { Student("Jack","jck@mail.com",1,123,789),
Student("John","jhn@mail.com",2,234,777),
Student("Nancy","nan@mail.com",3,345,666),
Student("Mary","mry@mail.com",4,456,555),
Student("Tom","tm@mail.com",5,567,444), };
for (int i = 0; i < 5; i++)
{
arr[i].Display();
arr[i].DisplayAdm();
arr[i].CountCGPA();
arr[i].DisplayRes();
}
}
Comments
Leave a comment