rendered paste body
#include <iostream> // for cout, cin, etc
using namespace std; // to elminate need for std
class UnivPerson {
private:
// every UnivPerson has a name and social #
string firstName, lastName, social;
public:
/** core methods */
// default constructor
UnivPerson() {
cout << "Default UnivPerson Constructor called." << endl;
}
// four param constructor
UnivPerson::UnivPerson( const string& first, const string& last, const string& soc )
: firstName( first ), lastName( last ), social( soc )
{
cout << "UnivPerson constructor called for " << getLastName() << endl;
}
// destructor
~UnivPerson()
{
cout << "UnivPerson destructor called for " << getLastName() << endl;
}
// present output for the base UnivPerson
void output( ostream& os ) const
{
os << lastName << ", " << firstName << " (" << social << ")" << endl;
}
/** basic get methods */
string getFirstName() const { return firstName; }
string getLastName() const { return lastName; }
string getSocial() const { return social; }
};
class Student : public UnivPerson {
private:
string major; // every student has a major of study
double gpa; // every student has a gpa on a 4.0 scale
int id; // every student has an id number
public:
/** core methods */
Student()
{
cout << "Student default constructor called." << endl;
}
// four param constructor
Student::Student( const UnivPerson& P, const string& M, double G, int I )
: UnivPerson( P ), major( M ), gpa( G ), id( I )
{
cout << "Student four-parameter constructor called for " << getLastName() << endl;
}
// six param constructor
Student::Student( const string& first, const string& last, const string& soc, const string& ma, double g, int i )
: UnivPerson( first, last, soc ), major( ma ), gpa( g ), id( i )
{
cout << "Student six-parameter constructor called for " << getLastName() << endl;
}
// destructor
Student::~Student()
{
cout << "Student DESTRUCTOR called." << endl;
}
/** get and set methods */
string getMajor() const { return major; };
double grade() const { return gpa; };
int identity() const { return id; };
};
int main( int argc, char* argv[] )
{
UnivPerson Person( "Fooperson", "Bar", "234-3455" );
Student One( Person, "Psychology", 3.21, 245345 );
Student Two( Person, "Business", 3.42, 3454324 );
Person.output( cout );
One.output( cout );
Two.output( cout );
return 0;
}