Advertisement
Guest User

cod

a guest
Dec 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Food
  6. {
  7.     string name;
  8.     int calories;
  9. public:
  10.     Food(string name, int calories) :name(name), calories(calories) { };
  11.     int getCalories()
  12.     {
  13.         return calories;
  14.     }
  15.  
  16. };
  17.  
  18. class Cake:public Food
  19. {
  20.     string mainIngridient;
  21. public:
  22.     Cake(string name, int calories, string mainIngridient) :Food(name, calories),
  23.         mainIngridient(mainIngridient) {};
  24.     string getMainIngridient()
  25.     {
  26.         return mainIngridient;
  27.     }
  28. };
  29.  
  30. int main()
  31. {
  32.     Food mancare("burger", 500);
  33.     Cake desert("amandina", 300, "ou");
  34.     cout << mancare.getCalories()<<'\n';
  35.     cout << desert.getMainIngridient() << '\n' << desert.getCalories();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement