Merge pull request 'client' (#2) from client into master

Reviewed-on: #2
pull/3/head^2
Matheo HERSAN 2 years ago
commit a92406963b

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="" vcs="Git" />
</component> </component>
</project> </project>

BIN
app

Binary file not shown.

@ -3,4 +3,3 @@
272 6.500 10.00 29.99 272 6.500 10.00 29.99
464 50.0 25.50 60.00 464 50.0 25.50 60.00
958 4.75 60.00 32.00 958 4.75 60.00 32.00

@ -1,24 +1,174 @@
// #include <stdio.h>
// Created by Mathéo Hersan on 16/10/2023.
//
#include "client.h" #include "client.h"
void afficherDonneesClient() { #define MAX_ARTICLES 100
FILE *fichier = fopen("donnee/client.txt", "r"); #define MAX_CLIENTS 100
int numeroClient;
int charger_clients(int numeros[], float cagnottes[], int suspendues[], int tPhysique) {
int i = 0, numero, suspendue;
float cagnotte; float cagnotte;
int suspendu; FILE *fe;
fe = fopen("donnee/client.txt", "r");
if (fe == NULL) {
perror("fopen");
return -1;
}
while (fscanf(fe, "%d %f %d", &numero, &cagnotte, &suspendue) == 3) {
if (i == tPhysique) {
fprintf(stderr, "Tableau plein");
break;
}
numeros[i] = numero;
cagnottes[i] = cagnotte;
suspendues[i] = suspendue;
i++;
}
fclose(fe);
return i;
}
void ajouter_article_au_panier(int numeroClient, int references[], float poids[], float volume[], float prixUnitaire[],
int numeros[], float cagnottes[], int suspendues[], int nombreArticles, int nombreClients,
float volumeCoffre, float chargeMaximale, int panier[], int quantites[], int *taillePanier) {
int reference, quantite;
printf("Entrez la référence de l'article : ");
scanf("%d", &reference);
printf("Entrez la quantité : ");
scanf("%d", &quantite);
int articleIndex = -1;
for (int i = 0; i < nombreArticles; i++) {
if (references[i] == reference) {
articleIndex = i;
break;
}
}
if (articleIndex == -1) {
printf("Article non trouvé. Veuillez entrer une référence valide.\n");
return;
}
for (int i = 0; i < *taillePanier; i++) {
if (panier[i] == reference) {
printf("Cet article est déjà dans le panier.\n");
return;
}
}
float poidsTotal = poids[articleIndex] * quantite;
float volumeTotal = volume[articleIndex] * quantite;
if (poidsTotal > chargeMaximale) {
printf("Désolé, dépassement de la charge autorisée.\n");
} else if (volumeTotal > volumeCoffre) {
printf("Désolé, dépassement du volume autorisé.\n");
} else {
float montantTotal = prixUnitaire[articleIndex] * quantite;
int clientIndex = -1;
for (int i = 0; i < nombreClients; i++) {
if (numeros[i] == numeroClient) {
clientIndex = i;
break;
}
}
if (clientIndex != -1) {
cagnottes[clientIndex] += 0.1 * montantTotal;
}
if (fichier == NULL) { panier[*taillePanier] = reference;
fprintf(stderr, "Erreur lors de l'ouverture du fichier"); quantites[*taillePanier] = quantite;
exit(EXIT_FAILURE); (*taillePanier)++;
printf("Contenu du panier : ");
for (int i = 0; i < *taillePanier; i++) {
printf("%d ", panier[i]);
}
printf("\n");
printf("Référence : %d\nQuantité : %d\n", reference, quantite);
printf("Récap :\n");
printf("Réf Qté Poids Vol PrixU PoidsTot VolTot PrixTot Cagnotte\n");
printf("%d %d %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n",
reference, quantite, poids[articleIndex], volume[articleIndex],
prixUnitaire[articleIndex], poidsTotal, volumeTotal, montantTotal,
cagnottes[clientIndex]);
printf("Prix total à payer: %.2f euros\n", montantTotal);
printf("Cagnotte totale : %.2f euros\n", cagnottes[clientIndex]);
printf("Volume utilise : %.2f litres\n", volumeTotal);
printf("Volume restant : %.2f litres\n", volumeCoffre - volumeTotal);
printf("Charge Actuelle: %.2f kg\n", poidsTotal);
printf("Charge restante: %.2f kg\n", chargeMaximale - poidsTotal);
}
}
void supprimer_article_du_panier(int panier[], int *taillePanier) {
int reference;
printf("Entrez la référence de l'article à supprimer : ");
scanf("%d", &reference);
int articleIndex = -1;
for (int i = 0; i < *taillePanier; i++) {
if (panier[i] == reference) {
articleIndex = i;
break;
}
}
if (articleIndex == -1) {
printf("Article non trouvé dans le panier. Veuillez entrer une référence valide.\n");
return;
} }
while (fscanf(fichier, "%d%f%d", &numeroClient, &cagnotte, &suspendu) == 3) { for (int i = articleIndex; i < (*taillePanier - 1); i++) {
printf("Client %d, Cagnotte %.2f, Suspendu: %s\n", panier[i] = panier[i + 1];
numeroClient, cagnotte, (suspendu == 0) ? "Non" : "Oui");
} }
fclose(fichier); (*taillePanier)--;
printf("Article supprimé du panier avec succès.\n");
} }
void affiche_recap_panier(int panier[], int taillePanier, int references[], float poids[], float volume[],
float prixUnitaire[], int quantites[]) {
printf("Réf Qté Poids Vol PrixU PoidsTot VolTot PrixTot\n");
float poidsTotal = 0, volumeTotal = 0, montantTotal = 0;
for (int i = 0; i < taillePanier; i++) {
int reference = panier[i];
int articleIndex = -1;
for (int j = 0; j < MAX_ARTICLES; j++) {
if (references[j] == reference) {
articleIndex = j;
break;
}
}
if (articleIndex == -1) {
printf("Article non trouvé. Veuillez entrer une référence valide.\n");
return;
}
float poidsArticle = poids[articleIndex];
float volumeArticle = volume[articleIndex];
float prixArticle = prixUnitaire[articleIndex];
int quantite = quantites[i];
printf("%d\t %d\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\n",
reference, quantite, poidsArticle, volumeArticle,
prixArticle, poidsArticle * quantite, volumeArticle * quantite, prixArticle * quantite);
poidsTotal += poidsArticle * quantite;
volumeTotal += volumeArticle * quantite;
montantTotal += prixArticle * quantite;
}
printf("Prix total à payer: %.2f euros\n", montantTotal);
printf("Volume utilise : %.2f litres\n", volumeTotal);
printf("Charge Actuelle: %.2f kg\n", poidsTotal);
}

@ -8,6 +8,11 @@
#include<stdio.h> #include<stdio.h>
#include<stdlib.h> #include<stdlib.h>
void afficherDonneesClient(); int charger_clients(int numeros[], float cagnottes[], int suspendues[], int tPhysique);
void ajouter_article_au_panier(int numeroClient, int references[], float poids[], float volume[], float prixUnitaire[],
int numeros[], float cagnottes[], int suspendues[], int nombreArticles, int nombreClients,
float volumeCoffre, float chargeMaximale, int panier[], int quantites[], int *taillePanier);
void supprimer_article_du_panier(int panier[], int *taillePanier);
void affiche_recap_panier(int panier[], int taillePanier, int references[], float poids[], float volume[],
float prixUnitaire[], int quantites[]);
#endif //SAE_101_CLIENT_H #endif //SAE_101_CLIENT_H

@ -1,11 +0,0 @@
#include <stdio.h>
#include "responsable.h"
#include "../interface/interface_resp.h"
#include "../interface/interface_client.h"
int main(void)
{
global_resp();
return 0;
}

@ -1,10 +1,14 @@
#include "interface_client.h" #include "interface_client.h"
#include "app/core_logic/client.h" #include "app/core_logic/client.h"
#include "app/core_logic/responsable.h"
void affiche_client(int a){ #define MAX_ARTICLES 100
#define MAX_CLIENTS 100
void affiche_client(int a) {
printf("\n"); printf("\n");
printf("+-------------+ \n"); printf("+-------------+ \n");
printf("|| Bonjour ! ||\n") ; printf("|| Bonjour ! ||\n");
printf("+-------------+ \n"); printf("+-------------+ \n");
printf("\n"); printf("\n");
printf("+-----------------------------------------------------------------+\n"); printf("+-----------------------------------------------------------------+\n");
@ -14,6 +18,7 @@ void affiche_client(int a){
printf("||\t3 : Supprimer un article du panier. \t \t \t || \n"); printf("||\t3 : Supprimer un article du panier. \t \t \t || \n");
printf("||\t4 : Modifier la quantité d'un article du panier. \t || \n"); printf("||\t4 : Modifier la quantité d'un article du panier. \t || \n");
printf("||\t5 : Réinitialiser le panier. \t \t \t \t || \n"); printf("||\t5 : Réinitialiser le panier. \t \t \t \t || \n");
printf("||\t9 : Quitter. \t \t \t \t \t \t || \n");
printf("+-----------------------------------------------------------------+\n"); printf("+-----------------------------------------------------------------+\n");
} }
@ -23,22 +28,79 @@ void affiche_client(int a){
void menu_client(int *choix, int jour) { void menu_client(int *choix, int jour) {
affiche_client(jour); affiche_client(jour);
printf("Vous choisissez: "); printf("Vous choisissez: ");
while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 5) { while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 9) {
while (getchar() != '\n'); // Nettoie le tampon d'entrée en cas de saisie invalide while (getchar() != '\n');
affiche_client(jour); affiche_client(jour);
printf("Veuillez entrer un choix valide : "); printf("Veuillez entrer un choix valide : ");
} }
} }
void global_client() { void global_client() {
int choix, jour; int choix, jour = 0;
int references[MAX_ARTICLES];
float poids[MAX_ARTICLES];
float volume[MAX_ARTICLES];
float prixUnitaire[MAX_ARTICLES];
int numeros[MAX_CLIENTS];
float cagnottes[MAX_CLIENTS];
int suspendus[MAX_CLIENTS];
int nombreArticles, nombreClients;
float volumeCoffre, chargeMaximale;
int numeroClient;
int quantites[MAX_ARTICLES];
int panier[MAX_ARTICLES];
int taillePanier = 0;
nombreArticles = chargementArticles(references, poids, volume, prixUnitaire, MAX_ARTICLES);
nombreClients = charger_clients(numeros, cagnottes, suspendus, MAX_CLIENTS);
printf("Veuillez saisir la taille disponible du véhicule (en litres) : ");
scanf("%f", &volumeCoffre);
printf("Veuillez saisir la charge maximale autorisée (en kg) : ");
scanf("%f", &chargeMaximale);
printf("Veuillez saisir votre numéro de client : ");
scanf("%d", &numeroClient);
int indexClient = -1;
for (int i = 0; i < nombreClients; i++) {
if (numeros[i] == numeroClient) {
indexClient = i;
break;
}
}
if (indexClient == -1) {
printf("Client non trouvé. Impossible d'utiliser l'application.\n");
return;
}
if (suspendus[indexClient] == 1) {
printf("Le client est suspendu et ne peut pas utiliser l'application.\n");
return;
}
do{
menu_client(&choix, jour); menu_client(&choix, jour);
switch (choix) { switch (choix) {
case 1: case 1:
afficherDonneesClient(); affiche_recap_panier(panier, taillePanier, references, poids, volume, prixUnitaire, quantites);
break;
case 2:
ajouter_article_au_panier(numeroClient, references, poids, volume, prixUnitaire, numeros, cagnottes,
suspendus, nombreArticles, nombreClients, volumeCoffre, chargeMaximale, panier, quantites, &taillePanier);
break;
case 3:
supprimer_article_du_panier(panier, &taillePanier);
break; break;
case 9:
printf("Au revoir !\n");
return;
default: default:
printf("Veuillez entrer un choix valide !\n"); printf("Veuillez entrer un choix valide !\n");
break; break;
} }
}while(choix != 9);
} }

@ -1,4 +1,3 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "interface_resp.h" #include "interface_resp.h"

@ -3,6 +3,7 @@
#include "app/interface/interface_client.h" #include "app/interface/interface_client.h"
#include "app/interface/interface_resp.h" #include "app/interface/interface_resp.h"
#include "app/core_logic/client.h" #include "app/core_logic/client.h"
#include "app/core_logic/responsable.h"
int choixInterface(void) { int choixInterface(void) {
int choix; int choix;
@ -26,5 +27,6 @@ int main(){
case 1: global_resp(); case 1: global_resp();
case 2: global_client(); case 2: global_client();
} }
return 0; return 0;
} }

Loading…
Cancel
Save