1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include<iostream>
#include<string>
using namespace std;
class Person{
public:
Person();
Person(string theName, string theAddress, string theCity, string theState, int theZip, string thePhone);
//~Person();
void printPerson()const;
protected:
string name;
string address;
string city;
string state;
int zip;
string phone;
};
Person::Person(string theName, string theAddress, string theCity, string theState, int theZip, string thePhone){
name=theName;
address=theAddress;
city=theCity;
state=theState;
zip=theZip;
phone=thePhone;
}
void Person::printPerson() const{
cout<<name<<" "<<address<<", "<<city<<", "<<state<<" "<<zip<<endl;
}
class Student:public Person{
public:
Student();
Student(string name, string address, string city, string state, int zip, string phone, char grade, string course, string gpa);
void printStudent() const;
protected:
char grade;
string course;
string gpa;
};
Student::Student(string theName, string theAddress, string theCity, string theState, int theZip, string thePhone, char theGrade, string theCourse, string theGpa)
: Person(theName, theAddress, theCity, theState, theZip, thePhone){
grade=theGrade;
course=theCourse;
gpa=theGpa;
}
void Student::printStudent() const{
printPerson();
cout<<grade<<" "<<course<<" "<<gpa<<endl;
}
int main()
{
Person person("karen", "3452 Ave.", "Somewhere", "FL", 83946, "123 456 7890");
Student student("tony","1111 Ave", "Anywhere", "TX", 74934, "924 654 8789", 'A', "Programming", "4.0");
person.printPerson();
//person.printStudent(); Won't work
student.printStudent();
student.printPerson();
system("pause");
return 0;
}
|