Advertisement
Proff_Ust

products

Nov 10th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. using namespace std;
  4. class CProduct
  5. {
  6. private:
  7.     string name;
  8.     float price;
  9.     string manufacturer;
  10. public:
  11.     CProduct()
  12.     {
  13.         this->name = "";
  14.         this->price = 0;
  15.         this->manufacturer = "";
  16.     }
  17.     CProduct(string newName, float newPrice, string newManufacturer)
  18.     {
  19.         this->name = newName;
  20.         this->price = newPrice;
  21.         this->manufacturer = newManufacturer;
  22.     }
  23.  
  24.     float Task1(float rate)
  25.     {
  26.         return this->price/rate;
  27.     }
  28.  
  29.     float Task2(float rate)
  30.     {
  31.         if(this->name.find("Toyota")!=string::npos)
  32.             return 1.1*(this->price/rate);
  33.         else
  34.             return this->price/rate;
  35.     }
  36.  
  37.     string toString()
  38.     {
  39.         ostringstream temp;
  40.         temp<<"Наименование товара: "<<this->name<<endl;
  41.         temp<<"Цена товара: "<<this->price<<endl;
  42.         temp<<"Производитель товара: "<<this->manufacturer<<endl;
  43.         return temp.str();
  44.     }
  45.  
  46.     ~CProduct()
  47.     {
  48.         cout<<"Объект уничтожен"<<endl;
  49.     }
  50. };
  51.  
  52. int main()
  53. {
  54.     setlocale(0,"Russian");
  55.     string inputName;
  56.     string inputManufacturer;
  57.     float inputPrice;
  58.     //float inputRate;
  59.     cout<<"Введите наименование товара: ";
  60.     cin>>inputName;
  61.     cout<<"Введите цену товара: ";
  62.     cin>>inputPrice;
  63.     cout<<"Введите производителя товара: ";
  64.     cin>>inputManufacturer;
  65.     //cout<<"Введите курс валюты: ";
  66.     //cin>>inputRate;
  67.     CProduct* productZero = new CProduct(inputName, inputPrice, inputManufacturer);
  68.     CProduct* productOne = new CProduct("Машина Toyota", 1000000, "Japan");
  69.     CProduct* productTwo = new CProduct("Машина Лада", 200000, "Russia");
  70.  
  71.     cout<<productZero->toString()<<endl;
  72.     cout<<productOne->toString()<<endl;
  73.     cout<<productTwo->toString()<<endl;
  74.  
  75.     cout<<"Цена введенного продукта в долларах: "<<productZero->Task1(63.78)<<endl;
  76.     cout<<"Цена первого продукта в долларах: "<<productOne->Task1(63.78)<<endl;
  77.     cout<<"Цена второго продукта в долларах: "<<productTwo->Task1(63.78)<<endl;
  78.  
  79.     cout<<endl;
  80.     cout<<"Цена введенного продукта в долларах после изменения цены: "<<productZero->Task2(63.78)<<endl;
  81.     cout<<"Цена первого продукта в долларах после изменения цены: "<<productOne->Task2(63.78)<<endl;
  82.     cout<<"Цена второго продукта в долларах после изменения цены: "<<productTwo->Task2(63.78)<<endl;
  83.  
  84.     delete productOne;
  85.     delete productTwo;
  86.     delete productZero;
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement