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"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="" vcs="Git" />
</component>
</project>

BIN
app

Binary file not shown.

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

@ -1,24 +1,174 @@
//
// Created by Mathéo Hersan on 16/10/2023.
//
#include <stdio.h>
#include "client.h"
void afficherDonneesClient() {
FILE *fichier = fopen("donnee/client.txt", "r");
int numeroClient;
#define MAX_ARTICLES 100
#define MAX_CLIENTS 100
int charger_clients(int numeros[], float cagnottes[], int suspendues[], int tPhysique) {
int i = 0, numero, suspendue;
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) {
fprintf(stderr, "Erreur lors de l'ouverture du fichier");
exit(EXIT_FAILURE);
panier[*taillePanier] = reference;
quantites[*taillePanier] = quantite;
(*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;
}
for (int i = articleIndex; i < (*taillePanier - 1); i++) {
panier[i] = panier[i + 1];
}
while (fscanf(fichier, "%d%f%d", &numeroClient, &cagnotte, &suspendu) == 3) {
printf("Client %d, Cagnotte %.2f, Suspendu: %s\n",
numeroClient, cagnotte, (suspendu == 0) ? "Non" : "Oui");
(*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;
}
fclose(fichier);
}
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<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

@ -57,14 +57,14 @@ int ajouterArticle( int tRef[], float tPoids[], float tVol[], float tPrix[], int
fprintf(stderr,"Tableau plein !");
return -2;
}
// SI on trie pas par ref c'est ca
tRef[i] = ref;
tPoids[i] = poids;
tVol[i] = volume;
tPrix[i] = prix;
return 0;
}
void rechercheRefArticle(int tRef[], int ref, int *index, int tLogique)
@ -88,15 +88,15 @@ void supprimerArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], i
int ref, index;
affichSupprimerArticle(&ref);
rechercheRefArticle(tRef, ref, &index, *tLogique);
for( int i = index; i< *tLogique-1; ++i)
{
tRef[i] = tRef[i+1];
tPoids[i] = tPoids[i+1];
tVol[i] = tVol[i+1];
tPrix[i] = tPrix[i+1];
}
*tLogique -= 1;
for( int i = index; i< *tLogique-1; ++i)
{
tRef[i] = tRef[i+1];
tPoids[i] = tPoids[i+1];
tVol[i] = tVol[i+1];
tPrix[i] = tPrix[i+1];
}
*tLogique -= 1;
}
void modifierArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique)

@ -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 "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("|| Bonjour ! ||\n") ;
printf("|| Bonjour ! ||\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("||\t4 : Modifier la quantité d'un article du panier. \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");
}
@ -23,22 +28,79 @@ void affiche_client(int a){
void menu_client(int *choix, int jour) {
affiche_client(jour);
printf("Vous choisissez: ");
while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 5) {
while (getchar() != '\n'); // Nettoie le tampon d'entrée en cas de saisie invalide
while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 9) {
while (getchar() != '\n');
affiche_client(jour);
printf("Veuillez entrer un choix valide : ");
}
}
void global_client() {
int choix, jour;
menu_client(&choix, jour);
switch (choix) {
case 1:
afficherDonneesClient();
break;
default:
printf("Veuillez entrer un choix valide !\n");
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);
switch (choix) {
case 1:
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;
case 9:
printf("Au revoir !\n");
return;
default:
printf("Veuillez entrer un choix valide !\n");
break;
}
}while(choix != 9);
}

@ -1,4 +1,3 @@
#include <stdio.h>
#include <stdlib.h>
#include "interface_resp.h"
@ -50,7 +49,7 @@ void affichArticles( int tRef[], float tPoids[], float tVol[], float tPrix[], in
for ( int i = 0; i < tLogique; ++i)
{
printf("\t %d %.2f %.2f %.2f\n\n", tRef[i], tPoids[i], tVol[i], tPrix[i]);
}
}
}
void affichUnArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique)
@ -117,7 +116,7 @@ void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix)
}
printf("Entrez le poids du nouveaux produit\n");
scanf("%f", poids);
if ( *poids < 0 )
if ( *poids < 0 )
{
while ( *poids < 0 )
{
@ -127,7 +126,7 @@ void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix)
}
printf("Entrez le volume du nouveaux produit\n");
scanf("%f", volume);
if ( *volume < 0 )
if ( *volume < 0 )
{
while ( *volume < 0 )
{
@ -137,7 +136,7 @@ void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix)
}
printf("Entrez le prix du nouveaux produit\n");
scanf("%f", prix);
if ( *prix < 0 )
if ( *prix < 0 )
{
while ( *prix < 0 )
{
@ -169,7 +168,7 @@ void affichModifierArticle(int *ref, float *poids, float *volume, float *prix)
printf("\tVeuillez entrer une référence correcte !\n");
while (getchar() != '\n');
}
printf("\t Quel est le nouveau poids à entrer ?\n");
while(scanf("%f", poids) != 1 || *poids <= 0)
{
@ -198,7 +197,7 @@ void menu_resp(int *choix, int jour) {
//affiche_resp(jour);
printf("Vous choisissez: ");
while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 5) {
while (getchar() != '\n');
while (getchar() != '\n');
affiche_resp(jour);
printf("Veuillez entrer un choix valide : ");
}
@ -210,14 +209,14 @@ void menu_resp(int *choix) {
//affiche_resp(jour);
printf("Vous choisissez: ");
while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 5) {
while (getchar() != '\n');
while (getchar() != '\n');
affiche_resp();
printf("Veuillez entrer un choix valide : ");
}
}
void global_resp(){
int choix, a;
int choix, a;
int tRef[MAX_ARTICLES];
float tPoids[MAX_ARTICLES];
float tVol[MAX_ARTICLES];

@ -7,4 +7,4 @@ void affichSupprimerArticle(int *ref);
void affichModifierArticle(int *ref, float *poids, float *volume, float *prix);
void menu_resp(int *choix, int jour);
void global_resp();
void affiche_resp(void);
void affiche_resp(void);

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

Loading…
Cancel
Save