Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- const int KMAX=25;
- const int KTAM=50;
- const int KPROV=10;
- typedef struct{
- char name[KMAX];
- char tipo;
- int ref;
- int prov[KPROV];
- }TMed;
- //rellena
- void rellena(TMed &, int &, int &, int &, int &);
- //menu
- void menu(int &);
- //listar por tipo
- void listar(TMed [], int);
- //listar por proveedor
- void listprov(TMed [], int);
- //Write the full name
- void fullname(char);
- int main(){
- TMed medic[KTAM];
- int num, num_r, num_l, num_v;
- int op;
- num=0;
- num_r=1;
- num_l=1;
- num_v=1;
- do{
- menu(op);
- switch(op){
- case 1: rellena(medic[num], num, num_r, num_l, num_v);
- break;
- case 2: listar(medic,num);
- break;
- case 3: listprov(medic,num);
- break;
- case 4: cout <<"FIN DEL PROGRAMA"<< endl;
- return 0;
- break;
- }
- }while(op!=4);
- cout << num;
- }
- void fullname(char tipo){
- if(tipo=='R'){
- cout <<" Con receta médica obligatoria" << endl;
- }
- else if(tipo=='L'){
- cout <<" Libre dispensación"<< endl;
- }
- else if(tipo=='V'){
- cout <<" Necesita visado médico para su dispensación"<< endl;
- }
- }
- void listprov(TMed medic[KTAM], int num){
- int i, n, k;
- cout << "Introduzca el número de proveedor: ";
- cin >> n;
- cout << endl;
- for(i=0;i<num;i++)
- for(k=0;k<KPROV;k++)
- if(medic[i].prov[k]==n){
- cout << "Nombre: " << medic[i].name<<endl;
- cout << "Tipo : ";
- fullname(medic[i].tipo);
- cout << "Referencia: "<<medic[i].tipo
- <<medic[i].ref<<endl;
- cout << endl;
- }
- cout << endl;
- cout<<"............................"<<endl;
- cout << endl;
- }
- void listar(TMed medic[KTAM], int num){
- int i;
- char leter;
- cout << "Introduzca el tipo de medicamento: ";
- cin >> leter;
- cout << endl;
- for(i=0;i<num;i++){
- if(medic[i].tipo=='R' && medic[i].tipo==leter){
- cout << "Nombre: " << medic[i].name << endl;
- cout << "Referencia: " << "R"
- << medic[i].ref;
- cout << endl;
- }
- else if(medic[i].tipo=='L' && medic[i].tipo==leter){
- cout << "Nombre: " << medic[i].name << endl;
- cout << "Referencia: " << "L"
- << medic[i].ref;
- cout << endl;
- }
- else if(medic[i].tipo=='V' && medic[i].tipo==leter){
- cout << "Nombre: " << medic[i].name << endl;
- cout << "Referencia: " << "L"
- << medic[i].ref;
- cout << endl;
- }
- else cout << "No hay ningún medicamento de este tipo"<<endl;
- cout << endl;
- }
- cout<<"............................"<<endl;
- cout << endl;
- }
- void rellena(TMed &medic, int &num, int &num_r, int &num_l, int &num_v){
- int i,n;
- cout << "Vamos a introducir los datos del medicamento: "<<endl;
- cout << "Nombre del medicamento: ";
- cin.get();
- cin.getline(medic.name,KMAX);
- cout << "Introduzca el tipo (R,L,V): ";
- cin >> medic.tipo;
- if(islower(medic.tipo)){
- do{
- cout << "Tipo erroneo"<< endl;
- cout << "Introduzca el tipo (R,L,V): ";
- cin >> medic.tipo;
- }while(islower(medic.tipo));
- }
- if(medic.tipo=='R'){
- medic.ref=num_r;
- num_r++;
- }
- else if(medic.tipo=='L'){
- medic.ref=num_l;
- num_l++;
- }
- else if(medic.tipo=='V'){
- medic.ref=num_v;
- num_v++;
- }
- cout << "El número de referencia del medicamento es "
- << medic.tipo << medic.ref << endl;
- i=0;
- do{
- cout << "Introduzca los proveedores que lo suministran (-1 para terminar): ";
- cin >> medic.prov[i];
- n=medic.prov[i];
- i++;
- }while(n>0 && i<KPROV);
- cout << "Los datos del medicamento han sido introducidos correctamente"<<endl;
- cout<<"............................"<<endl;
- cout << endl;
- //num=medic.ref;
- num++;
- }
- void menu(int &op){
- cout << "Introduzca una opción del siguiente menú:"<< endl;
- cout << "1.- introducir datos de un nuevo medicamento."<<endl;
- cout << "2.- Listar medicamentos en función del tipo."<< endl;
- cout << "3.- Mostrar medicamentos en función del proveedor."<<endl;
- cout << "4.- SALIR"<<endl;
- cout << "OPCIÓN... ";
- cin >> op;
- cout << endl;
- if(op!=1 && op!=2 && op!=3 && op!=4){
- cout << "introduzca una opción válida"<< endl;
- cout << endl;
- menu(op);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement