6.1.1.  Inheritance Client Code Example

[ fromfile: inheritance-intro.xml id: inheritanceclientcode1 ]

Example 6.5. src/derivation/qmono/student-test.cpp

#include <QTextStream> 
#include "student.h"

static QTextStream cout(stdout); 

void finish(Student* student) {
    cout << "\nThe following "
         << student->getClassName()
         << " has applied for graduation.\n "
         << student->toString() << "\n";
}

int main() {
    Undergrad us("Frodo Baggins", 5562, "Ring Theory", 4, 1220);
    GradStudent gs("Bilbo Baggins", 3029, "History", 6,
                    GradStudent::fellowship);
    cout << "Here is the data for the two students:\n";
    cout << gs.toString() << endl;
    cout << us.toString() << endl;
    cout << "\nHere is what happens when they finish their studies:\n";
    finish(&us);
    finish(&gs);
    return 0;
}

src/derivation/qmono> qmake -project 
src/derivation/qmono> qmake 
src/derivation/qmono> make 
   
src/derivation/qmono> ./qmono
Here is the data for the two students:
[Student][27] name: Bilbo Baggins; Id: 3029; Year: gradual student;
  Major: History  [Support: fellowship ]

[Student] name: Frodo Baggins; Id: 5562; Year: senior;
  Major: Ring Theory  [SAT: 1220 ]

Here is what happens when they finish their studies:

The following Student has applied for graduation.
 [Student] name: Frodo Baggins; Id: 5562; Year: senior; 
   Major: Ring Theory
   
The following Student has applied for graduation.
 [Student] name: Bilbo Baggins; Id: 3029; Year: gradual student;
   Major: History
src/derivation/qmono>


[27] It would be nice if the output showed [GradStudent] here.