Advertisement
kalin729

dsa

Jun 19th, 2017 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<vector>
  4. using namespace std;
  5. class Sladoled
  6. {
  7. private:
  8.     string vid;
  9.     int broi;
  10.     double cena;
  11. public:
  12.     Sladoled();
  13.     Sladoled (string, int, double);
  14.     void Read();
  15.     void Inf();
  16.     void Prodadeni(int x);
  17.     void Dobaveni(int x);
  18.     string GetVid();
  19.     int GetBroi();
  20.     double GetCena();
  21.     bool IsCena();
  22.     void Add();
  23.     ~Sladoled();
  24. };
  25. Sladoled::Sladoled()
  26. {
  27.     vid="";
  28.     broi=0;
  29.     cena=0;
  30. };
  31. Sladoled::Sladoled(string vid1,int broi1, double cena1)
  32. {
  33.     vid=vid1;
  34.     broi=broi1;
  35.     cena=cena1;
  36. }
  37. Sladoled::~Sladoled()
  38. {
  39.  
  40. }
  41. void Sladoled::Read()
  42. {
  43.     cout<<"vid;";
  44.     cin.sync();
  45.     getline(cin,vid);
  46.     cout<<"Braoi:";
  47.     cin>>broi;
  48.     cout<<"Cena: ";
  49.     cin>>cena;
  50. }
  51. void Sladoled ::Inf()
  52. {
  53.     cout<<"vid;"<<vid<<endl;
  54.     cout<<"broi"<<broi<<endl;
  55.     cout<<"cena"<<cena<<endl;
  56. }
  57. void Sladoled::Prodadeni(int x)
  58. {
  59.     broi=broi-x;
  60. }
  61. void Sladoled::Dobaveni(int x)
  62. {
  63.     broi=broi+x;
  64. }
  65. string Sladoled::GetVid()
  66. {
  67.     return vid;
  68. }
  69. int Sladoled::GetBroi()
  70. {
  71.     return broi;
  72. }
  73. double Sladoled::GetCena()
  74. {
  75.     return cena;
  76. }
  77. bool Sladoled::IsCena()
  78. {
  79.     if (cena==0)
  80.         return true;
  81.     else
  82.     return false;
  83. }
  84. void Sladoled::Add(int x)
  85. {
  86.     broi = broi + x;
  87. }
  88. int main()
  89. {
  90.     char ch;
  91.     vector<Sladoled>a;
  92.     Sladoled r;
  93.     do
  94.     {
  95.         r.Read();
  96.         a.push_back(r);
  97.         cout<<"Prodyljete da ili ne:";
  98.         cin>>ch;
  99.     }
  100.     while(ch!='Y'&&ch!='y');
  101.     for(int i=0; i<a.size(); i++)
  102.     {
  103.     cout<<"Sladoled: "<<i+1<<endl;
  104.     a[i].Inf();
  105.     }
  106.     for(int i=0; i<a.size(); i++)
  107.     {
  108.      int y;
  109.      cout<<"Prodadeni baravinki:";
  110.      cin>>y;
  111.      if(a[i].GetVid()=="baravinki")
  112.      {
  113.      a[i].Prodadeni(y);
  114.      }
  115.     }
  116.     string n;
  117.     int add;
  118.     for(int i=0; i<a.size(); i++)
  119.     {
  120.         if(a[i].GetVid()==n)
  121.         {
  122.             a[i].Add(add);
  123.         }
  124.     }
  125. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement