# Include "stdafx. h"
# Include <iostream>
# Include <string>
Using namespace std;
Class student {
Private:
Int num;
Int age;
Float score;
Public:
Student (int, int, float );
Void display ();
};
// Define the constructor
Student: student (int n, int a, float SC): num (n), age (a), score (SC ){}
Void student: display () {// define a member function
Cout <num <endl;
Cout <age <endl;
Cout <score <endl;
}
Class graduate: public student {
Private:
Float pay;
Public:
Graduate (int, int, float, float );
Void display ();
};
Graduate: graduate (int n, int a, float SC, float p): student (n, a, SC), pay (p ){}
Void graduate: display (){
Student: display ();
Cout <pay <endl;
}
Int main (){
Student st (12222,22, 97.4 );
Graduate gr (2017543,26, 88.2, 8000 );
Student * pt = & st;
Pt-> display ();
Pt = & gr;
Pt-> display ();
Return 0;
}
Output result:
12222
22
97.4
353543
26
88.2
Press any key to continue