Compañía Telefónica

/* COMPTELEFONICA.CPP VERSION DE UNA SOLA PAGINA CARGAR, MODIFICAR, ELIMINAR DATOS DE COMPAÑIA FICTICIA CARLOS D. ALVAREZ, 010615 */ #include <windows.h> #include <string.h> #include <iostream> #include <vector> using namespace std; typedef struct { char NumeroTel[100]; char NombreComp[100]; char ModeloTel[100]; char NombreProp[100]; char DireccionProp[96]; int ModPago; } REG_VENTA, *PREG_VENTA; class ManejoVentas { public: ManejoVentas(char* CompVendedora); private: void Intro(char* Titulo); void MenuPrincipal(); void MenuAgregar(); void MenuModificar (); void MenuEliminar (); void MenuLista(); void ModificarEspecifico(int Indice); void EliminarEspecifico(int Indice); signed int BuscarRegistro(char *sNumeroTel); char* CompVendedora; vector<PREG_VENTA> ListaDeVentas; int VentasTotales; }; ManejoVentas::ManejoVentas(char* NombreComp) { CompVendedora = NombreComp; VentasTotales = 0; MenuPrincipal(); } void ManejoVentas::Intro(char* Titulo) { system("cls"); cout << "******** " << Titulo << " ********" << endl << endl; } void ManejoVentas::MenuPrincipal(){ int Opcion = 10; while(Opcion != 0) { Intro(CompVendedora); cout << "1. Agregar venta." << endl; if (VentasTotales > 0) { cout << "2: Listar Ventas." << endl; cout << "3: Modificar Venta." << endl; cout << "4: Eliminar Venta." << endl; } cout << endl << "0: Salir." << endl; cout << endl; cout << "Ingrese opcion: "; cin >> Opcion; switch (Opcion) { case 0: break; case 1: MenuAgregar(); break; case 2: if (VentasTotales > 0) MenuLista(); break; case 3: if (VentasTotales > 0) MenuModificar(); break; case 4: if (VentasTotales > 0) MenuEliminar(); break; default: Intro(CompVendedora); cout << "OPCION INVALIDA, PRESIONE ENTER" << endl; cout << "E INTENTE NUEVAMENTE."; } } } void ManejoVentas::MenuAgregar() { ++VentasTotales; ListaDeVentas.resize(VentasTotales); ListaDeVentas[VentasTotales-1] = new REG_VENTA; ZeroMemory(ListaDeVentas[VentasTotales-1], sizeof(REG_VENTA)); ModificarEspecifico(VentasTotales-1); } void ManejoVentas::MenuModificar (){ char NumeroTemporal[20] = ""; Intro("..MODIFICAR VENTA.."); cout << "Ingrese numero telefonico: " ; cin >> NumeroTemporal; if (BuscarRegistro(NumeroTemporal) == -1) { Intro("..NUMERO ERRADO.."); cout << "Entre a la lista para concer los numeros guardados." << endl << endl; system("pause"); } else { ModificarEspecifico(BuscarRegistro(NumeroTemporal)); } } void ManejoVentas::MenuEliminar (){ char NumeroTemporal[20] = ""; Intro("..ELIMINAR VENTA.."); cout << "Ingrese numero telefonico: " ; cin >> NumeroTemporal; if (BuscarRegistro(NumeroTemporal) == -1) { Intro("..NUMERO ERRADO.."); cout << "Entre a la lista para concer los numeros guardados." << endl << endl; system("pause"); } else { EliminarEspecifico(BuscarRegistro(NumeroTemporal)); } } void ManejoVentas::MenuLista(){ Intro("..LISTA DE VENTAS.."); for (int i = 0; i < VentasTotales; i++) { cout << "Numero: " << ListaDeVentas[i]->NumeroTel; cout << "Modelo: " << ListaDeVentas[i]->ModeloTel; cout << "Operadora: " << ListaDeVentas[i]->NombreComp; cout << "Propietario: " << ListaDeVentas[i]->NombreProp; cout << "Direccion: " << ListaDeVentas[i]->DireccionProp; if (ListaDeVentas[i]->ModPago == 1) { cout << "Modo de Pago: Prepago, renta de $0.00"; } else { cout << "Modo de Pago: Pospago, renta de 25.00"; } cout << endl << endl; } system("pause"); } void ManejoVentas::EliminarEspecifico(int Indice) { ListaDeVentas.erase(ListaDeVentas.begin()+Indice); VentasTotales--; } void ManejoVentas::ModificarEspecifico(int Indice) { char* Actual = "..INGRESE DATOS DE REGISTRO.."; char Temporal[100]; fgets(Temporal, 99, stdin); Intro(Actual); cout << "Numero Telefonico: "; fgets(ListaDeVentas[Indice]->NumeroTel, 99, stdin); Intro(Actual); cout << "Nombre de empresa telefonica: "; fgets(ListaDeVentas[Indice]->NombreComp, 99, stdin); Intro(Actual); cout << "Modelo de telefono: "; fgets(ListaDeVentas[Indice]->ModeloTel, 99, stdin); Intro(Actual); cout << "Nombre de propietario: "; fgets(ListaDeVentas[Indice]->NombreProp, 99, stdin); Intro(Actual); cout << "Direccion de propietario: "; fgets(ListaDeVentas[Indice]->DireccionProp, 99, stdin); Intro(Actual); cout << "Modo de pago (1: Prepago, 2: Pospago): "; cin >> ListaDeVentas[Indice]->ModPago; for (unsigned int i = 0; i <= strlen(ListaDeVentas[Indice]->NumeroTel); i++) { if (ListaDeVentas[Indice]->NumeroTel[i] == 10) { ListaDeVentas[Indice]->NumeroTel[i] = 0; break; } } } signed int ManejoVentas::BuscarRegistro(char* sNumeroTel) { for (int i = 0; i < VentasTotales; i++) { if (!strcmp(ListaDeVentas[i]->NumeroTel, sNumeroTel)) return i; } return -1; } int main(int argc, char* argv[]) { ManejoVentas Ventas = ManejoVentas("CELULIN SA de CV"); return 0; }
Uso de memoria dinámica con Vector, leer líneas enteras con fgets, clases, punteros, datos estructurados, un problema simple resuelto de la mejor manera.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.