0% found this document useful (0 votes)
837 views

Meniu C++

This C++ program manages a database of medicines. It defines a struct to store medicine name, code, price and grams. It loads initial medicines, then displays a menu to select operations like sorting by price, searching by name/code, adding/modifying medicines. Based on the selection, it performs the operation like sorting, searching the array of medicines and displays the results. The menu allows selecting options until exit is chosen.

Uploaded by

Carlan Marcel
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
837 views

Meniu C++

This C++ program manages a database of medicines. It defines a struct to store medicine name, code, price and grams. It loads initial medicines, then displays a menu to select operations like sorting by price, searching by name/code, adding/modifying medicines. Based on the selection, it performs the operation like sorting, searching the array of medicines and displays the results. The menu allows selecting options until exit is chosen.

Uploaded by

Carlan Marcel
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<iostream.

h>
#include<string.h>
int main()
{struct medicament
{char nume[30];
long cod;
float pr,gm;
}v[100],aux;
int n,i,j,max=0,min=32000,op;
char d[30];
long rez;
long rezi;
float pri;
cout<<"0. Adauga medicamente in memorie (OBLIGATORIU)"<<endl;
cout<<"1. Cel mai scump medicament"<<endl;
cout<<"2. Cel mai ieftin medicament"<<endl;
cout<<"3. Sortare crescatoare dupa cod"<<endl;
cout<<"4. Sortare descrescatoare dupa cod"<<endl;
cout<<"5. Sortare crescatoare dupa pret"<<endl;
cout<<"6. Sortare descrescatoare dupa pret"<<endl;
cout<<"7. Adaugare medicament nou"<<endl;
cout<<"8. Cautare medicament in functie de nume"<<endl;
cout<<"9. Cautare medicament in funtcie de cod"<<endl;
cout<<"10. Modificare pret"<<endl;
cout<<"11. Listare"<<endl;
cout<<"12. Inchide program"<<endl;
cout<<endl;
do{ cout<<endl;
cout<<"Alege optiune: ";cin>>op;
cout<<endl;
if(op==0)
{cout<<"Numar de medicamente =";cin>>n; cout<<endl;
for(i=1;i<=n;i++)
{cout<<"Medicament "<<i<<": "; cin>>v[i].nume;
cout<<"Cod : ";
cin>>v[i].cod;
cout<<"Pret : "; cin>>v[i].pr;
cout<<"Gramaj : "; cin>>v[i].gm;
}
}
if(op==1)
{max=0;
for(i=1;i<=n;i++)
if(v[i].pr>max)
max=v[i].pr;
for(i=1;i<=n;i++)
if(v[i].pr==max)
{cout<<"Medicament "<<i<<": "; cout<<v[i].nume<<endl;
cout<<"Cod : ";
cout<<v[i].cod<<endl;
cout<<"Pret : "; cout<<v[i].pr<<endl;
cout<<"Gramaj : "; cout<<v[i].gm<<endl;
}
}
if(op==2)
{min=32000;
for(i=1;i<=n;i++)
if(v[i].pr<min)

min=v[i].pr;
for(i=1;i<=n;i++)
if(v[i].pr==min)
{cout<<"Medicament "<<i<<": "; cout<<v[i].nume<<endl;
cout<<"Cod : ";
cout<<v[i].cod<<endl;
cout<<"Pret : "; cout<<v[i].pr<<endl;
cout<<"Gramaj : "; cout<<v[i].gm<<endl;
}
}
if(op==3)
{
for(i=1;i<=n-1;i++)
for(j=i+1;j<=n;j++)
if(v[i].cod>v[j].cod)
{aux=v[i];
v[i]=v[j];
v[j]=aux;
}
for(i=1;i<=n;i++)
{cout<<"Medicament "<<i<<": "; cout<<v[i].nume<<endl;
cout<<"Cod : ";
cout<<v[i].cod<<endl;
cout<<"Pret : "; cout<<v[i].pr<<endl;
cout<<"Gramaj : "; cout<<v[i].gm<<endl;
}
}
if(op==4)
{for(i=1;i<=n-1;i++)
for(j=i+1;j<=n;j++)
if(v[i].cod<v[j].cod)
{aux=v[i];
v[i]=v[j];
v[j]=aux;
}
for(i=1;i<=n;i++)
{cout<<"Medicament "<<i<<": "; cout<<v[i].nume<<endl;
cout<<"Cod : ";
cout<<v[i].cod<<endl;
cout<<"Pret : "; cout<<v[i].pr<<endl;
cout<<"Gramaj : "; cout<<v[i].gm<<endl;
}
}
if(op==5)
{ for(i=1;i<=n-1;i++)
for(j=i+1;j<=n;j++)
if(v[i].pr>v[j].pr)
{aux=v[i];
v[i]=v[j];
v[j]=aux;}
for(i=1;i<=n;i++)
{cout<<"Medicament "<<i<<": "; cout<<v[i].nume<<endl;
cout<<"Cod : ";
cout<<v[i].cod<<endl;
cout<<"Pret : "; cout<<v[i].pr<<endl;
cout<<"Gramaj : "; cout<<v[i].gm<<endl;
}
}
if(op==6)
{for(i=1;i<=n-1;i++)
for(j=i+1;j<=n;j++)
if(v[i].pr<v[j].pr)
{aux=v[i];
v[i]=v[j];

v[j]=aux;
}
for(i=1;i<=n;i++)
{cout<<"Medicament "<<i<<": "; cout<<v[i].nume<<endl;
cout<<"Cod : ";
cout<<v[i].cod<<endl;
cout<<"Pret : "; cout<<v[i].pr<<endl;
cout<<"Gramaj : "; cout<<v[i].gm<<endl;
}
}
if(op==7)
{n++;
cout<<"Medicament :"; cin>>v[n].nume;cout<<endl;
cout<<"Cod : "; cin>>v[n].cod;cout<<endl;
cout<<"Pret : "; cin>>v[n].pr;cout<<endl;
cout<<"Gramaj : "; cin>>v[n].gm;cout<<endl;
}
if(op==8)
{cout<<"Denumire :"; cin>>d;
for(i=1; i<=n; i++)
if(strcmp(v[i].nume,d)==0)
{cout<<"Medicament "<<i<<": "; cout<<v[i].nume<<endl;
cout<<"Cod : "; cout<<v[i].cod<<endl;
cout<<"Pret : "; cout<<v[i].pr<<endl;
cout<<"Gramaj : ";cout<<v[i].gm<<endl;}
}
if(op==9)
{cout<<"Cod :"; cin>>rez; cout<<endl;
for(i=1; i<=n; i++)
if(v[i].cod==rez)
{cout<<"Medicament "<<i<<": "; cout<<v[i].nume<<endl;
cout<<"Cod : "; cout<<v[i].cod<<endl;
cout<<"Pret : "; cout<<v[i].pr<<endl;
cout<<"Gramaj : ";cout<<v[i].gm<<endl;}
}
if(op==10)
{cout<<"Codul produsului :" ; cin>>rezi; cout<<endl;
for(i=1; i<=n; i++)
if(v[i].cod==rezi)
{cout<<"Pretul nou :"; cin>>pri; cout<<endl;
v[i].pr=pri;}
}
if(op==11)
{for(i=1;i<=n;i++)
{cout<<"Medicament "<<i<<": "; cout<<v[i].nume<<endl;
cout<<"Cod : "; cout<<v[i].cod<<endl;
cout<<"Pret : "; cout<<v[i].pr<<endl;
cout<<"Gramaj : ";cout<<v[i].gm<<endl;
}
}
}while(op<=11);
return 0; }

You might also like