Advertisement
evcamels

lab-8_var-9

Dec 17th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. class item{
  5. public:
  6. virtual void show() = 0;
  7. };
  8. class product: public item{
  9. string name;
  10. int cost;
  11. public:
  12. product(string name, int cost){
  13. this->name = name;
  14. this->cost = cost;
  15. }
  16. protected:
  17. void show()override{
  18. cout << "Товар: " << name << " , цена: " << cost << endl;;
  19. }
  20. };
  21. class milk_product:public item{
  22. string name;
  23. int cost;
  24. public:
  25. milk_product(string name, int cost){
  26. this->name = name;
  27. this->cost = cost;
  28. }
  29. protected:
  30. void show()override{
  31. cout << "Товар: " << name << " , цена: " << cost << endl;
  32. }
  33. };
  34. class toy:public item{
  35. string name;
  36. int cost;
  37. public:
  38. toy(string name, int cost){
  39. this->name = name;
  40. this->cost = cost;
  41. }
  42. protected:
  43. void show()override{
  44. cout << "Товар: " << name << " , цена: " << cost << endl;
  45. }
  46. };
  47. int main(){
  48. string a1,b1,c1;
  49. cout << "Введите игрушку: ";
  50. getline(cin,a1);
  51. cout << "Введите продукт: ";
  52. getline(cin,b1);
  53. cout << "Введите молочный продукт: ";
  54. getline(cin,c1);
  55. cout << "===============================" << endl;
  56. item *begin[3];
  57. toy a(a1,3000);
  58. milk_product b(b1, 200);
  59. product c(c1, 40);
  60. begin[0] = &a;
  61. begin[1] = &b;
  62. begin[2] = &c;
  63. for(int i=0;i<3;i++){
  64. begin[i]->show();
  65. }
  66. return 0;
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement