Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- საბაზო კლასში Building გაითვალისწინეთ მონაცემები floors და windows; ასევე პარამეტრიანი კონსტრუქტორი, დესტრუქტორი,
- ბეჭდვის ვირტუალური ფუნქცია.
- Building კლასის მემკვიდრე კლასში House დაამატეთ მონაცემები rooms და porches. შემოიღეთ პარამეტრიანი კონსტრუქტორი,
- დესტრუქტორი და ბეჭდვის ფუნქცია.
- House კლასის მემკვიდრე კლასში Office დაამატეთ მონაცემები computers და workers.შემოიღეთ პარამეტრიანი კონსტრუქტორი,
- დესტრუქტორი და ბეჭდვის ფუნქცია.
- main-ში გააკეთეთ განაცხადი სამივე კლასის ობიექტზე. შექმენით დინამიკური მასივი სახელით a , რომელშიც შესაძლებელი იქნება
- ამ ობიექტების მისამართების შენახვა. a-ში შეინახეთ შექმნილი ობიექტების მისამართები და ერთი განმეორების შეტყობინებით(ციკლით)
- დაბეჭდეთ a-ს ელემენტების მონაცემები.
- */
- #include <iostream>
- using namespace std;
- class Building {
- protected :
- int floors, windows;
- public:
- Building(){ floors = 0; windows = 0; }
- Building(int f, int w);
- ~Building(){}
- virtual void print();
- };
- Building::Building(int f, int w){
- floors = f;
- windows = w;
- }
- void Building::print(){
- cout << "I am building. I have " << windows << " windows and " << floors << " floors;" << endl;
- }
- class House :public Building{
- protected:
- int rooms, porches;
- public:
- House(){ rooms = 0; porches = 0; }
- ~House(){}
- House(int f, int w, int r, int p);
- virtual void print();
- };
- House::House(int f, int w, int r, int p) :Building(f, w){
- rooms = r;
- porches = p;
- }
- void House::print(){
- Building::print();
- cout << "I am house I have " << rooms << " rooms and " << porches << " porches" << endl;
- }
- class Office :public House{
- private :
- int computers, workers;
- public:
- Office(){ computers = 0; workers = 0; }
- ~Office(){}
- Office(int f, int w, int r, int p, int c, int wor);
- virtual void print();
- };
- Office::Office(int f, int w, int r, int p, int c, int wor):House(f,w,r,p){
- computers = c;
- workers = wor;
- }
- void Office::print(){
- House::print();
- cout << "I am office I have " << computers << " computers and " << workers << " workers" << endl;
- }
- int main(){
- Building b(4, 16);
- House h(3, 12, 12, 1);
- Office o(4, 20, 20, 4, 10, 10);
- Building* a[3];
- a[0] = &b;
- a[1] = &h;
- a[2] = &o;
- for (int i = 0; i < 3; i++){
- a[i]->print();
- cout << endl << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement