Alx09

Problema POO de 6.5

Mar 2nd, 2021
818
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include <string>
  4. #include<list>
  5. #include <iterator>
  6. #include <fstream>
  7. using namespace std;
  8.  
  9. class Articol {
  10. private:
  11.     int tip;
  12.     string denumire;
  13.     double pret, cantitate;
  14. public:
  15.     Articol(int tip, string denumire, double pret, double cantitate) {
  16.         this->tip = tip;
  17.         this->denumire = denumire;
  18.         this->pret = pret;
  19.         this->cantitate = cantitate;
  20.     }
  21.     virtual void Afis() {
  22.         cout << denumire<<" "<< pret <<" "<<cantitate<<" " ;
  23.     }
  24. };
  25.  
  26. class Perisabil: public Articol{
  27. private:
  28.     string dataExp, categ;
  29. public:
  30.     Perisabil(int tip, string denumire, double pret, double cantitate, string dataExp, string categ) : Articol(0, denumire, pret, cantitate) {
  31.         this->dataExp = dataExp;
  32.         this->categ = categ;
  33.     }
  34.     void Afis() {
  35.         Articol::Afis();
  36.         cout << dataExp << " " << categ<<endl;
  37.     }
  38. };
  39.  
  40. class NePerisabil : public Articol {
  41. private:
  42.     string domeniu, material;
  43. public:
  44.     NePerisabil(int tip, string denumire, double pret, double cantitate, string domeniu, string material) : Articol(1, denumire, pret, cantitate) {
  45.         this->domeniu= domeniu;
  46.         this->material = material;
  47.     }
  48.     void Afis() {
  49.         Articol::Afis();
  50.         cout << domeniu << " " << material << endl;
  51.     }
  52. };
  53.  
  54. istream &operator>>(istream &in, Articol *& a) {
  55.     int tip;
  56.     string denumire;
  57.     double pret, cantitate;
  58.  
  59.     string dataExp, categ;
  60.     string domeniu, material;
  61.  
  62.     cout << "Denumire: "; in >> denumire;
  63.     cout << "Pret: "; in >> pret;
  64.     cout << "Cantitate: "; in >> cantitate;
  65.     cout << "Tip(0-Perisabil, 1-Neperisabil) "; in >> tip;
  66.  
  67.     if (tip == 0) {
  68.         cout << "Data expirari: "; in >> dataExp;
  69.         cout << "Categorie: "; in >> categ;
  70.         a = new Perisabil(0, denumire, pret, cantitate, dataExp, categ);
  71.     }
  72.     else
  73.     {
  74.         cout << "Domeniu: "; in >> domeniu;
  75.         cout << "Material: "; in >> material;
  76.         a = new NePerisabil(1, denumire, pret, cantitate, domeniu, material);
  77.     }
  78.     return in;
  79. }
  80.  
  81. ifstream &operator>>(ifstream &in, Articol *& a) {
  82.     int tip;
  83.     string denumire;
  84.     double pret, cantitate;
  85.  
  86.     string dataExp, categ;
  87.     string domeniu, material;
  88.  
  89.      in >> denumire;
  90.      in >> pret;
  91.      in >> cantitate;
  92.      in >> tip;
  93.    
  94.     if (tip == 0) {
  95.      in >> dataExp;
  96.      in >> categ;
  97.         a = new Perisabil(0, denumire, pret, cantitate, dataExp, categ);
  98.     }
  99.     else
  100.     {
  101.         in >> domeniu;
  102.         in >> material;
  103.         a = new NePerisabil(1, denumire, pret, cantitate, domeniu, material);
  104.     }
  105.     return in;
  106. }
  107.  
  108. int main() {
  109.     list<Articol *> lista;
  110.     list<Articol *>::iterator it;
  111.     int opt;
  112.     Articol *a = NULL;
  113.     ifstream f("in.txt");
  114.     do {
  115.         cout << "0. Iesire\n";
  116.         cout << "1. Citire Tast\n";
  117.         cout << "2. Afisare\n";
  118.         cout << "3. Citire Fiser\n";
  119.         cout << "Optiunea aleasa: "; cin >> opt;
  120.         switch (opt)
  121.         {
  122.         case 0: exit(0);
  123.         case 1:
  124.             cin >> a;
  125.             lista.push_back(a);
  126.             break;
  127.         case 2:
  128.             for (it = lista.begin(); it != lista.end(); it++)(*it)->Afis();
  129.             break;
  130.         case 3:
  131.             while (!f.eof())
  132.             {
  133.                 f >> a;
  134.                 lista.push_back(a);
  135.             }
  136.             lista.erase(--lista.end() ); // stergem ulitmul elment din lista deoarece este vid
  137.             break;
  138.         default:
  139.             break;
  140.         }
  141.  
  142.     } while (1);
  143.     return 0;
  144. }
  145.  
  146.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×