Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7.      class Person {
  8.         protected:
  9.             string name;
  10.             string surname;
  11.             int age;
  12.  
  13.         public:
  14.             virtual void info() = 0;
  15.             virtual void setName(string newName) = 0;
  16.             virtual string getName() = 0;
  17.             virtual void setSurname(string newSurname) = 0;
  18.             virtual string getSurname() = 0;
  19.             virtual void setAge(int newAge) = 0;
  20.             virtual int getAge() = 0;
  21.     };
  22.  
  23.     class Student : public Person {
  24.  
  25.         public:
  26.             Student(){}
  27.  
  28.             Student(string newName, string newSurname, int newAge){
  29.                 this->name = newName;
  30.                 this->surname = newSurname;
  31.                 this->age = newAge;
  32.             }
  33.  
  34.             virtual void info() {
  35.                 cout << name << ", " << surname << ", " << age << " lat" << endl;
  36.             }
  37.  
  38.             void setName(string newName) {
  39.                 this->name = newName;
  40.             }
  41.  
  42.             string getName(){
  43.                 return this->name;
  44.             }
  45.  
  46.              void setSurname(string newSurname) {
  47.                 this->surname = newSurname;
  48.             }
  49.  
  50.             string getSurname(){
  51.                 return this->surname;;
  52.             }
  53.  
  54.             void setAge(int newAge){
  55.                 this->age = newAge;
  56.             }
  57.  
  58.             int getAge(){
  59.                 return this->age;
  60.             }
  61.  
  62.  
  63.     };
  64.  
  65.     istream &operator>> (istream &input, Person &p){
  66.         string temp;
  67.         cout << "Imie: ";
  68.         input >> temp;
  69.         p.setName(temp);
  70.         cout << "Nazwisko: ";
  71.         input >> temp;
  72.         p.setSurname(temp);
  73.         int tempAge;
  74.         cout << "Wiek: ";
  75.         input >> tempAge;
  76.         p.setAge(tempAge);
  77.         cout << endl;
  78.         return input;
  79.     }
  80.  
  81.     ostream &operator<< (ostream &output, Person &p){
  82.         output << "[" << p.getName() << ", " << p.getSurname() << ", " << p.getAge() << " lat]" << endl;
  83.         return output;
  84.     }
  85.  
  86.     int main(){
  87.         int size;
  88.         cout << "Podaj rozmiar: " << endl << endl;
  89.         cin >> size;
  90.  
  91.         Student* tab;
  92.         tab = new Student[size];
  93.         Student* start = tab;
  94.  
  95.         for(int i = 0; i < size; i++, tab++)
  96.             cin >> *tab;
  97.  
  98.         for(int i = 0; i < size; i++, start++)
  99.             cout << *start;
  100.  
  101.         return 0;
  102.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement