Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class item{
- public:
- virtual void show() = 0;
- };
- class product: public item{
- string name;
- int cost;
- public:
- product(string name, int cost){
- this->name = name;
- this->cost = cost;
- }
- protected:
- void show()override{
- cout << "Товар: " << name << " , цена: " << cost << endl;;
- }
- };
- class milk_product:public item{
- string name;
- int cost;
- public:
- milk_product(string name, int cost){
- this->name = name;
- this->cost = cost;
- }
- protected:
- void show()override{
- cout << "Товар: " << name << " , цена: " << cost << endl;
- }
- };
- class toy:public item{
- string name;
- int cost;
- public:
- toy(string name, int cost){
- this->name = name;
- this->cost = cost;
- }
- protected:
- void show()override{
- cout << "Товар: " << name << " , цена: " << cost << endl;
- }
- };
- int main(){
- string a1,b1,c1;
- cout << "Введите игрушку: ";
- getline(cin,a1);
- cout << "Введите продукт: ";
- getline(cin,b1);
- cout << "Введите молочный продукт: ";
- getline(cin,c1);
- cout << "===============================" << endl;
- item *begin[3];
- toy a(a1,3000);
- milk_product b(b1, 200);
- product c(c1, 40);
- begin[0] = &a;
- begin[1] = &b;
- begin[2] = &c;
- for(int i=0;i<3;i++){
- begin[i]->show();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement