Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- using namespace std;
- struct Date {
- int bday;
- int bmonth;
- int byear;
- };
- class Person{
- public:
- Person(string, int, int, int, int, string);
- //int age(int);
- //void setOccupation(string);
- //string getOccupation();
- void print();
- private:
- string name;
- Date birthdate;
- int ssn;
- string occupation;
- };
- class Student : public Person {
- private:
- double GPA;
- public:
- Student(string, int, int, int, int, double);
- //void setGPA(double);
- //double getGPA();
- void printAll();
- };
- int main()
- {
- Person *p1;
- p1 = new Person("No Name", 1, 1, 1990, 111111111, "Student"); //"new" = to create an object dynamically
- //(*p1).print();
- //p1->print(); //-> = allows to access the memebrs of an object using the pointer
- Student s1("No Name", 1, 1, 1990, 1111111111, 3.85);
- s1.printAll();
- //s1.setGPA(3.85);
- //if (s1.getGPA() == 3.85)
- //{
- //}
- return 0;
- }
- Person::Person(string tempname, int tempday, int tempmonth, int tempyear, int tempssn, string tempOccupation)
- {
- name = tempname;
- birthdate.bday = tempday;
- birthdate.bmonth = tempmonth;
- birthdate.byear = tempyear;
- ssn = tempssn;
- occupation = tempOccupation;
- }
- void Person::print()
- {
- cout << "First Hame: " << name << endl;
- cout << "Birthday: " << birthdate.bday << "/" << birthdate.bmonth << "/" << birthdate.byear << endl;
- cout << "SSN:" << ssn << endl;
- }
- Student::Student(string tempname, int tempday, int tempmonth, int tempyear, int tempssn, double tempGPA) :Person(tempname, tempday, tempmonth, tempyear, tempssn, "Student")
- {
- GPA = tempGPA;
- }
- void Student::printAll()
- {
- Person::print();
- cout << "GPA: " << GPA << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement