|
| 1 | +#include <iostream> |
| 2 | +#include <iomanip> |
| 3 | +#include <fstream> |
| 4 | +#include <stdlib.h> |
| 5 | +#include <string.h> |
| 6 | +using namespace std; |
| 7 | +struct T1{ |
| 8 | + int N; |
| 9 | + string exp, grupo, nombre; |
| 10 | +}; |
| 11 | +typedef T1 _T1; |
| 12 | +struct nodo{ |
| 13 | + _T1 info; |
| 14 | + nodo* sig; |
| 15 | +}; |
| 16 | +typedef nodo* ptnodo; |
| 17 | +ptnodo cola[5]; |
| 18 | +// funciones |
| 19 | +int ultimo_num(string n); |
| 20 | +void popcola_todo(ptnodo &cola, T1 &elem); |
| 21 | +void pushcola(ptnodo &cola,T1 &elem); |
| 22 | +void cima_cola(ptnodo &frente,string &elem); |
| 23 | +void popcola(ptnodo &cola, T1 &elem); |
| 24 | +void mostrar_cola(ptnodo &cola, T1 registro); |
| 25 | +void borrar_cola(ptnodo &cola); |
| 26 | +int main() { |
| 27 | + string elem, num; |
| 28 | + int opc = 0, i = 0, opc2 = 0, res; |
| 29 | + ifstream A1; |
| 30 | + T1 registro, *ptregistro = NULL; |
| 31 | + while(opc != 5){ |
| 32 | + cout << "Menu de opciones\n"; |
| 33 | + cout << "1.- Cargar datos\n"; |
| 34 | + cout << "2.- Mostrar una cola especifica\n"; |
| 35 | + cout << "3.- Vaciar arreglo, mostrando datos que salen\n"; |
| 36 | + cout << "4.- Opcion adicional\n"; |
| 37 | + cout << "5.- Salir\n"; |
| 38 | + cin >> opc; |
| 39 | + system("cls"); |
| 40 | + switch(opc){ |
| 41 | + case 1: |
| 42 | + if(ptregistro != NULL)// liberar memoria |
| 43 | + delete[] ptregistro; |
| 44 | + for(i = 0; i < 5; i++) |
| 45 | + borrar_cola(cola[i]); |
| 46 | + ptregistro = new T1[27]; |
| 47 | + A1.open("lista3.txt"); |
| 48 | + if(!A1){ |
| 49 | + cout << "Error al abrir archivo\n"; |
| 50 | + } |
| 51 | + A1>> ptregistro -> N; |
| 52 | + A1.ignore(1); |
| 53 | + getline(A1,ptregistro -> exp,'\t'); |
| 54 | + getline(A1,ptregistro -> grupo,'\t'); |
| 55 | + getline(A1,ptregistro -> nombre); |
| 56 | + i = 1; |
| 57 | + while(A1.eof() == 0){ |
| 58 | + A1>>ptregistro[i].N; |
| 59 | + A1.ignore(1); |
| 60 | + getline(A1,ptregistro[i].exp,'\t'); |
| 61 | + getline(A1,ptregistro[i].grupo,'\t'); |
| 62 | + getline(A1,ptregistro[i].nombre); |
| 63 | + i++; |
| 64 | + } |
| 65 | + A1.close(); |
| 66 | + for(i = 0; i < 27; i++){ |
| 67 | + num = ptregistro[i].exp[10]; |
| 68 | + res = ultimo_num(num); |
| 69 | + switch(res){ |
| 70 | + case 0: case 1: |
| 71 | + pushcola(cola[0], ptregistro[i]); |
| 72 | + break; |
| 73 | + case 2: case 3: |
| 74 | + pushcola(cola[1], ptregistro[i]); |
| 75 | + break; |
| 76 | + case 4: case 5: |
| 77 | + pushcola(cola[2], ptregistro[i]); |
| 78 | + break; |
| 79 | + case 6: case 7: |
| 80 | + pushcola(cola[3], ptregistro[i]); |
| 81 | + break; |
| 82 | + case 8: case 9: |
| 83 | + pushcola(cola[4], ptregistro[i]); |
| 84 | + break; |
| 85 | + } |
| 86 | + } |
| 87 | + break; |
| 88 | + case 2: |
| 89 | + opc2 = 0; |
| 90 | + while (opc2 != 6){ |
| 91 | + cout << "\nmenu de opciones mostrar\n" << endl; |
| 92 | + cout << "1.- cola del dia lunes\n"; |
| 93 | + cout << "2.- cola del dia martes\n"; |
| 94 | + cout << "3.- cola del dia miercoles\n"; |
| 95 | + cout << "4.- cola del dia jueves\n"; |
| 96 | + cout << "5.- cola del dia viernes\n"; |
| 97 | + cout << "6.- salir del modo mostrar\n"; |
| 98 | + cin >> opc2; |
| 99 | + system("cls"); |
| 100 | + switch(opc2){ |
| 101 | + case 1: |
| 102 | + mostrar_cola(cola[0], registro); |
| 103 | + break; |
| 104 | + case 2: |
| 105 | + mostrar_cola(cola[1], registro); |
| 106 | + break; |
| 107 | + case 3: |
| 108 | + mostrar_cola(cola[2], registro); |
| 109 | + break; |
| 110 | + case 4: |
| 111 | + mostrar_cola(cola[3], registro); |
| 112 | + break; |
| 113 | + case 5: |
| 114 | + mostrar_cola(cola[4], registro); |
| 115 | + break; |
| 116 | + case 6: |
| 117 | + cout << "salio de la modalidad mostrar\n" << endl; |
| 118 | + break; |
| 119 | + default: |
| 120 | + cout << "ingrese una opcion valida\n\n"; |
| 121 | + } |
| 122 | + } |
| 123 | + break; |
| 124 | + case 3: |
| 125 | + i = 0; |
| 126 | + while(i < 5){ |
| 127 | + mostrar_cola(cola[i], registro); |
| 128 | + popcola_todo(cola[i], registro); |
| 129 | + i++; |
| 130 | + } |
| 131 | + break; |
| 132 | + case 4: |
| 133 | + break; |
| 134 | + case 5: |
| 135 | + // liberar memoria |
| 136 | + delete[] ptregistro; |
| 137 | + for(i = 0; i < 5; i++) |
| 138 | + borrar_cola(cola[i]); |
| 139 | + break; |
| 140 | + default: |
| 141 | + cout << "Ingrese una opcion valida \n\n"; |
| 142 | + break; |
| 143 | + } |
| 144 | + } |
| 145 | + return 0; |
| 146 | + } |
| 147 | +void pushcola(ptnodo &cola,T1 &elem){ |
| 148 | + ptnodo nuevo, Aux = cola; |
| 149 | + nuevo = new(nodo); |
| 150 | + nuevo -> info = elem; |
| 151 | + nuevo -> sig = NULL; |
| 152 | + if(cola == NULL) |
| 153 | + cola = nuevo; |
| 154 | + else{ |
| 155 | + while(Aux -> sig != NULL) |
| 156 | + Aux = Aux -> sig; |
| 157 | + Aux -> sig = nuevo; |
| 158 | + } |
| 159 | +} |
| 160 | +void cima_cola(ptnodo &frente,string &elem){ |
| 161 | + if(cola != NULL) |
| 162 | + elem = frente -> info.exp; |
| 163 | +} |
| 164 | +void popcola(ptnodo &cola, T1 &elem){ |
| 165 | + ptnodo Aux = cola; |
| 166 | + if(cola != NULL){ |
| 167 | + cola = cola -> sig; |
| 168 | + elem = Aux -> info; |
| 169 | + delete(Aux); |
| 170 | + }else{ |
| 171 | + cout << "error popc_t\n" << endl;} |
| 172 | +} |
| 173 | +void popcola_todo(ptnodo &cola, T1 &elem){ |
| 174 | + ptnodo Aux = cola; |
| 175 | + if(cola != NULL){ |
| 176 | + while (cola != NULL){ |
| 177 | + cola = cola -> sig; |
| 178 | + elem = Aux -> info; |
| 179 | + } |
| 180 | + delete(Aux); |
| 181 | + }else{ |
| 182 | + cout << "error popc\n" << endl;} |
| 183 | +} |
| 184 | +void mostrar_cola(ptnodo &cola, T1 registro){ |
| 185 | + ptnodo Aux1 = cola; |
| 186 | + if(Aux1 != NULL){ |
| 187 | + registro = Aux1 -> info; |
| 188 | + while(Aux1 != NULL){ |
| 189 | + registro = Aux1 -> info; |
| 190 | + cout << setw(3) << left <<registro.N; |
| 191 | + cout << setw(13) << registro.exp; |
| 192 | + cout << setw(4) << registro.grupo; |
| 193 | + cout << setw(24) << registro.nombre <<endl; |
| 194 | + Aux1 = Aux1 -> sig; |
| 195 | + } |
| 196 | + delete Aux1; |
| 197 | + }else |
| 198 | + cout << "cola vacia\n\n"; |
| 199 | +} |
| 200 | +void borrar_cola(ptnodo &cola){ |
| 201 | + T1 elem; |
| 202 | + while(cola != NULL) |
| 203 | + popcola_todo(cola, elem); |
| 204 | +} |
| 205 | +int ultimo_num(string n){ |
| 206 | + if(n == "0") |
| 207 | + return 0; |
| 208 | + if(n == "1") |
| 209 | + return 1; |
| 210 | + if(n == "2") |
| 211 | + return 2; |
| 212 | + if(n == "3") |
| 213 | + return 3; |
| 214 | + if(n == "4") |
| 215 | + return 4; |
| 216 | + if(n == "5") |
| 217 | + return 5; |
| 218 | + if(n == "6") |
| 219 | + return 6; |
| 220 | + if(n == "7") |
| 221 | + return 7; |
| 222 | + if(n == "8") |
| 223 | + return 8; |
| 224 | + if(n == "9") |
| 225 | + return 9; |
| 226 | + } |
0 commit comments