Advertisement
Guest User

ZaBudeshteto

a guest
Feb 20th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class Person
  6. {
  7. public:
  8. Person (string name,int age);
  9. // декларация на инициализиращ конструктор
  10. void printInfo() ;
  11. // декларация на виртуален метод printInfo()
  12. protected:
  13. string name;
  14. int age;
  15. // декларация на атрибут за възраст
  16. };
  17.  
  18. class Student:Person {
  19.  
  20. public:
  21. Student (string Uni1,string Spec1,double srUsp1,string name, int age);
  22. void printInfo();
  23. private:
  24. string Uni;
  25. string Spec;
  26. double srUsp;
  27. };
  28.  
  29. Person::Person (string sname, int sage){
  30. name = sname;
  31. age = sage;
  32. }
  33. // дефиниция на конструктора
  34.  
  35. Student::Student (string Uni1, string Spec1, double srUsp1,string name1, int age1) : Person (name1,age1) {
  36. Uni = Uni1;
  37. Spec = Spec1;
  38. srUsp = srUsp1;
  39.  
  40. }
  41.  
  42. void Person::printInfo()
  43. {
  44. cout << "Name:" << name.c_str() << endl;
  45. cout << "Age :" << age<<endl;
  46. //.....................
  47.  
  48. }
  49.  
  50. void Student::printInfo()
  51. {
  52. Person::printInfo();
  53. cout << "Uni:" << Uni.c_str() << endl;
  54. cout << "Spec :" << Spec.c_str()<<endl;
  55. cout << "srUsp :" << srUsp<<endl;
  56. //.....................
  57.  
  58. }
  59.  
  60. int main()
  61. {
  62.  
  63. // създаване на обекти
  64. // извикване на printInfo() за обектите
  65. Person Pesho ("Pesho",19);
  66. Pesho.printInfo();
  67.  
  68. Student Gosho2 ("Uak","KST",4.50,"Gosho",23);
  69. Gosho2.printInfo();
  70. system("pause");
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement