#include #include #define NUM_CLIENTS 10 #define PRIX_STANDARD 0.2 struct call_record { int no_client; // numéro client int no_tel_appel; // numéro de tel appelé int date; // la date int minutes; // la durée de l'appel }; struct cost { int tel; // numéro de tel float chf_par_minute; // tarif }; struct call_record *load_n_call_records(int n) { struct call_record *records = malloc(n * sizeof(struct call_record)); for (int i = 0; i < n; i++) { scanf("%d %d %d %d", &records[i].no_client, &records[i].date, &records[i].no_tel_appel, &records[i].minutes); } return records; } struct cost *load_n_costs(int n) { struct cost *costs = malloc(n * sizeof(struct cost)); for (int i = 0; i < n; i++) { scanf("%d %f", &costs[i].tel, &costs[i].chf_par_minute); } return costs; } void temps_total(const struct call_record *records, int M, int *total_minutes) { for (int i = 0; i < 10; i++) total_minutes[i] = 0; for (int i = 0; i < M; i++) { total_minutes[records[i].no_client] += records[i].minutes; } } void temps_total_mois(const struct call_record *records, int M, int mois, int *total_minutes) { for (int i = 0; i < 10; i++) total_minutes[i] = 0; for (int i = 0; i < M; i++) { if (records[i].date / 100 == mois) { total_minutes[records[i].no_client] += records[i].minutes; } } } float chf_minute(const struct cost *costs, int N, int tel) { for (int i = 0; i < N; i++) { if (costs[i].tel == tel) { return costs[i].chf_par_minute; } } return PRIX_STANDARD; } void chf_total_mois(const struct call_record *records, const struct cost *costs, int M, int N, int mois, float *total_cout) { for (int i = 0; i < 10; i++) total_cout[i] = 0; for (int i = 0; i < M; i++) { if (records[i].date / 100 == mois) { total_cout[records[i].no_client] += records[i].minutes * chf_minute(costs, N, records[i].no_tel_appel); } } } void afficher_minutes(int *minutes) { for (int i = 0; i < NUM_CLIENTS; i++) { printf("Client %d: %d minutes\n", i, minutes[i]); } } void afficher_chf(float *cout) { for (int i = 0; i < NUM_CLIENTS; i++) { printf("Client %d: CHF %.02f\n", i, cout[i]); } } int main() { int M, N; struct call_record *records; struct cost *costs; scanf("%d %d", &M, &N); records = load_n_call_records(M); costs = load_n_costs(N); int total_minutes[10]; temps_total(records, M, total_minutes); afficher_minutes(total_minutes); temps_total_mois(records, M, 202401, total_minutes); printf("***\n" "Minutes janvier 2024\n"); afficher_minutes(total_minutes); temps_total_mois(records, M, 202311, total_minutes); printf("***\n" "Minutes novembre 2023\n"); afficher_minutes(total_minutes); float total_cout[10]; chf_total_mois(records, costs, M, N, 202311, total_cout); printf("***\n" "CHF novembre 2023\n"); afficher_chf(total_cout); chf_total_mois(records, costs, M, N, 202308, total_cout); printf("***\n" "CHF aout 2023\n"); afficher_chf(total_cout); free(records); free(costs); }