Programul in C++
pls
Răspunsuri la întrebare
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream f_echipa("echipa.txt");
ifstream f_medicamente("medicamente.txt");
char echipa[20][50];
struct med{
char nume[50];
unsigned cantitate;
float pret;
char recomandari[100];
} m[100];
int citire_medicamente(){
int nrmed=0;
while(!f_medicamente.eof()){
f_medicamente >> m[nrmed].nume >> m[nrmed].cantitate >> m[nrmed].pret >> m[nrmed].recomandari;
nrmed++;
}
f_medicamente.close();
return nrmed;
}
void afisare_medicamente(int nr, bool sz=0){
cout << "\n\n\tLista medicamente : \n";
int i;
for(i=0;i<nr;i++){
if(m[i].nume != "$$deleted$$"){
if(sz==1 && m[i].cantitate==0)cout << m[i].nume << endl;
else if (sz==0) cout << m[i].nume << endl;
}
}
}
void stergere_medicament(int nr){
int i;
char snume[50];
cout << "\n\t\tNume medicament de sters :";
cin >> snume;
for(i=0;i<nr;i++){
if(m[i].nume == snume) strcpy(m[i].nume,"$$deleted");
}
}
void adaugare_medicament(int nr){
char nume[50];
unsigned cantitate;
float pret;
char rec[100];
cout << "\n\t\tCitire date medicament nou :";
cin >> nume >> cantitate >> pret >> rec;
strcpy(m[nr].nume,nume);
m[nr].cantitate = cantitate;
m[nr].pret = pret;
strcpy(m[nr].recomandari,rec);
nr++;
}
void afisare_stoc(int nr, bool st=0){
int i;
float suma=0;
for (i=0;i<nr;i++){
if(m[i].nume != "$$deleted$$"){
if(st) suma+= m[i].pret*m[i].cantitate;
else suma+= m[i].cantitate;
}
}
cout << "Stoc : " << suma;
}
int citire_echipa(){
int i=0;
while(!f_echipa.eof()){
f_echipa >> echipa[i++];
}
return i;
}
void afisare_echipa(int nr){
int i;
cout << "\n\n\tAfisare echipa :\n";
for(i=0;i<nr;i++){
cout << echipa[i] << endl;
}
}
int main(){
int ok=1, med=0, ech=0, alegere;
med = citire_medicamente();
ech = citire_echipa();
while(ok){
cout << "\n ==== $ $ ==== \n";
cout << "\n1. Lista medicamente";
cout << "\n2. Medicamente stoc zero";
cout << "\n3. Stergere medicament";
cout << "\n4. Adaugare medicament";
cout << "\n5. Valoare stoc";
cout << "\n6. Valoare valoare totala stoc";
cout << "\n7. Echipa";
cout << "\n0. Iesire";
cout << "\n\tOptiune : ";
cin >> alegere;
switch(alegere){
case 1 :
afisare_medicamente(med);
break;
case 2 :
afisare_medicamente(med, 1);
break;
case 3:
stergere_medicament(med);
break;
case 4:
adaugare_medicament(med++);
break;
case 5:
afisare_stoc(med);
break;
case 6:
afisare_stoc(med,1);
break;
case 7:
afisare_echipa(ech);
break;
case 0:
ok=0;
}
}
}