Last active
March 10, 2017 01:04
-
-
Save sebassdc/eb4bddb0c342a7a93fd48dbadc581170 to your computer and use it in GitHub Desktop.
Taller para entrega 09/03/2017 prog1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
// Agregar soporte para compilar en linux | |
// #define LIN | |
#define WIN | |
using namespace std; | |
// Declaracion de funciones | |
void clear(); | |
void eqline(); | |
void emline(); | |
void title(string); | |
void printMenu(); | |
void pause(); | |
main(){ | |
bool flag = false; | |
int i, j, tecl, acum, mayor, mayor_j, total_productos, ganancia_bruta; | |
float pago_de_impuestos, pago_servicios, pago_de_empleados, deducciones; | |
int opcion = 0; | |
int n_p = 0; | |
int precio_base; | |
string meses[] = {"ENERO", "FEBRE", "MARZO", "ABRIL", "MAYO", "JUNIO", "JULIO", "AGOST", "SEPTI", "OCTUB", "NOVIE", "DICIE"}; | |
// Inicializar los productos | |
title("Configuracion inicial"); | |
cout << "¿Cuantos productos vende la empresa?: "; cin >> n_p; | |
emline(); | |
cout << "Ingrese los nombres de los productos" << endl; | |
emline(); | |
// Algunas variables | |
int data[n_p][12]; | |
string productos[n_p]; | |
for (i = 0; i < n_p; i++) { | |
cout << "Producto " << i+1 << ": "; | |
cin >> productos[i]; | |
} | |
cout << "¿Cual es el precio base de los productos?: "; cin >> precio_base; | |
clear(); | |
do { | |
clear(); | |
printMenu(); // Imprime el menu de opciones | |
cin >> opcion; | |
if(opcion < 1 || opcion > 10){ | |
clear(); | |
title("ERROR: Por favor elija un numero que corresponda a una opcion del menu"); | |
pause(); | |
continue; | |
} | |
if (opcion > 1 && opcion < 10) { | |
if (!flag) { | |
title("Debe ingresar primero los datos"); | |
pause(); | |
continue; | |
} | |
} | |
switch (opcion) { | |
case 1: | |
clear(); | |
title("INGRESAR DATOS"); | |
cout << "Ingrese la cantidad de ventas para cada producto cada mes" << endl; | |
for (i = 0; i < n_p; i++) { | |
emline(); | |
cout << productos[i] << endl; | |
emline(); | |
for (j = 0; j < 12; j++) { | |
cout << meses[j] << ": "; | |
cin >> tecl; | |
if (!tecl) tecl = 0; | |
data[i][j] = tecl; | |
} | |
} | |
flag = true; | |
pause(); | |
break; | |
case 2: | |
clear(); | |
title("MOSTRAR DATOS"); | |
cout << "\tM\t"; | |
for (i = 0; i < 12; i++) | |
cout << meses[i] << "\t"; | |
cout << endl; | |
eqline(); | |
for (i = 0; i < n_p; i++) { | |
cout << "\t" << productos[i] << "\t"; | |
for (j = 0; j < 12; j++) | |
cout << data[i][j] << "\t"; | |
cout << endl; | |
} | |
pause(); | |
break; | |
case 3: | |
clear(); | |
title("TOTAL VENTAS POR PRODUCTO"); | |
for (i = 0; i < n_p; i++) { | |
acum = 0; | |
for (j = 0; j < 12; j++) { | |
acum += data[i][j]; | |
} | |
cout << productos[i] << ": " << acum << endl; | |
} | |
pause(); | |
break; | |
case 4: | |
clear(); | |
title("TOTAL VENTAS POR MES"); | |
for (i = 0; i < 12; i++) { | |
acum = 0; | |
for (j = 0; j < n_p; j++) { | |
acum += data[j][i]; | |
} | |
cout << meses[i] << ": " << acum << endl; | |
} | |
pause(); | |
break; | |
case 5: | |
clear(); | |
title("PRODUCTO MAS VENDIDO POR MES"); | |
for (i = 0; i < 12; i++) { | |
mayor = 0; | |
for (j = 0; j < n_p; j++) { | |
if (data[mayor][i] < data[j][i]) mayor = j; | |
} | |
cout << meses[i] << ": " << productos[mayor]; | |
cout << " con " << data[mayor][i] << " vendidos" << endl; | |
} | |
pause(); | |
break; | |
case 6: | |
clear(); | |
title("PRODUCTO MAS VENDIDO"); | |
mayor = 0; | |
mayor_j = 0; | |
for (i = 0; i < n_p; i++) { | |
for (j = 0; j < 12; j++) { | |
if (data[mayor][mayor_j] < data[i][j]) { | |
mayor = i; mayor_j = j; | |
} | |
} | |
} | |
cout << "Se vendieron " << data[mayor][mayor_j] << " unidades de "; | |
cout << productos[mayor] << " en el mes de " << meses[mayor_j] << endl; | |
pause(); | |
break; | |
case 7: | |
clear(); | |
title("PORCENTAJE DE PRODUCTOS VENDIDOS CADA MES"); | |
total_productos = 0; | |
// calcular el total de productos | |
for (i = 0; i < n_p; i++) { | |
for (j = 0; j < 12; j++) { | |
total_productos += data[i][j]; | |
} | |
} | |
// determinar porcentajes | |
for (i = 0; i < 12; i++) { | |
acum = 0; | |
for (j = 0; j < n_p; j++) { | |
acum += data[j][i]; | |
} | |
cout << "En el mes " << meses[i] << " se vendio un "; | |
cout << ((float)acum / (float)total_productos) * 100.0 << "% de los productos " << endl; | |
} | |
pause(); | |
break; | |
case 8: | |
clear(); | |
title("TOTAL VENTAS POR PRODUCTO"); | |
total_productos = 0; | |
// calcular el total de productos | |
for (i = 0; i < n_p; i++) { | |
for (j = 0; j < 12; j++) { | |
total_productos += data[i][j]; | |
} | |
} | |
// determinar porcentajes | |
for (i = 0; i < n_p; i++) { | |
acum = 0; | |
for (j = 0; j < 12; j++) { | |
acum += data[i][j]; | |
} | |
cout << "Del producto " << productos[i] << " se vendio un "; | |
cout << ((float)acum / (float)total_productos) * 100.0 << "%" << endl; | |
} | |
pause(); | |
break; | |
case 9: | |
clear(); | |
title("GANANCIA TOTAL DEL ALMACEN"); | |
ganancia_bruta = 0; | |
// ciclar y sumar | |
for (i = 0; i < n_p; i++) { | |
for (j = 0; j < 12; j++) { | |
ganancia_bruta += (data[i][j] * precio_base) + (i * 15); // El i por 15 le agrega los 15 dependiendo de producto | |
} | |
} | |
// calculo de deducciones | |
pago_servicios = ganancia_bruta * 0.15; | |
pago_de_impuestos = ganancia_bruta * 0.16; | |
pago_de_empleados = ganancia_bruta * 0.215; | |
deducciones = pago_servicios + pago_de_empleados + pago_de_impuestos; | |
// Imprimir datos | |
cout << "El ingreso total es de: " << ganancia_bruta << "bs" << endl; | |
cout << "Pago para los servicios: " << pago_servicios << "bs" << endl; | |
cout << "Pago de impuestos: " << pago_de_impuestos << "bs" << endl; | |
cout << "Pago de empleados: " << pago_de_empleados << "bs" << endl; | |
eqline(); | |
cout << "GANANCIA TOTAL: " << (float)ganancia_bruta - deducciones << endl; | |
eqline(); | |
pause(); | |
break; | |
case 10: | |
cout << "Gracias por usar nuestros servicios" << endl; | |
pause(); | |
break; | |
} | |
} while(opcion != 10); | |
} // main | |
// clear screen in both linux and windows | |
void clear(){ | |
#ifdef LIN | |
system("clear"); | |
#endif | |
#ifdef WIN | |
system("cls"); | |
#endif | |
} | |
void pause(){ | |
#ifdef LIN | |
cin.ignore(1024, '\n'); | |
cout << "Press enter to continue..."; | |
cin.get(); | |
#endif | |
#ifdef WIN | |
system("pause"); | |
#endif | |
} | |
// some helpers | |
void eqline(){cout << "===================================================\n";} | |
void emline(){cout << "\n";} | |
void title(string s){ | |
eqline(); | |
emline(); | |
cout << "\t" << s << endl; | |
emline(); | |
eqline(); | |
} | |
void printMenu(){ | |
emline(); | |
eqline(); | |
cout << "1. Ingresar datos" << endl; | |
cout << "2. Mostrar datos" << endl; | |
cout << "3. Total ventas por producto" << endl; | |
cout << "4. Total ventas por mes" << endl; | |
cout << "5. Producto mas vendido por mes" << endl; | |
cout << "6. Producto mas vendido" << endl; | |
cout << "7. Porcentaje de productos vendidos cada mes" << endl; | |
cout << "8. Porcentaje de las ventas de productos" << endl; | |
cout << "9. Ganancia total del almacen" << endl; | |
cout << "10. Salir" << endl; | |
eqline(); | |
emline(); | |
cout << "Elija una opcion: "; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment