Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <algorithm>
- using namespace std;
- ifstream fin("input.txt");
- class Goods {
- protected:
- string name;
- double cost;
- string made;
- int age;
- int type;
- public:
- virtual void show() = 0;
- void printType()
- {
- if (type == 1)
- cout << "Toy\n";
- if (type == 2)
- cout << "Book\n";
- if (type == 3)
- cout << "Sports Equipment\n";
- }
- Goods(string name, double cost, string made, int age)
- : name(name), cost(cost), made(made), age(age) {};
- };
- //Toy(название, цена, производитель, материал,возраст, на который рассчитана),
- class Toy : public Goods
- {
- string material;
- public:
- Toy(string name, double cost, string made, int age, string material)
- :Goods(name, cost, made, age), material(material) {
- type = 1;
- };
- void show() override
- {
- cout << name << ' ' << cost << ' ' << made << ' ' << age
- << ' ' << material << endl << endl;
- }
- };
- //, Book (название, автор, цена, издательство, возраст, на который рассчитана)
- class Book : public Goods {
- string autor;
- public:
- Book(string name, double cost, string made, int age, string autor)
- :Goods(name, cost, made, age), autor(autor) {
- type = 2;
- };
- void show() override
- {
- cout << name << ' ' << cost << ' ' << made << ' ' << age
- << ' ' << autor << endl << endl;
- }
- };
- // SportsEquipment (название, цена, производитель, возраст, на который рассчитан).
- class SportsEquipment : public Goods {
- public:
- SportsEquipment(string name, double cost, string made, int age)
- :Goods(name, cost, made, age) {
- type = 3;
- };
- void show() override
- {
- cout << name << ' ' << cost << ' ' << made << ' ' << age
- << endl;
- }
- };
- const int MAXSIZE = 100;
- int main()
- {
- /*
- 3
- 1 MyFistToy 666 Russia 18 LaTeX
- 2 MyFirstMatAnTime 228 USA 50 Sahno
- 3 MyFirstSki 333 France 4
- */
- int n;
- fin >> n;
- Goods* a[MAXSIZE];
- for (int i = 0; i < n; ++i)
- {
- int type;
- fin >> type;
- string name, made;
- double cost;
- int age;
- string feature;
- fin >> name >> cost >> made >> age;
- if (type != 3)
- fin >> feature;
- if (type == 1)
- a[i] = new Toy(name, cost, made, age, feature);
- if (type == 2)
- a[i] = new Book(name, cost, made, age, feature);
- if (type == 3)
- a[i] = new SportsEquipment(name, cost, made, age);
- }
- for (int i = 0; i < n; ++i)
- {
- a[i]->show();
- cout << "It's a ";
- a[i]->printType();
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement