Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Person
- {
- public:
- Person (string name,int age);
- // декларация на инициализиращ конструктор
- void printInfo() ;
- // декларация на виртуален метод printInfo()
- protected:
- string name;
- int age;
- // декларация на атрибут за възраст
- };
- class Student:Person {
- public:
- Student (string Uni1,string Spec1,double srUsp1,string name, int age);
- void printInfo();
- private:
- string Uni;
- string Spec;
- double srUsp;
- };
- Person::Person (string sname, int sage){
- name = sname;
- age = sage;
- }
- // дефиниция на конструктора
- Student::Student (string Uni1, string Spec1, double srUsp1,string name1, int age1) : Person (name1,age1) {
- Uni = Uni1;
- Spec = Spec1;
- srUsp = srUsp1;
- }
- void Person::printInfo()
- {
- cout << "Name:" << name.c_str() << endl;
- cout << "Age :" << age<<endl;
- //.....................
- }
- void Student::printInfo()
- {
- Person::printInfo();
- cout << "Uni:" << Uni.c_str() << endl;
- cout << "Spec :" << Spec.c_str()<<endl;
- cout << "srUsp :" << srUsp<<endl;
- //.....................
- }
- int main()
- {
- // създаване на обекти
- // извикване на printInfo() за обектите
- Person Pesho ("Pesho",19);
- Pesho.printInfo();
- Student Gosho2 ("Uak","KST",4.50,"Gosho",23);
- Gosho2.printInfo();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement