Ayuda el programa debe hacerse uso de estructuras y funciones
Publicado por Maria (10 intervenciones) el 12/10/2020 18:33:48

Valora esta pregunta


-1
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Hospital
{
int num_expediente;
string nombre;
string apellido;
string enfermedad;
string medico;
string fecha_ingreso;
};
void menu();
void ingresoPaciente(vector<Hospital> &v);
int buscarPaciente(vector<Hospital> v, int num);
void mostrarPaciente(vector<Hospital> v, int i);
void mostrarMedico(vector<Hospital> v, string medico);
void bajaPaciente(vector<Hospital> &v, int num);
int main()
{
int num, id;
char opcion;
string nombre;
vector<Hospital> pacientes;
do {
menu();
cin >> opcion;
switch(opcion)
{
case '1':
ingresoPaciente(pacientes);
break;
case '2':
cout << "\nNumero de expediente:: "; cin >> num;
id = buscarPaciente(pacientes, num);
if (id != -1)
mostrarPaciente(pacientes, id);
else
cout << "\n\nPaciente NO encontrado" << endl;
break;
case '3':
cout << "\nNombre del medico: "; cin >> nombre;
mostrarMedico(pacientes, nombre);
break;
case '4':
cout << "\nNumero de expediente:: "; cin >> num;
id = buscarPaciente(pacientes, num);
if (id != -1)
{
mostrarPaciente(pacientes, id);
bajaPaciente(pacientes, id);
}
else
cout << "\n\nPaciente NO encontrado" << endl;
break;
case '5':
cout << "\n\nFIN DEL PROGRAMA" << endl;
break;
default:
cout << "\n\nOPCION NO VALIDA" << endl;
break;
}
} while (opcion != '5');
return 0;
}
void menu()
{
cout << "\n M E N U"
<< "\n============================"
<< "\n1.- Ingresar Paciente"
<< "\n2.- Buscar de un paciente"
<< "\n3.- Pacientes por medico"
<< "\n4.- Baja de paciente"
<< "\n5.- Salir"
<< "\n============================"
<< "\nOPCION (1-5): ";
}
void ingresoPaciente(vector<Hospital> &v)
{
Hospital p;
cout << "\nNUEVO PACIENTE:";
cin.ignore(80, '\n');
cout << "\nNumero de expediente: "; cin >> p.num_expediente;
cin.ignore(80, '\n');
cout << "Nombre: "; getline(cin, p.nombre);
cout << "Apellido: "; getline(cin, p.apellido);
cout << "Enfermedad: "; getline(cin, p.enfermedad);
cout << "Medico: "; getline(cin, p.medico);
cout << "Fecha de ingreso: "; cin >> p.fecha_ingreso;
cin.ignore(80, '\n');
v.push_back(p);
}
int buscarPaciente(vector<Hospital> v, int num)
{
int pos = 0;
while (pos < v.size() && v[pos].num_expediente != num)
pos++;
if (pos >= v.size())
pos = -1;
return pos;
}
void mostrarPaciente(vector<Hospital> v, int i)
{
cout << "\nNumero de expediente: " << v[i].num_expediente;
cout << "\nNombre: " << v[i].nombre;
cout << "\nApellido: " << v[i].apellido;
cout << "\nEnfermedad: " << v[i].enfermedad;
cout << "\nMedico: " << v[i].medico;
cout << "\nFecha de ingreso: " << v[i].fecha_ingreso;
cout << endl;
}
void mostrarMedico(vector<Hospital> v, string medico)
{
cout << "\nPacientes del Dr." << medico << ":\n";
for (int i = 0; i < v.size(); i++)
if (v[i].medico == medico)
cout << v[i].num_expediente << " " << v[i].nombre << " " << v[i].apellido << endl;
cout << endl;
}
void bajaPaciente(vector<Hospital> &v, int num)
{
v.erase(v.begin() + num);
}