Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- using namespace std;
- class Person {
- protected:
- string name;
- string surname;
- int age;
- public:
- virtual void info() = 0;
- virtual void setName(string newName) = 0;
- virtual string getName() = 0;
- virtual void setSurname(string newSurname) = 0;
- virtual string getSurname() = 0;
- virtual void setAge(int newAge) = 0;
- virtual int getAge() = 0;
- };
- class Student : public Person {
- public:
- Student(){}
- Student(string newName, string newSurname, int newAge){
- this->name = newName;
- this->surname = newSurname;
- this->age = newAge;
- }
- virtual void info() {
- cout << name << ", " << surname << ", " << age << " lat" << endl;
- }
- void setName(string newName) {
- this->name = newName;
- }
- string getName(){
- return this->name;
- }
- void setSurname(string newSurname) {
- this->surname = newSurname;
- }
- string getSurname(){
- return this->surname;;
- }
- void setAge(int newAge){
- this->age = newAge;
- }
- int getAge(){
- return this->age;
- }
- };
- istream &operator>> (istream &input, Person &p){
- string temp;
- cout << "Imie: ";
- input >> temp;
- p.setName(temp);
- cout << "Nazwisko: ";
- input >> temp;
- p.setSurname(temp);
- int tempAge;
- cout << "Wiek: ";
- input >> tempAge;
- p.setAge(tempAge);
- cout << endl;
- return input;
- }
- ostream &operator<< (ostream &output, Person &p){
- output << "[" << p.getName() << ", " << p.getSurname() << ", " << p.getAge() << " lat]" << endl;
- return output;
- }
- int main(){
- int size;
- cout << "Podaj rozmiar: " << endl << endl;
- cin >> size;
- Student* tab;
- tab = new Student[size];
- Student* start = tab;
- for(int i = 0; i < size; i++, tab++)
- cin >> *tab;
- for(int i = 0; i < size; i++, start++)
- cout << *start;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement