SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 66 in 339 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. class IBuilding
  7. {
  8. public:
  9.     virtual void TotalHealth() = 0;
  10. };
  11.  
  12. class Barracks : public IBuilding
  13. {
  14. public:
  15.     void TotalHealth()
  16.     {
  17.         cout << "Health of Barrack is :" << 100;
  18.     }
  19. };
  20.  
  21. class Temple : public IBuilding
  22. {
  23. public:
  24.     void TotalHealth()
  25.     {
  26.         cout << "Health of Temple is :" << 75;
  27.     }
  28. };
  29.  
  30. class Farmhouse : public IBuilding
  31. {
  32. public:
  33.     void TotalHealth()
  34.     {
  35.         cout << "Health of Farmhouse is :" << 50;
  36.     }
  37. };
  38.  
  39. int main()
  40. {
  41.     vector<IBuilding*> BuildingTypes;
  42.     int choice;
  43.     cout << "Specify the different building types in your village" << endl;
  44.     while (true)
  45.     {
  46.         cout << "Barracks(1) Temple(2) Farmhouse(3) Go(0): ";
  47.         cin >> choice;
  48.         if (choice == 0)
  49.         {
  50.             break;
  51.         }
  52.         else if (choice == 1)
  53.         {
  54.             BuildingTypes.push_back(new Barracks);
  55.         }
  56.         else if (choice == 2)
  57.         {
  58.             BuildingTypes.push_back(new Temple);
  59.         }
  60.         else
  61.         {
  62.             BuildingTypes.push_back(new Farmhouse);
  63.         }
  64.     }
  65.     cout << endl;
  66.     cout << "There are total " << BuildingTypes.size() << " buildings" << endl;
  67.     for (int i = 0; i < BuildingTypes.size(); i++)
  68.     {
  69.         BuildingTypes[i]->TotalHealth();
  70.         cout << endl;
  71.     }
  72.     for (int i = 0; i < BuildingTypes.size(); i++)
  73.     {
  74.         delete BuildingTypes[i];
  75.     }
  76.     _getch();
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top