SHARE
TWEET

Pointers

a guest May 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. struct Date {
  7.     int bday;
  8.     int bmonth;
  9.     int byear;
  10. };
  11.  
  12. class Person{
  13. public:
  14.     Person(string, int, int, int, int, string);
  15.     //int age(int);
  16.     //void setOccupation(string);
  17.     //string getOccupation();
  18.     void print();
  19. private:
  20.     string name;
  21.     Date birthdate;
  22.     int ssn;
  23.     string occupation;
  24. };
  25. class Student : public Person {
  26. private:
  27.     double GPA;
  28. public:
  29.     Student(string, int, int, int, int, double);
  30.     //void setGPA(double);
  31.     //double getGPA();
  32.     void printAll();
  33. };
  34.  
  35. int main()
  36. {
  37.  
  38.     Person *p1;
  39.     p1 = new Person("No Name", 1, 1, 1990, 111111111, "Student"); //"new" = to create an object dynamically
  40.     //(*p1).print();
  41.     //p1->print(); //-> = allows to access the memebrs of an object using the pointer
  42.     Student s1("No Name", 1, 1, 1990, 1111111111, 3.85);
  43.     s1.printAll();
  44.     //s1.setGPA(3.85);
  45.     //if (s1.getGPA() == 3.85)
  46.     //{
  47.  
  48.     //}
  49.     return 0;
  50. }
  51. Person::Person(string tempname, int tempday, int tempmonth, int tempyear, int tempssn, string tempOccupation)
  52. {
  53.     name = tempname;
  54.     birthdate.bday = tempday;
  55.     birthdate.bmonth = tempmonth;
  56.     birthdate.byear = tempyear;
  57.     ssn = tempssn;
  58.     occupation = tempOccupation;
  59. }
  60. void Person::print()
  61. {
  62.     cout << "First Hame: " << name << endl;
  63.     cout << "Birthday: " << birthdate.bday << "/" << birthdate.bmonth << "/" << birthdate.byear << endl;
  64.     cout << "SSN:" << ssn << endl;
  65. }
  66.  
  67. Student::Student(string tempname, int tempday, int tempmonth, int tempyear, int tempssn, double tempGPA) :Person(tempname, tempday, tempmonth, tempyear, tempssn, "Student")
  68. {
  69.     GPA = tempGPA;
  70. }
  71.  
  72. void Student::printAll()
  73. {
  74.     Person::print();
  75.     cout << "GPA: " << GPA << endl;
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top