As part of my subject of data structure we have left the following exercise:
Create a data structure that allows to store the data of the total purchases of customers from a warehouse. You want to store the following information: Number of the invoice, Date, Warehouse, Client, City, Sex, Value purchases.
Create an arrangement that allows you to fill in the information of N clients and then implement (you can use a menu) the following options:
Show the total value of purchases made by customers, and the average of purchases Sort the arrangement and display it according to the following criteria:
- 2.1 For customers
- 2.2 Por almacen
- 2.3 By value purchases (descending)
Show a summary that says:
- 3.1 How many sales were made in each city
- 3.2 How many customers are there in each city
Include an option that allows you to search the vector by city. The name of the city will be entered and the system must return all sales made in that city.
The point is that we have already done most of the code, the program is able to read the necessary data, perform the operations, the orders, etc ...
But we have not been able to create the algorithm to count the number of clients in each city, since the program must be able to recognize when a customer has repeated itself in the city so as not to register it as a different client; that is, if a client performs, for example, 2 purchases in the same city, the program registers it as a single client, not as 2.
Here is the code we use to count sales (the simple part, since there are no exceptions) and the structure we created:
struct venta{//la estructura que utilizamos
string numfactura;//numero de factura
string fecha;
string almacen;
string cliente;
int ciudad;//la ciudad tiene unos cuantos valores predefinidos
float valorcompras;
}vector[50];
for (int i=0;i<N;i++){//Este ciclo recorre el vector en busca de las coincidencias
if (vector[i].ciudad==1){
ventasm+=1;//cuando ciudad es 1, se le suma 1 al contador de la ciudad 1.
clientesm+=1;//esto es lo que tenemos, si el cliente se repite varias veces, este algorito lo contará como clientes diferentes. esto es lo que necesitamos cambiar.
}
else if (vector[i].ciudad==2){//exactamente lo mismo pero con la segunda ciudad
ventabq+=1;
clientebq+=1;
}
}
I really hope I have been concise and that you can help me solve this problem. thanks in advance.