Advertisement
Guest User

Exam2013_Task1

a guest
Sep 8th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.29 KB | None | 0 0
  1. /*
  2. საბაზო კლასში Building გაითვალისწინეთ მონაცემები floors და windows; ასევე პარამეტრიანი კონსტრუქტორი, დესტრუქტორი,
  3. ბეჭდვის ვირტუალური ფუნქცია.
  4.  
  5. Building კლასის მემკვიდრე კლასში House დაამატეთ მონაცემები rooms და porches. შემოიღეთ პარამეტრიანი კონსტრუქტორი,
  6. დესტრუქტორი და ბეჭდვის ფუნქცია.
  7.  
  8. House კლასის მემკვიდრე კლასში Office დაამატეთ მონაცემები computers და workers.შემოიღეთ პარამეტრიანი კონსტრუქტორი,
  9. დესტრუქტორი და ბეჭდვის ფუნქცია.
  10.  
  11. main-ში გააკეთეთ განაცხადი სამივე კლასის ობიექტზე. შექმენით დინამიკური მასივი სახელით a , რომელშიც შესაძლებელი იქნება
  12. ამ ობიექტების მისამართების შენახვა. a-ში შეინახეთ შექმნილი ობიექტების მისამართები და ერთი განმეორების შეტყობინებით(ციკლით)
  13. დაბეჭდეთ a-ს ელემენტების მონაცემები.
  14. */
  15.  
  16. #include <iostream>
  17.  
  18. using namespace std;
  19.  
  20. class Building {
  21. protected :
  22.     int floors, windows;
  23. public:
  24.     Building(){ floors = 0; windows = 0; }
  25.     Building(int f, int w);
  26.     ~Building(){}
  27.     virtual void print();
  28. };
  29.  
  30. Building::Building(int f, int w){
  31.     floors = f;
  32.     windows = w;
  33. }
  34.  
  35. void Building::print(){
  36.     cout << "I am building. I have  " << windows << " windows and " << floors << " floors;" << endl;
  37. }
  38.  
  39. class House :public Building{
  40. protected:
  41.     int rooms, porches;
  42. public:
  43.     House(){ rooms = 0; porches = 0; }
  44.     ~House(){}
  45.     House(int f, int w, int r, int p);
  46.     virtual void print();
  47. };
  48.  
  49. House::House(int f, int w, int r, int p) :Building(f, w){
  50.     rooms = r;
  51.     porches = p;
  52. }
  53.  
  54. void House::print(){
  55. Building::print();
  56.     cout << "I am house I have " << rooms << " rooms and " << porches << " porches" << endl;
  57. }
  58.  
  59. class Office :public House{
  60. private :
  61.     int computers, workers;
  62. public:
  63.     Office(){ computers = 0; workers = 0; }
  64.     ~Office(){}
  65.     Office(int f, int w, int r, int p, int c, int wor);
  66.     virtual void print();
  67. };
  68.  
  69. Office::Office(int f, int w, int r, int p, int c, int wor):House(f,w,r,p){
  70.     computers = c;
  71.     workers = wor;
  72. }
  73.  
  74. void Office::print(){
  75. House::print();
  76.     cout << "I am office I have " << computers << " computers and " << workers << " workers" << endl;
  77. }
  78.  
  79. int main(){
  80.  
  81.     Building b(4, 16);
  82.     House h(3, 12, 12, 1);
  83.     Office o(4, 20, 20, 4, 10, 10);
  84.  
  85.     Building* a[3];
  86.     a[0] = &b;
  87.     a[1] = &h;
  88.     a[2] = &o;
  89.  
  90.     for (int i = 0; i < 3; i++){
  91.         a[i]->print();
  92.         cout << endl << endl;
  93.     }
  94.  
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement