Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- typedef struct FechaPublicacion{
- int dia;
- int mes;
- int anio;
- }Fecha;
- typedef struct MercadoLibre{
- char Sitio[100];
- char NombreProducto[100];
- char Categoria[100];
- float Precio;
- char Pago;
- float Descuento;
- int Stock;
- Fecha Publicacion;
- }datos;
- datos cargarDatos(){
- datos retorno;
- printf("Ingrese la dirección url del sitio.\n");
- gets(retorno.Sitio);
- printf("Ingrese el nombre del producto.\n");
- gets(retorno.NombreProducto);
- printf("Ingrese la categoría del producto.\n");
- gets(retorno.Categoria);
- printf("Ingrese el precio del producto.\n");
- scanf("%f", &retorno.Precio);
- printf("Ingrese la forma de pago (Efectivo=E/Tarjeta=T).\n");
- scanf(" %c", &retorno.Pago);
- printf("Ingrese el descuento correspondiente.\n");
- scanf("%f", &retorno.Descuento);
- printf("Ingrese la cantidad de productos en Stock.\n");
- scanf("%d", &retorno.Stock);
- printf("Ingrese la fecha de publicación del producto (formato dd/mm/aaaa).\n");
- scanf("%d/%d/%d", &retorno.Publicacion.dia, &retorno.Publicacion.mes, &retorno.Publicacion.anio);
- return retorno;
- }
- void mostrarDatos(datos *Producto){
- printf("url: %s\n", Producto->Sitio);
- printf("Producto: %s\n", Producto->NombreProducto);
- printf("Categoria: %s\n", Producto->Categoria);
- printf("Precio: %.2f\n", Producto->Precio);
- printf("Pago: %c\n", Producto->Pago);
- printf("Descuento: %.2f\n", Producto->Descuento);
- printf("Stock: %d\n", Producto->Stock);
- printf("Fecha Publicacion: %d/%d/%d\n", Producto->Publicacion.dia,Producto->Publicacion.mes,Producto->Publicacion.anio);
- }
- void modificarPrecio(float *precio, int *stock){
- if(*stock<3) (*precio)*=1.1;
- else if(*stock>4) (*precio)*=0.85;
- }
- int i=1;
- void cargarProductos(datos *arreglo){
- char opcion = 'S';
- while(opcion=='S'){
- printf("Ingrese los datos del producto %d.\n", i);
- *arreglo = cargarDatos();
- printf("¿Desea ingresar los datos de otro producto? S/N\n");
- scanf(" %c", &opcion);
- i++;
- arreglo++;
- }
- }
- void mostrarProductos(datos *arreglo){
- int j=0;
- while(j<i-1){
- printf("Datos del producto %d.\n", j+1);
- mostrarDatos(arreglo);
- j++;
- arreglo++;
- }
- }
- int computacion(datos *arreglo){
- int k=0, cantidad=0;
- while(k<i-1){
- if(strcmp(arreglo->Categoria, "computacion") == 0){
- cantidad++;
- }
- k++;
- arreglo++;
- }
- return cantidad;
- }
- int main(void){
- int cantidad;
- datos PRODUCTOS[1000];
- cargarProductos(PRODUCTOS);
- mostrarProductos(PRODUCTOS);
- cantidad = computacion(PRODUCTOS);
- printf("La cantidad de productos de la categoria Computacion son: %d",cantidad);
- //datos producto = cargarDatos();
- //modificarPrecio(&producto.Precio, &producto.Stock);
- //printf("Precio final: %f", producto.Precio);
- //mostrarDatos(&producto);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement