Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <conio.h>
- using namespace std;
- class Articole
- {
- int td,cod_produs,rezolutie,dimensiuni;
- char *producator;
- Articole *urm;
- public:
- Articole(int tip_derivat,int c, char *p, int r, int d)
- {
- td=tip_derivat;
- producator = new char[strlen(p)+1];
- strcpy(producator,p);
- cod_produs=c;
- rezolutie=r;
- dimensiuni=d;
- urm=NULL;
- }
- virtual void afisare()
- {
- cout<<"----------------------------"<<endl;
- cout<<"Producatorul este: "<<producator<<endl;
- cout<<"Codul este: "<<cod_produs<<endl;
- cout<<"Rezolutia este: "<<rezolutie<<endl;
- cout<<"Dimensiunile sunt: "<<dimensiuni<<endl;
- }
- friend class Lista;
- };
- class Scanere:public Articole
- {
- char *soft_inclus;
- int viteza;
- public:
- Scanere(int tip_derivat,int c, char *p,int r,int d,char *s,int v):Articole(tip_derivat,c,p,r,d)
- {
- soft_inclus = new char[strlen(s)+1];
- strcpy(soft_inclus,s);
- viteza=v;
- }
- void afisare()
- {
- Articole::afisare();
- cout<<"Softul este: "<<soft_inclus<<endl;
- cout<<"Viteza este: "<<viteza<<endl;
- }
- friend class Lista;
- };
- class Imprimante:public Articole
- {
- char *format,*tip;
- public:
- Imprimante(int tip_derivat,int c, char *p,int r,int d,char *f,char *t):Articole(tip_derivat,c,p,r,d)
- {
- format = new char[strlen(f)+1];
- strcpy(format,f);
- tip = new char[strlen(t)+1];
- strcpy(tip,t);
- }
- void afisare()
- {
- Articole::afisare();
- cout<<"Formatul este: "<<format<<endl;
- cout<<"Tipul este: "<<tip<<endl;
- }
- friend class Lista;
- };
- class Lista
- {
- public:
- Articole *head;
- void adaugare(Articole *prod);
- void afisare_lista();
- void cautare(char *soft);
- void stergere(char *prod);
- };
- void Lista::adaugare(Articole *a)
- {
- Articole *p;
- p=head;
- if(!p)
- head=a;
- else
- if(strcmp(a->producator,p->producator)<0)
- {
- a->urm=head;
- head=a;
- }
- else
- {
- while(p->urm && strcmp(a->producator,p->urm->producator)>0)
- p=p->urm;
- a->urm=p->urm;
- p->urm=a;
- }
- }
- void introducere(Lista &l, int x)
- {
- char producator[50],soft_inclus[50],format[50],tip_derivat[50],tip[50];
- int cod_produs,rezolutie,dimensiuni,viteza;
- Articole *a;
- cout<<"Introduceti producatorul: ";
- cin>>producator;
- cout<<"Introduceti codul: ";
- cin>>cod_produs;
- cout<<"Introduceti rezolutia: ";
- cin>>rezolutie;
- cout<<"Introduceti dimensiunea: ";
- cin>>dimensiuni;
- if(x==0)
- {
- Scanere *Sc;
- cout<<"Introduceti softul: ";
- cin>>soft_inclus;
- cout<<"Introduceti viteza: ";
- cin>>viteza;
- Sc = new Scanere(1,cod_produs,producator,rezolutie,dimensiuni,soft_inclus,viteza);
- a=Sc;
- l.adaugare(a);
- }
- else
- if(x==1)
- {
- Imprimante *Imp;
- cout<<"Introduceti format: ";
- cin>>format;
- cout<<"Introduceti tipul: ";
- cin>>tip;
- Imp = new Imprimante(2,cod_produs,producator,rezolutie,dimensiuni,format,tip);
- a=Imp;
- l.adaugare(a);
- }
- }
- void Lista::afisare_lista()
- {
- Articole *a;
- a=head;
- if(!a)
- cout<<"Lista este vida";
- else
- while(a)
- {
- a->afisare();
- a=a->urm;
- }
- }
- void Lista::cautare(char *soft)
- {
- Articole *a;
- Scanere *Sc;
- a=head;
- if(!a)
- cout<<"Lista este vida";
- else
- while(a)
- {
- if(a->td==1)
- {
- Sc = (Scanere*)a;
- if(strcmp(Sc->soft_inclus,soft)==0)
- a->afisare();
- }
- a=a->urm;
- }
- }
- void Lista::stergere(char *prod)
- {
- Articole *a,*q;
- a=q=head;
- if(!a)
- cout<<"Lista este vida";
- else
- {
- while(a && strcmp(a->producator,prod)!=0)
- {
- q=a;
- a=a->urm;
- }
- if(!a)
- cout<<"Producatorul nu exista in lista";
- else
- if(a!=q)
- {
- q->urm=a->urm;
- delete a;
- }
- else
- {
- head=a->urm;
- delete a;
- }
- }
- }
- int main()
- {
- int optiune;
- Lista l;
- l.head=NULL;
- do
- {
- cout<<"1. Adaugare scanere in lista"<<endl;
- cout<<"2. Adaugare imprimante in lista"<<endl;
- cout<<"3. Afisare articole"<<endl;
- cout<<"4. Afisare scanere cu un anumit soft"<<endl;
- cout<<"5. Stergere articol dupa producator"<<endl;
- cout<<"Dati o optiune: ";
- cin>>optiune;
- switch(optiune)
- {
- case 1:
- introducere(l,0);
- break;
- case 2:
- introducere(l,1);
- break;
- case 3:
- l.afisare_lista();
- break;
- case 4:
- char soft[50];
- cout<<"Introduceti numele softului: ";
- cin>>soft;
- l.cautare(soft);
- break;
- case 5:
- char prod[50];
- cout<<"Introduceti numele producatorului: ";
- cin>>prod;
- l.stergere(prod);
- l.afisare_lista();
- case 0:
- break;
- default:
- cout<<"Optiune gresita"<<endl;
- }
- }while(optiune);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement