Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- using namespace std;
- class CProduct
- {
- private:
- string name;
- float price;
- string manufacturer;
- public:
- CProduct()
- {
- this->name = "";
- this->price = 0;
- this->manufacturer = "";
- }
- CProduct(string newName, float newPrice, string newManufacturer)
- {
- this->name = newName;
- this->price = newPrice;
- this->manufacturer = newManufacturer;
- }
- float Task1(float rate)
- {
- return this->price/rate;
- }
- float Task2(float rate)
- {
- if(this->name.find("Toyota")!=string::npos)
- return 1.1*(this->price/rate);
- else
- return this->price/rate;
- }
- string toString()
- {
- ostringstream temp;
- temp<<"Наименование товара: "<<this->name<<endl;
- temp<<"Цена товара: "<<this->price<<endl;
- temp<<"Производитель товара: "<<this->manufacturer<<endl;
- return temp.str();
- }
- ~CProduct()
- {
- cout<<"Объект уничтожен"<<endl;
- }
- };
- int main()
- {
- setlocale(0,"Russian");
- string inputName;
- string inputManufacturer;
- float inputPrice;
- //float inputRate;
- cout<<"Введите наименование товара: ";
- cin>>inputName;
- cout<<"Введите цену товара: ";
- cin>>inputPrice;
- cout<<"Введите производителя товара: ";
- cin>>inputManufacturer;
- //cout<<"Введите курс валюты: ";
- //cin>>inputRate;
- CProduct* productZero = new CProduct(inputName, inputPrice, inputManufacturer);
- CProduct* productOne = new CProduct("Машина Toyota", 1000000, "Japan");
- CProduct* productTwo = new CProduct("Машина Лада", 200000, "Russia");
- cout<<productZero->toString()<<endl;
- cout<<productOne->toString()<<endl;
- cout<<productTwo->toString()<<endl;
- cout<<"Цена введенного продукта в долларах: "<<productZero->Task1(63.78)<<endl;
- cout<<"Цена первого продукта в долларах: "<<productOne->Task1(63.78)<<endl;
- cout<<"Цена второго продукта в долларах: "<<productTwo->Task1(63.78)<<endl;
- cout<<endl;
- cout<<"Цена введенного продукта в долларах после изменения цены: "<<productZero->Task2(63.78)<<endl;
- cout<<"Цена первого продукта в долларах после изменения цены: "<<productOne->Task2(63.78)<<endl;
- cout<<"Цена второго продукта в долларах после изменения цены: "<<productTwo->Task2(63.78)<<endl;
- delete productOne;
- delete productTwo;
- delete productZero;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement