#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include<string.h>
struct Gastos {
char nombre[20];
float cantidad;
int pos;
};
//declaracion de funciones
void menu ();
void agregar(int* A, struct Gastos gastos[]);
void mostrar(int* A, struct Gastos gastos []);
void editar(int* A,struct Gastos gastos[]);
void burbunum (int A,struct Gastos gastos[]);
void burbupal(int A,struct Gastos gastos[]);
//bloque principal
int main (){
struct Gastos gastos[15];
int opc,a=1,flag=0,i=0;
do{
menu();
switch(opc){
case 1:
agregar(&a,gastos);
printf("Los datos guardados para la posicion %d fueron:nn" "%s $%.2f",gastos[a-1].pos, gastos[a-1].nombre , gastos[a-1].cantidad);
break;
case 2:
mostrar(&a,gastos);
break;
case 3:
editar(&a,gastos);
break;
case 4:
burbunum(a,gastos);
for (i=1;i<a;i++){
printf(" %-15s $%-6.2f", gastos
[i
].
nombre,gastos
[i
].
cantidad); }
break;
case 5:
burbupal(a,gastos);
for (i=1;i<a;i++){
printf(" %-15s $%-6.2f", gastos
[i
].
nombre,gastos
[i
].
cantidad); }
break;
case 9:
flag=1;
break;
}
}
while(flag==0);
return 0;
}
//Desarrollo de funciones
void menu (){
printf("4-Ordenar por gastosn"); printf("5-Ordenar por nombren"); }
void agregar(int* A,struct Gastos gastos[]){
scanf("%s",&gastos
[*A
].
nombre); scanf("%f",&gastos
[*A
].
cantidad);
gastos[*A].pos=*A;
*A+=1;
}
void mostrar (int* A, struct Gastos gastos []){
int i=1,w=1;
for (i=1;i<*A;i+=1){
printf("%-5.2i %-15s $%-6.2f", w
, gastos
[i
].
nombre,gastos
[i
].
cantidad); w++;
}
}
void editar(int* A,struct Gastos gastos[]){
int OPC;
mostrar(A,gastos);
printf("nQue posicion desea editar?");
scanf("%s",&gastos
[OPC
].
nombre); scanf("%f",&gastos
[OPC
].
cantidad); }
void burbunum(int A,struct Gastos gastos[]){
int i=0,flag=0;
struct Gastos aux;
while (flag==0){
flag=1;
for (i=1;i<A-1;i++){
if (gastos[i].cantidad>gastos[i+1].cantidad){
aux=gastos[i+1];
gastos[i+1]=gastos[i];
gastos[i]=aux;
flag=0;
}
}
}
}
void burbupal(int A,struct Gastos gastos[]){
int i=0,flag=0;
struct Gastos aux;
while (flag==0){
flag=1;
for (i=1;i<A-1;i++){
if (strcmp(gastos
[i
].
nombre,gastos
[i
+1].
nombre)>0){ aux=gastos[i+1];
gastos[i+1]=gastos[i];
gastos[i]=aux;
flag=0;
}
}
}
}