Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int KMAX=25;
  6. const int KTAM=50;
  7. const int KPROV=10;
  8.  
  9. typedef struct{
  10.     char name[KMAX];
  11.     char tipo;
  12.     int ref;
  13.     int prov[KPROV];
  14. }TMed;
  15.  
  16. //rellena
  17. void rellena(TMed &, int &, int &, int &, int &);
  18.  
  19. //menu
  20. void menu(int &);
  21.  
  22. //listar por tipo
  23. void listar(TMed [], int);
  24.  
  25. //listar por proveedor
  26. void listprov(TMed [], int);
  27.  
  28. //Write the full name
  29. void fullname(char);
  30.  
  31.  
  32. int main(){
  33.     TMed medic[KTAM];
  34.     int num, num_r, num_l, num_v;
  35.     int op;
  36.  
  37.     num=0;
  38.     num_r=1;
  39.     num_l=1;
  40.     num_v=1;
  41.  
  42.     do{    
  43.         menu(op);
  44.         switch(op){
  45.             case 1: rellena(medic[num], num, num_r, num_l, num_v);
  46.                 break;
  47.             case 2: listar(medic,num);
  48.                 break;
  49.             case 3: listprov(medic,num);
  50.                 break;
  51.             case 4: cout <<"FIN DEL PROGRAMA"<< endl;
  52.                     return 0;
  53.                 break;
  54.         }
  55.  
  56.     }while(op!=4);
  57.     cout << num;
  58. }
  59.  
  60. void fullname(char tipo){
  61.  
  62.     if(tipo=='R'){
  63.         cout <<" Con receta médica obligatoria" << endl;
  64.     }
  65.     else if(tipo=='L'){
  66.         cout <<" Libre dispensación"<< endl;
  67.     }
  68.     else if(tipo=='V'){
  69.         cout <<" Necesita visado médico para su dispensación"<< endl;
  70.     }
  71.  
  72. }
  73.  
  74. void listprov(TMed medic[KTAM], int num){
  75.     int i, n, k;
  76.  
  77.     cout << "Introduzca el número de proveedor: ";
  78.     cin >> n;
  79.     cout << endl;
  80.  
  81.     for(i=0;i<num;i++)
  82.         for(k=0;k<KPROV;k++)
  83.             if(medic[i].prov[k]==n){
  84.                 cout << "Nombre: " << medic[i].name<<endl;
  85.                 cout << "Tipo : ";
  86.                 fullname(medic[i].tipo);
  87.                 cout << "Referencia: "<<medic[i].tipo
  88.                         <<medic[i].ref<<endl;
  89.         cout << endl;      
  90.             }
  91.     cout << endl;
  92.     cout<<"............................"<<endl;
  93.     cout << endl;
  94. }
  95.  
  96.  
  97. void listar(TMed medic[KTAM], int num){
  98.     int i;
  99.     char leter;
  100.  
  101.     cout << "Introduzca el tipo de medicamento: ";
  102.     cin >> leter;
  103.     cout << endl;
  104.  
  105.     for(i=0;i<num;i++){
  106.         if(medic[i].tipo=='R' && medic[i].tipo==leter){
  107.             cout << "Nombre: " << medic[i].name << endl;
  108.             cout << "Referencia: " << "R"
  109.                 << medic[i].ref;
  110.             cout << endl;
  111.         }
  112.         else if(medic[i].tipo=='L' && medic[i].tipo==leter){
  113.             cout << "Nombre: " << medic[i].name << endl;
  114.             cout << "Referencia: " << "L"
  115.                 << medic[i].ref;
  116.             cout << endl;
  117.         }
  118.         else if(medic[i].tipo=='V' && medic[i].tipo==leter){
  119.             cout << "Nombre: " << medic[i].name << endl;
  120.             cout << "Referencia: " << "L"
  121.                 << medic[i].ref;
  122.             cout << endl;
  123.         }
  124.         else cout << "No hay ningún medicamento de este tipo"<<endl;      
  125.         cout << endl;
  126.     }
  127.  
  128.     cout<<"............................"<<endl;
  129.     cout << endl;
  130. }
  131.  
  132. void rellena(TMed &medic, int &num, int &num_r, int &num_l, int &num_v){
  133.     int i,n;
  134.    
  135.     cout << "Vamos a introducir los datos del medicamento: "<<endl;
  136.     cout << "Nombre del medicamento: ";
  137.     cin.get();
  138.     cin.getline(medic.name,KMAX);
  139.     cout << "Introduzca el tipo (R,L,V): ";
  140.     cin >> medic.tipo;
  141.  
  142.     if(islower(medic.tipo)){
  143.         do{
  144.             cout << "Tipo erroneo"<< endl;
  145.             cout << "Introduzca el tipo (R,L,V): ";
  146.             cin >> medic.tipo;
  147.         }while(islower(medic.tipo));
  148.     }
  149.  
  150.     if(medic.tipo=='R'){
  151.         medic.ref=num_r;
  152.         num_r++;
  153.     }
  154.     else if(medic.tipo=='L'){
  155.         medic.ref=num_l;
  156.         num_l++;
  157.     }
  158.     else if(medic.tipo=='V'){
  159.         medic.ref=num_v;
  160.         num_v++;
  161.     }
  162.  
  163.  
  164.     cout << "El número de referencia del medicamento es "
  165.         << medic.tipo << medic.ref  << endl;
  166.  
  167.     i=0;
  168.     do{
  169.         cout << "Introduzca los proveedores que lo suministran (-1 para terminar): ";
  170.         cin >> medic.prov[i];
  171.         n=medic.prov[i];
  172.         i++;
  173.     }while(n>0 && i<KPROV);
  174.     cout << "Los datos del medicamento han sido introducidos correctamente"<<endl;
  175.     cout<<"............................"<<endl;
  176.     cout << endl;
  177.  
  178.     //num=medic.ref;
  179.     num++; 
  180. }
  181.  
  182. void menu(int &op){
  183.     cout << "Introduzca una opción del siguiente menú:"<< endl;
  184.     cout << "1.- introducir datos de un nuevo medicamento."<<endl;
  185.     cout << "2.- Listar medicamentos en función del tipo."<< endl;
  186.     cout << "3.- Mostrar medicamentos en función del proveedor."<<endl;
  187.     cout << "4.- SALIR"<<endl;
  188.     cout << "OPCIÓN... ";
  189.     cin >> op;
  190.     cout << endl;
  191.  
  192.     if(op!=1 && op!=2 && op!=3 && op!=4){
  193.         cout << "introduzca una opción válida"<< endl;
  194.         cout << endl;
  195.         menu(op);
  196.     }
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement