Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include<string.h>
- using namespace std;
- class lista;
- class fructe {
- private:
- int tip;
- string nume;
- int pret;
- string valabilitate;
- int cantitate;
- fructe* urm;
- public:
- fructe(int t,string n, int p, string valb, int cnt) {
- tip = t;
- nume = n;
- pret = p;
- valabilitate = valb;
- cantitate = cnt;
- urm = NULL;
- }
- virtual void afisare() {
- cout <<"nume: "<< nume << endl;
- cout <<"pret: "<< pret << endl;
- cout << "valabilitate: "<<valabilitate << endl;
- cout << "cantitate: "<<cantitate << endl;
- }
- friend class lista;
- };
- class autohtone : public fructe {
- private:
- string judet;
- string producator;
- string data_cules;
- public:
- autohtone(int t,string n, int p, string valb, int cnt, string jud, string prod, string data_c) :fructe(t,n, p, valb, cnt) {
- judet = jud;
- producator = prod;
- data_cules = data_c;
- }
- void afisare() {
- fructe::afisare();
- cout << "JUDET: " << judet << endl;
- cout << "producator: "<<producator << endl;
- cout << "data cules: "<<data_cules << endl;
- }
- friend class lista;
- };
- class import: public fructe {
- private:
- string tara_prov;
- string importator;
- public:
- import(int t,string n, int p, string valb, int cnt, string tara_p, string imp) : fructe(t,n, p, valb, cnt) {
- tara_prov = tara_p;
- importator = imp;
- }
- void afisare() {
- fructe::afisare();
- cout << "TARA: " << tara_prov << endl;
- cout <<"importator: "<< importator << endl;
- }
- friend class lista;
- };
- class lista {
- public:
- fructe* head;
- void adaugare_fructe(fructe* a);
- void afisare_fructe();
- void cautare_valabilitate(string valabilitate);
- int afisare_stoc();
- void vanzare(string nume,int cnt);
- void max();
- };
- void lista::adaugare_fructe(fructe* a) {
- fructe* p;
- p = head;
- if (p == NULL) {
- head = a;
- }
- else if (a->nume < head->nume) {
- a->urm = head;
- head = a;
- }
- else {
- while (p->urm && a->nume > p->urm->nume) p = p->urm;
- a->urm = p->urm;
- p->urm = a;
- }
- }
- void lista::afisare_fructe() {
- fructe* p;
- p = head;
- if (p == NULL) cout << "LISTA GOALA";
- else
- while (p) {
- p->afisare();
- p = p->urm;
- }
- }
- void lista::cautare_valabilitate(string valabilitate) {
- fructe* p;
- p = head;
- if (p == NULL) cout << "lista goala";
- else
- while (p) {
- if (p->valabilitate == valabilitate)
- p->afisare();
- p = p->urm;
- }
- }
- int lista::afisare_stoc() {
- int stoc = 0;
- fructe* p;
- p = head;
- if (p == NULL) return 0;
- else
- while (p) {
- stoc = stoc + p->cantitate;
- p = p->urm;
- }
- return stoc;
- }
- void lista::vanzare(string nume,int cnt) {
- fructe* p,*q;
- p = q = head;
- if (p == NULL) cout << "lista vida";
- else
- while (p && p->nume!=nume){
- q = p;
- p = p->urm;
- }
- if (p==NULL) cout << "nu exista fructul";
- else
- if (p->cantitate > cnt) p->cantitate = p->cantitate - cnt;
- else
- if (p != q) {
- q->urm = p->urm;
- delete p;
- }
- else {
- head = p->urm;
- delete q;
- }
- }
- void lista::max()
- {
- int max = 0;
- fructe* p,*q;
- p = q = head;
- if (p == NULL) cout << "lista vida";
- while (p) {
- if (p->pret > max && p->tip==1) max = p->pret;
- p = p->urm;
- }
- while (q) {
- if (q->pret == max&& q->tip==1) q->afisare();
- q = q->urm;
- }
- }
- void introducere(lista &l, int x) {
- fructe *f;
- autohtone *a;
- import* i;
- string nume, valabilitate, judet, producator, data_cules, tara, importator;
- int pret, cantitate;
- cout << "nume: "; cin >> nume;
- cout << "pret: "; cin >> pret;
- cout << "valabilitate: "; cin >> valabilitate;
- cout << "cantitate: "; cin >> cantitate;
- if (x == 0) {
- cout << "judet: "; cin >> judet;
- cout << "producator:"; cin >> producator;
- cout << "data la care au fost culese:"; cin >> data_cules;
- a = new autohtone(0,nume, pret,valabilitate, cantitate, judet, producator, data_cules);
- f = a;
- l.adaugare_fructe(f);
- }
- else
- if (x == 1) {
- cout << "tara provenienta: "; cin >> tara;
- cout << "importaor: "; cin >> importator;
- i = new import(1,nume, pret, valabilitate, cantitate, tara, importator);
- f = i;
- l.adaugare_fructe(f);
- }
- }
- int main() {
- int opt,cnt;
- string nume,vlb;
- lista l;
- l.head = NULL;
- do {
- cout << "1.adaugare autohtone" << endl;
- cout << "2.adaugare import" << endl;
- cout << "3.afisare lista " << endl;
- cout << "4.afisare stoc(cantitatea totala de frct)" << endl;
- cout << "5 cautare dupa valabilitate " << endl;
- cout << "6.vanzare: " << endl;
- cout << "7.pret max import" << endl;
- cin >> opt;
- switch (opt)
- {
- case 1:
- introducere(l, 0);
- break;
- case 2:
- introducere(l, 1);
- break;
- case 3:
- l.afisare_fructe();
- break;
- case 4:
- cout << l.afisare_stoc();
- break;
- case 5:
- cout << "valabilitate cautata:"; cin >> vlb;
- l.cautare_valabilitate(vlb);
- break;
- case 6:
- cout << "nume: "; cin >> nume;
- cout << "cantitate "; cin >> cnt;
- l.vanzare(nume, cnt);
- break;
- case 7:
- l.max();
- break;
- default: cout << "optiune gresita";
- break;
- }
- } while (opt);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement