diff --git a/GaideC18.c b/GaideC18.c index e40699c..58bdee6 100644 --- a/GaideC18.c +++ b/GaideC18.c @@ -1,57 +1,57 @@ -#include -#include -#include -#include - -//http://www.gnu.org/software/libc/manual/html_mono/libc.html#Comparison-Functions - -void EncoderContact (char*,char*,char*,char*,char*); -void EcrireContact (char*,char*,char*,char*,char*,FILE*); -FILE*OuvrirFichier (); -int main() -{ - char Nom[21],Prenom[21],Tel[11],GSM[15],eMail[30]; - - EncoderContact(Nom, Prenom, Tel, GSM, eMail); - EcrireContact(Nom, Prenom, Tel, GSM, eMail, OuvrirFichier()); -} -EncoderContact(char*Nom,char*Prenom,char*Tel,char*GSM,char*eMail) -{ - printf("entrez votre nom: \t"); - fflush(stdin); - gets(Nom); - printf(" entrez votre Prenom: \t"); - fflush(stdin); - gets(Prenom); - printf("\n entrez votre num�ro de telephone :\t "); - fflush(stdin); - gets(Tel); - printf("\n entrez votre num�ro de GSM : \t"); - fflush(stdin); - gets(GSM); - printf("\n entrez votre eMail:\t "); - fflush(stdin); - gets(eMail); - -} -EcrireContact(char*Nom,char*Prenom,char*Tel,char*GSM,char*eMail,FILE*PtFichier) -{ - fprintf(PtFichier, "%s\n%s \n %s \n%s \n %s \n",Nom,Prenom,Tel,GSM,eMail); - fclose(PtFichier); -} -FILE *OuvrirFichier () -{ - char NomFichier [50]; - FILE*PtFichier; - do - { - printf("entrez le nom de votre fichier (avec chemin d'acc�s):\n"); - fflush(stdin); - gets(NomFichier); - PtFichier=fopen(NomFichier,"w"); - } - while(PtFichier==NULL); - printf("fichier cree"); - return (PtFichier); - -} +#include +#include +#include +#include + +//http://www.gnu.org/software/libc/manual/html_mono/libc.html#Comparison-Functions + +void EncoderContact (char*,char*,char*,char*,char*); +void EcrireContact (char*,char*,char*,char*,char*,FILE*); +FILE*OuvrirFichier (); +int main() +{ + char Nom[21],Prenom[21],Tel[11],GSM[15],eMail[30]; + + EncoderContact(Nom, Prenom, Tel, GSM, eMail); + EcrireContact(Nom, Prenom, Tel, GSM, eMail, OuvrirFichier()); +} +EncoderContact(char*Nom,char*Prenom,char*Tel,char*GSM,char*eMail) +{ + printf("entrez votre nom: \t"); + fflush(stdin); + gets(Nom); + printf(" entrez votre Prenom: \t"); + fflush(stdin); + gets(Prenom); + printf("\n entrez votre num�ro de telephone :\t "); + fflush(stdin); + gets(Tel); + printf("\n entrez votre num�ro de GSM : \t"); + fflush(stdin); + gets(GSM); + printf("\n entrez votre eMail:\t "); + fflush(stdin); + gets(eMail); + +} +EcrireContact(char*Nom,char*Prenom,char*Tel,char*GSM,char*eMail,FILE*PtFichier) +{ + fprintf(PtFichier, "%s\n%s \n %s \n%s \n %s \n",Nom,Prenom,Tel,GSM,eMail); + fclose(PtFichier); +} +FILE *OuvrirFichier () +{ + char NomFichier [50]; + FILE*PtFichier; + do + { + printf("entrez le nom de votre fichier (avec chemin d'acc�s):\n"); + fflush(stdin); + gets(NomFichier); + PtFichier=fopen(NomFichier,"w"); + } + while(PtFichier==NULL); + printf("fichier cree"); + return (PtFichier); + +} diff --git a/GaideC19.c b/GaideC19.c index a97fde4..3897da1 100644 --- a/GaideC19.c +++ b/GaideC19.c @@ -1,33 +1,33 @@ -#include -#include -void CharToString(char,char*); -int versAscii(char); -int main() -{ - char cara,b[9]; - for(cara= 'A'; cara<='Z';cara++) - { - CharToString(cara,b); - printf("%c: %Xh %s\n",cara, versAscii(cara), b); - - } - getch(); - return 0; -} - -int versAscii(char c) -{ - return (int)c; -} - -void CharToString(char cara, char* b) -{ - int i,m=1; - for(i=7;i>=0;i--) - { - if(cara&m) b[i]='1'; - else b[i]='0'; - m<<=1; - } - b[8]='\0'; -} +#include +#include +void CharToString(char,char*); +int versAscii(char); +int main() +{ + char cara,b[9]; + for(cara= 'A'; cara<='Z';cara++) + { + CharToString(cara,b); + printf("%c: %Xh %s\n",cara, versAscii(cara), b); + + } + getch(); + return 0; +} + +int versAscii(char c) +{ + return (int)c; +} + +void CharToString(char cara, char* b) +{ + int i,m=1; + for(i=7;i>=0;i--) + { + if(cara&m) b[i]='1'; + else b[i]='0'; + m<<=1; + } + b[8]='\0'; +} diff --git a/VANDAMME18.c b/VANDAMME18.c index d9ec778..d722e2c 100644 --- a/VANDAMME18.c +++ b/VANDAMME18.c @@ -1,92 +1,92 @@ -/* - * EX18 - * VAN DAMME Adrien - * Grp 2 - * La fct fgets permet de récuperer une chaine de caractère de façon sécurisée - * - */ - -#include -#include -#include -#include - -#define __STR_LENGHT__ 20 - -int EncoderContact(char *, char *, char *, char *, char *); -int EcrireContact(char *, char *, char *, char *, char *, FILE *); -FILE* OuvrirFichier(); - -int main() { - char Nom[__STR_LENGHT__],Prenom[__STR_LENGHT__],Tel[__STR_LENGHT__],GSM[__STR_LENGHT__],eMail[__STR_LENGHT__]; - FILE * fi; - fi = OuvrirFichier(); - - while(EncoderContact(Nom, Prenom, Tel, GSM, eMail)==-1); - while(EcrireContact(Nom, Prenom, Tel, GSM, eMail, fi)==-1); - fclose(fi); - return 0; -} - -int EncoderContact(char *nom, char *prenom, char *tel, char *gsm, char *email) -{ - int bug = 0; - char *p; - printf("Votre nom (%d caratères max)", (int)__STR_LENGHT__); - fflush(stdin);bug = fgets(nom, __STR_LENGHT__, stdin)?bug:-1; - p = strchr(nom, '\n'); - if(p)*p=0; - - printf("Votre prenom (%d caratères max)", (int)__STR_LENGHT__); - fflush(stdin);bug = fgets(prenom, __STR_LENGHT__, stdin)?bug:-1; - p = strchr(prenom, '\n'); - if(p)*p=0; - - printf("Votre telephone (%d caratères max)", (int)__STR_LENGHT__); - fflush(stdin);bug = fgets(tel, __STR_LENGHT__, stdin)?bug:-1; - p = strchr(tel, '\n'); - if(p)*p=0; - - printf("Votre gsm (%d caratères max)", (int)__STR_LENGHT__); - fflush(stdin);bug = fgets(gsm, __STR_LENGHT__, stdin)?bug:-1; - p = strchr(gsm, '\n'); - if(p)*p=0; - - printf("Votre email (%d caratères max)", (int)__STR_LENGHT__); - fflush(stdin);bug = fgets(email, __STR_LENGHT__, stdin)?bug:-1; - p = strchr(email, '\n'); - if(p)*p = 0; - - return bug; -} -int EcrireContact(char *nom, char *prenom, char *tel, char *gsm, char *email, FILE *f) -{ - int bug = 0; - clearerr(f); - fprintf(f, "Nom %s\n", nom); - bug = ferror(f)?-1:bug; - fprintf(f, "Prenom %s\n", prenom); - bug = ferror(f)?-1:bug; - fprintf(f, "Telephone %s\n", tel); - bug = ferror(f)?-1:bug; - fprintf(f, "GSM %s\n", gsm); - bug = ferror(f)?-1:bug; - fprintf(f, "Email %s\n", email); - bug = ferror(f)?-1:bug; - - return bug; -} -FILE* OuvrirFichier() -{ - FILE *fi; - char chemin[__STR_LENGHT__]; - do{ - do{ - printf("Emplacement de votre fichier (%d caratères max)", (int)__STR_LENGHT__); - fflush(stdin); - }while(fgets(chemin, __STR_LENGHT__, stdin) == NULL); - *(strchr(chemin, '\n')) = 0; - fi = fopen(chemin, "w"); - }while(fi == NULL); - return fi; -} +/* + * EX18 + * VAN DAMME Adrien + * Grp 2 + * La fct fgets permet de récuperer une chaine de caractère de façon sécurisée + * + */ + +#include +#include +#include +#include + +#define __STR_LENGHT__ 20 + +int EncoderContact(char *, char *, char *, char *, char *); +int EcrireContact(char *, char *, char *, char *, char *, FILE *); +FILE* OuvrirFichier(); + +int main() { + char Nom[__STR_LENGHT__],Prenom[__STR_LENGHT__],Tel[__STR_LENGHT__],GSM[__STR_LENGHT__],eMail[__STR_LENGHT__]; + FILE * fi; + fi = OuvrirFichier(); + + while(EncoderContact(Nom, Prenom, Tel, GSM, eMail)==-1); + while(EcrireContact(Nom, Prenom, Tel, GSM, eMail, fi)==-1); + fclose(fi); + return 0; +} + +int EncoderContact(char *nom, char *prenom, char *tel, char *gsm, char *email) +{ + int bug = 0; + char *p; + printf("Votre nom (%d caratères max)", (int)__STR_LENGHT__); + fflush(stdin);bug = fgets(nom, __STR_LENGHT__, stdin)?bug:-1; + p = strchr(nom, '\n'); + if(p)*p=0; + + printf("Votre prenom (%d caratères max)", (int)__STR_LENGHT__); + fflush(stdin);bug = fgets(prenom, __STR_LENGHT__, stdin)?bug:-1; + p = strchr(prenom, '\n'); + if(p)*p=0; + + printf("Votre telephone (%d caratères max)", (int)__STR_LENGHT__); + fflush(stdin);bug = fgets(tel, __STR_LENGHT__, stdin)?bug:-1; + p = strchr(tel, '\n'); + if(p)*p=0; + + printf("Votre gsm (%d caratères max)", (int)__STR_LENGHT__); + fflush(stdin);bug = fgets(gsm, __STR_LENGHT__, stdin)?bug:-1; + p = strchr(gsm, '\n'); + if(p)*p=0; + + printf("Votre email (%d caratères max)", (int)__STR_LENGHT__); + fflush(stdin);bug = fgets(email, __STR_LENGHT__, stdin)?bug:-1; + p = strchr(email, '\n'); + if(p)*p = 0; + + return bug; +} +int EcrireContact(char *nom, char *prenom, char *tel, char *gsm, char *email, FILE *f) +{ + int bug = 0; + clearerr(f); + fprintf(f, "Nom %s\n", nom); + bug = ferror(f)?-1:bug; + fprintf(f, "Prenom %s\n", prenom); + bug = ferror(f)?-1:bug; + fprintf(f, "Telephone %s\n", tel); + bug = ferror(f)?-1:bug; + fprintf(f, "GSM %s\n", gsm); + bug = ferror(f)?-1:bug; + fprintf(f, "Email %s\n", email); + bug = ferror(f)?-1:bug; + + return bug; +} +FILE* OuvrirFichier() +{ + FILE *fi; + char chemin[__STR_LENGHT__]; + do{ + do{ + printf("Emplacement de votre fichier (%d caratères max)", (int)__STR_LENGHT__); + fflush(stdin); + }while(fgets(chemin, __STR_LENGHT__, stdin) == NULL); + *(strchr(chemin, '\n')) = 0; + fi = fopen(chemin, "w"); + }while(fi == NULL); + return fi; +} diff --git a/VANDAMME19.c b/VANDAMME19.c index e7699fe..77f868d 100644 --- a/VANDAMME19.c +++ b/VANDAMME19.c @@ -1,26 +1,26 @@ -#include -#include -void CharToString(char,char*); -unsigned int toAscii(char); -int main() -{ - char cara,b[9]; - for(cara='A'; cara<='Z';cara++) - { - CharToString(cara,b); - printf("%c: %Xh %s\n",cara, toAscii(cara), b); - } - getch(); - return 0; -} - -unsigned int toAscii(char c) - return (unsigned int)c; - -void CharToString(char cara, char* b) -{ - int i; - for(i=0;i<8;i++) - b[8-i-1]=(cara&(1< +#include +void CharToString(char,char*); +unsigned int toAscii(char); +int main() +{ + char cara,b[9]; + for(cara='A'; cara<='Z';cara++) + { + CharToString(cara,b); + printf("%c: %Xh %s\n",cara, toAscii(cara), b); + } + getch(); + return 0; +} + +unsigned int toAscii(char c) + return (unsigned int)c; + +void CharToString(char cara, char* b) +{ + int i; + for(i=0;i<8;i++) + b[8-i-1]=(cara&(1< -#include -#include -#include - -#define __STR_LENGHT__ 20 - -int LireMots(char *, char **); -int trier (char **); -int cmpstr(char *, char *); -int affTab(char **); - -int main() { - char tab[20][20]; - char chemin[20] = "tt.txt"; - LireMots(chemin, tab); - affTab(tab); - trier(tab); - affTab(tab); - return 0; -} - - -int LireMots(char *chemin, char **tab) -{ - int i; - char c[__STR_LENGHT__]; - char *p; - FILE * fi; - if((fi=fopen(chemin, "r")) == NULL) - return -1; - for(i=0;i<20;i++) - { - fgets(c, 20,fi); - p = strchr(c, '\n'); - if(p)*p = 0; - strcpy(((char*)tab+(i*20)),c); - } - return 0; -} -int trier(char **tab) -{ - qsort(tab,20,20,cmpstr); -} -int affTab(char **tab) -{ - int i=0; - for(i=0;i<20;i++) - printf("%s\n", ((char*)tab+(i*20))); -} -int cmpstr(char *a, char *b) { - return strcmp(a, b); -} +/* + * EX20 + * VAN DAMME Adrien + * Grp 2 + * La fct fgets permet de récuperer une chaine de caractère de façon sécurisée + * + */ + +#include +#include +#include +#include + +#define __STR_LENGHT__ 20 + +int LireMots(char *, char **); +int trier (char **); +int cmpstr(char *, char *); +int affTab(char **); + +int main() { + char tab[20][20]; + char chemin[20] = "tt.txt"; + LireMots(chemin, tab); + affTab(tab); + trier(tab); + affTab(tab); + return 0; +} + + +int LireMots(char *chemin, char **tab) +{ + int i; + char c[__STR_LENGHT__]; + char *p; + FILE * fi; + if((fi=fopen(chemin, "r")) == NULL) + return -1; + for(i=0;i<20;i++) + { + fgets(c, 20,fi); + p = strchr(c, '\n'); + if(p)*p = 0; + strcpy(((char*)tab+(i*20)),c); + } + return 0; +} +int trier(char **tab) +{ + qsort(tab,20,20,cmpstr); +} +int affTab(char **tab) +{ + int i=0; + for(i=0;i<20;i++) + printf("%s\n", ((char*)tab+(i*20))); +} +int cmpstr(char *a, char *b) { + return strcmp(a, b); +} diff --git a/VANDAMME23.c b/VANDAMME23.c index fc640a0..483327d 100644 --- a/VANDAMME23.c +++ b/VANDAMME23.c @@ -1,232 +1,232 @@ -#include -#include -#include -#include -#include -#define __TVA__ 1.21 -#define __REDUC__ 0.9 -#define __MAXNBRART__ 3 - -#define __STRLEN__ 34 - -typedef struct { - char deisgnation[__STRLEN__]; - float prixHTVA; - int quant; -} Article; -typedef struct { - Article * article; - unsigned int nbrArt; -} Panier; - - - - -void EncoderDate(int*, int*, int*); -int DateValide (int, int, int); -void afficherArticle(Article * article, unsigned int nbrArt, FILE * file); -void encoderArticle(Article * article); - -int main() -{ - int j,m,a; - char continuer = 'y'; - FILE * file; - file = fopen("fact.txt","w"); - if(file == NULL) - { - printf("Erreur lors de l'ouvertur !\n"); - return -1; - } - - Panier panier; - panier.article = (Article *)malloc(sizeof(Article)); - panier.nbrArt = 1; - if(panier.article == NULL) - { - printf("ERREUR ALLOCATION !"); - free(panier.article); - return -1; - } - - do - { - EncoderDate(&j,&m,&a); - } - while (!DateValide(j, m, a)); - - do - { - if(panier.nbrArt <= __MAXNBRART__) - { - encoderArticle(&(panier.article[panier.nbrArt-1])); - printf("Y-a-t-il encore un article ?(Y|n)"); - fflush(stdin); - scanf("%c", &continuer); - if(panier.nbrArt < 3 && (continuer|0b00100000) == 'y') - { - panier.nbrArt++; - Article * tempArticle; - tempArticle = (Article*)realloc(panier.article, sizeof(Article)*(panier.nbrArt)); - if(panier.article == NULL) - { - printf("ERREUR ALLOCATION !"); - free(tempArticle); - free(panier.article); - return -1; - } - else - { - panier.article = tempArticle; - } - } - else - { - system("cls"); - printf("Vous avez ateint le nombre d'article maximum !\n\n"); - break; - } - } - }while((continuer|0b00100000) == 'y'); - //En t�te de la facture - printf("La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n"); - printf("\nFacture a payer\n"); - printf("Date de facturation :"); - - fprintf(file,"La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n"); - fprintf(file,"\nFacture a payer\n"); - fprintf(file,"Date de facturation :"); - if (j<10) - { - if (m<10) - { - printf("0%d/0%d/%d", j, m, a); - fprintf(file,"0%d/0%d/%d", j, m, a); - } - else - { - printf("0%d/%d/%d", j, m, a); - fprintf(file,"0%d/%d/%d", j, m, a); - } - } - else - { - if (m<10) - { - printf("%d/0%d/%d", j, m, a); - fprintf(file,"%d/0%d/%d", j, m, a); - } - else - { - printf("%d/%d/%d", j, m, a); - fprintf(file,"%d/%d/%d", j, m, a); - } - } - printf("%u\n", panier.nbrArt); - afficherArticle(panier.article,panier.nbrArt, file); - getch(); - fclose(file); - free(panier.article); - return 0; -} -void EncoderDate(int *j, int *m, int *a) -{ - printf("Entrez la date sous cette forme : jj/mm/aaaa\n"); - fflush(stdin); scanf("%d/%d/%d",j,m,a); -} - -int DateValide(int j, int m, int a) -{ - int bis; - if(m != 2) - { - if(m >= 1 && m <= 7) - { - if(m %2 == 0) - { - if(j >= 1 && j <= 30) return 1; - else return 0; - } - else - { - if(j >= 1 && j <= 31) return 1; - else return 0; - } - } - else if(m > 7 && m <= 12) - { - if(m %2 == 0) - { - if(j >= 1 && j <= 31) return 1; - else return 0; - } - else - { - if(j >= 1 && j <= 30) return 1; - else return 0; - } - } - else return 0; - } - else - { - if(a %100 == 0) - { - if(a %400 == 0) bis = 1; - else bis = 0; - } - else - { - if(a %4 == 0)bis = 1; - else bis = 0; - } - if(bis == 1) - { - if(j >= 1 && j <= 29) return 1; - else return 0; - } - else - { - if(j >= 1 && j <= 28) return 1; - else return 0; - } - } -} - -void afficherArticle(Article * article, unsigned int nbrArt,FILE * file) -{ - unsigned int i; - float prixTot=0; - fprintf(file,"\n|---------------------------------------------------------------------------------------------|\ - \n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |"); - printf("\n|---------------------------------------------------------------------------------------------|\ - \n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |"); - for(i=0;i=20)?'x':' ',\ - (article[i].quant>=20)?article[i].prixHTVA*__TVA__*__REDUC__*article[i].quant:article[i].prixHTVA*__TVA__*article[i].quant); - fprintf(file,"\n|%34s|%12.2f Eur |%14d| %c |%12.2f |",\ - article[i].deisgnation,article[i].prixHTVA,article[i].quant\ - ,(article[i].quant>=20)?'x':' ',\ - (article[i].quant>=20)?article[i].prixHTVA*__TVA__*__REDUC__*article[i].quant:article[i].prixHTVA*__TVA__*article[i].quant); - - prixTot += (article[i].quant>=20)?article[i].prixHTVA*__TVA__*__REDUC__*article[i].quant:article[i].prixHTVA*__TVA__*article[i].quant; - } - printf("\n|---------------------------------------------------------------------------------------------|"); - printf("\nPrix totale :%f", prixTot); - - fprintf(file,"\n|---------------------------------------------------------------------------------------------|"); - fprintf(file,"\nPrix totale :%f", prixTot); -} -void encoderArticle(Article * article) -{ - printf("\nVeuillez entrer le nom : "); - scanf("%34s", article->deisgnation); - printf("\nVeuillez entrer le prix a l'unite hors TVA : "); - scanf("%f", &article->prixHTVA); - printf("\nVeuillez entrer la quantite desiree : "); - fflush(stdin); - scanf("%d", &article->quant); -} +#include +#include +#include +#include +#include +#define __TVA__ 1.21 +#define __REDUC__ 0.9 +#define __MAXNBRART__ 3 + +#define __STRLEN__ 34 + +typedef struct { + char deisgnation[__STRLEN__]; + float prixHTVA; + int quant; +} Article; +typedef struct { + Article * article; + unsigned int nbrArt; +} Panier; + + + + +void EncoderDate(int*, int*, int*); +int DateValide (int, int, int); +void afficherArticle(Article * article, unsigned int nbrArt, FILE * file); +void encoderArticle(Article * article); + +int main() +{ + int j,m,a; + char continuer = 'y'; + FILE * file; + file = fopen("fact.txt","w"); + if(file == NULL) + { + printf("Erreur lors de l'ouvertur !\n"); + return -1; + } + + Panier panier; + panier.article = (Article *)malloc(sizeof(Article)); + panier.nbrArt = 1; + if(panier.article == NULL) + { + printf("ERREUR ALLOCATION !"); + free(panier.article); + return -1; + } + + do + { + EncoderDate(&j,&m,&a); + } + while (!DateValide(j, m, a)); + + do + { + if(panier.nbrArt <= __MAXNBRART__) + { + encoderArticle(&(panier.article[panier.nbrArt-1])); + printf("Y-a-t-il encore un article ?(Y|n)"); + fflush(stdin); + scanf("%c", &continuer); + if(panier.nbrArt < 3 && (continuer|0b00100000) == 'y') + { + panier.nbrArt++; + Article * tempArticle; + tempArticle = (Article*)realloc(panier.article, sizeof(Article)*(panier.nbrArt)); + if(panier.article == NULL) + { + printf("ERREUR ALLOCATION !"); + free(tempArticle); + free(panier.article); + return -1; + } + else + { + panier.article = tempArticle; + } + } + else + { + system("cls"); + printf("Vous avez ateint le nombre d'article maximum !\n\n"); + break; + } + } + }while((continuer|0b00100000) == 'y'); + //En t�te de la facture + printf("La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n"); + printf("\nFacture a payer\n"); + printf("Date de facturation :"); + + fprintf(file,"La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n"); + fprintf(file,"\nFacture a payer\n"); + fprintf(file,"Date de facturation :"); + if (j<10) + { + if (m<10) + { + printf("0%d/0%d/%d", j, m, a); + fprintf(file,"0%d/0%d/%d", j, m, a); + } + else + { + printf("0%d/%d/%d", j, m, a); + fprintf(file,"0%d/%d/%d", j, m, a); + } + } + else + { + if (m<10) + { + printf("%d/0%d/%d", j, m, a); + fprintf(file,"%d/0%d/%d", j, m, a); + } + else + { + printf("%d/%d/%d", j, m, a); + fprintf(file,"%d/%d/%d", j, m, a); + } + } + printf("%u\n", panier.nbrArt); + afficherArticle(panier.article,panier.nbrArt, file); + getch(); + fclose(file); + free(panier.article); + return 0; +} +void EncoderDate(int *j, int *m, int *a) +{ + printf("Entrez la date sous cette forme : jj/mm/aaaa\n"); + fflush(stdin); scanf("%d/%d/%d",j,m,a); +} + +int DateValide(int j, int m, int a) +{ + int bis; + if(m != 2) + { + if(m >= 1 && m <= 7) + { + if(m %2 == 0) + { + if(j >= 1 && j <= 30) return 1; + else return 0; + } + else + { + if(j >= 1 && j <= 31) return 1; + else return 0; + } + } + else if(m > 7 && m <= 12) + { + if(m %2 == 0) + { + if(j >= 1 && j <= 31) return 1; + else return 0; + } + else + { + if(j >= 1 && j <= 30) return 1; + else return 0; + } + } + else return 0; + } + else + { + if(a %100 == 0) + { + if(a %400 == 0) bis = 1; + else bis = 0; + } + else + { + if(a %4 == 0)bis = 1; + else bis = 0; + } + if(bis == 1) + { + if(j >= 1 && j <= 29) return 1; + else return 0; + } + else + { + if(j >= 1 && j <= 28) return 1; + else return 0; + } + } +} + +void afficherArticle(Article * article, unsigned int nbrArt,FILE * file) +{ + unsigned int i; + float prixTot=0; + fprintf(file,"\n|---------------------------------------------------------------------------------------------|\ + \n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |"); + printf("\n|---------------------------------------------------------------------------------------------|\ + \n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |"); + for(i=0;i=20)?'x':' ',\ + (article[i].quant>=20)?article[i].prixHTVA*__TVA__*__REDUC__*article[i].quant:article[i].prixHTVA*__TVA__*article[i].quant); + fprintf(file,"\n|%34s|%12.2f Eur |%14d| %c |%12.2f |",\ + article[i].deisgnation,article[i].prixHTVA,article[i].quant\ + ,(article[i].quant>=20)?'x':' ',\ + (article[i].quant>=20)?article[i].prixHTVA*__TVA__*__REDUC__*article[i].quant:article[i].prixHTVA*__TVA__*article[i].quant); + + prixTot += (article[i].quant>=20)?article[i].prixHTVA*__TVA__*__REDUC__*article[i].quant:article[i].prixHTVA*__TVA__*article[i].quant; + } + printf("\n|---------------------------------------------------------------------------------------------|"); + printf("\nPrix totale :%f", prixTot); + + fprintf(file,"\n|---------------------------------------------------------------------------------------------|"); + fprintf(file,"\nPrix totale :%f", prixTot); +} +void encoderArticle(Article * article) +{ + printf("\nVeuillez entrer le nom : "); + scanf("%34s", article->deisgnation); + printf("\nVeuillez entrer le prix a l'unite hors TVA : "); + scanf("%f", &article->prixHTVA); + printf("\nVeuillez entrer la quantite desiree : "); + fflush(stdin); + scanf("%d", &article->quant); +} diff --git a/VANDAMME24.c b/VANDAMME24.c index a25d27d..2b62c87 100644 --- a/VANDAMME24.c +++ b/VANDAMME24.c @@ -1,429 +1,484 @@ -#include -#include -#include -#include -#include - - -#define __TVA__ 1.21 -#define __REDUC__ 0.9 -#define __MAXNBRART__ 3 - -#define __STRLEN__ 34 - -typedef enum{FALSE,TRUE} Bool; -typedef struct { - char deisgnation[__STRLEN__]; - float prixHTVA; - int quant; -} Article; -typedef struct { - Article * article; - unsigned int nbrArt; -} Panier; -typedef struct{ - int jour,moi,annee; -} Date; -typedef struct{ - char rue[__STRLEN__],numero[__STRLEN__],localite[__STRLEN__]; - int codePostal; -} Adresse; -typedef struct{ - char telephone[13],email[__STRLEN__]; -} Contact; -typedef struct{ - char nom[__STRLEN__]; - Adresse adresse; - Contact contact; - Date anniversaire; - Panier panier; -} Client; - - - - -void encoderDate(Date *); -Bool dateValide (Date *); -void encoderArticle(Article *); -void encoderClient(Client *); -void sauvegarderClient(Client *, FILE *); -void afficherClient(Client *); -void encoderFacture(Panier *); -FILE * creerFichier(Date *, Client *); -Bool fichierExistant(char *); -void sauvergarderFacture(FILE *, Date *, Client *); -void afficherFacture(Date *, Client *); -void cleanFgets(char*); -int itoaY(int i, char*); -int itoaDM(int i, char*); - - -int main() -{ - Date date; - FILE * file; - Client client; - do - encoderDate(&date); - while(!dateValide(&date)); - - encoderClient(&client); - afficherClient(&client); - - file = creerFichier(&date, &client); - - client.panier.article = (Article *)malloc(sizeof(Article)); - client.panier.nbrArt = 1; - if(client.panier.article == NULL) - { - printf("ERREUR ALLOCATION ARTICLE!"); - free(client.panier.article); - return -1; - } - - encoderFacture(&client.panier); - afficherFacture(&date, &client); - sauvergarderFacture(file, &date, &client); - getch(); - fclose(file); - free(client.panier.article); - return 0; -} -void encoderDate(Date * date) -{ - printf("Entrez la date sous cette forme : jj/mm/aaaa\n"); - fflush(stdin); scanf("%d/%d/%d",&(date->jour),&(date->moi),&(date->annee)); -} - -Bool dateValide(Date * date) -{ - int j = date->jour; - int m = date->moi; - int a = date->annee; - int bis; - if(m != 2) - { - if(m >= 1 && m <= 7) - { - if(m %2 == 0) - { - if(j >= 1 && j <= 30) return TRUE; - else return FALSE; - } - else - { - if(j >= 1 && j <= 31) return TRUE; - else return FALSE; - } - } - else if(m > 7 && m <= 12) - { - if(m %2 == 0) - { - if(j >= 1 && j <= 31) return TRUE; - else return FALSE; - } - else - { - if(j >= 1 && j <= 30) return TRUE; - else return FALSE; - } - } - else return FALSE; - } - else - { - if(a %100 == 0) - { - if(a %400 == 0) bis = 1; - else bis = FALSE; - } - else - { - if(a %4 == 0)bis = 1; - else bis = FALSE; - } - if(bis == 1) - { - if(j >= 1 && j <= 29) return TRUE; - else return FALSE; - } - else - { - if(j >= 1 && j <= 28) return TRUE; - else return FALSE; - } - } -} - -void encoderArticle(Article * article) -{ - printf("\nVeuillez entrer le nom : "); - scanf("%34s", article->deisgnation); - printf("\nVeuillez entrer le prix a l'unite hors TVA : "); - scanf("%f", &article->prixHTVA); - printf("\nVeuillez entrer la quantite desiree : "); - fflush(stdin); - scanf("%d", &article->quant); -} - -void encoderClient(Client * client) -{ - printf("Encoage Client\n"); - fflush(stdin); - if(!(printf("Entrez la rue :") && !fflush(stdin) && fgets(client->adresse.rue,__STRLEN__,stdin) != NULL && \ - printf("\nEntrez le numero :" ) && !fflush(stdin) && fgets(client->adresse.numero,__STRLEN__,stdin) != NULL && \ - printf("\nEntrez la localité :") && !fflush(stdin) && fgets(client->adresse.localite,__STRLEN__,stdin) != NULL && \ - printf("\nEntrez le code postal :") && !fflush(stdin) && scanf("%d", &(client->adresse.codePostal)) && \ - printf("\nNom client :") && !fflush(stdin) && fgets(client->nom,__STRLEN__,stdin) != NULL)) - { - printf("\nErreur lors de l'encodage de l'adresse"); - exit(-1); - } - cleanFgets(client->adresse.rue);cleanFgets(client->adresse.numero);cleanFgets(client->adresse.localite); - cleanFgets(client->nom); - if(!(printf("\n Entrez le numéro de tél. :") && !fflush(stdin) &&fgets(client->contact.telephone,13,stdin) && \ - printf("\nEntrez l'adresse email :") && !fflush(stdin) &&fgets(client->contact.email,__STRLEN__,stdin))) - { - printf("\nErreur lors de l'encodage des coo de contact"); - exit(-1); - } - cleanFgets(client->contact.telephone);cleanFgets(client->contact.email); - printf("\n Anniversaire client :"); - do - encoderDate(&(client->anniversaire)); - while(!dateValide(&(client->anniversaire))); -} -void afficherClient(Client *client) -{ - printf("Client : %s\n", client->nom); - printf("rue : %s",client->adresse.rue); - printf("numero : %s",client->adresse.numero); - printf("localité : %s",client->adresse.localite); - printf("code postal : %d",client->adresse.codePostal); - printf("numéro de tél. : %s",client->contact.telephone); - printf("adresse email : %s",client->contact.email); -} -void sauvegarderClient(Client *client, FILE * file) -{ - fprintf(file, "Client : %s\n", client->nom); - fprintf(file, "rue : %s",client->adresse.rue); - fprintf(file, "numero : %s",client->adresse.numero); - fprintf(file, "localité : %s",client->adresse.localite); - fprintf(file, "code postal : %d",client->adresse.codePostal); - fprintf(file, "numéro de tél. : %s",client->contact.telephone); - fprintf(file, "adresse email : %s",client->contact.email); -} -void encoderFacture(Panier * panier) -{ - char continuer = 'y'; - do{ - if(panier->nbrArt <= __MAXNBRART__) - { - encoderArticle(&(panier->article[panier->nbrArt-1])); - printf("Y-a-t-il encore un article ?(Y|n)"); - fflush(stdin); - scanf("%c", &continuer); - if(panier->nbrArt < __MAXNBRART__ && (continuer|0b00100000) == 'y') - { - panier->nbrArt++; - Article * tempArticle; - tempArticle = (Article*)realloc(panier->article, sizeof(Article)*(panier->nbrArt)); - if(panier->article == NULL) - { - printf("ERREUR ALLOCATION !"); - free(tempArticle); - free(panier->article); - exit(-1); - } - else - { - panier->article = tempArticle; - } - } - else if((continuer|0b00100000) == 'y') - { - system("cls"); - printf("Vous avez ateint le nombre d'article maximum !\n\n"); - break; - } - } - }while((continuer|0b00100000) == 'y' && panier->nbrArt <= __MAXNBRART__); -} -FILE * creerFichier(Date * date, Client * client) -{ - char fileName[__STRLEN__*+16]; - fileName[0] = '\0'; - int i; - char buf[5]; - - //Toute cette partie aurais pus être remplacé par un sprintf - strcat(fileName,client->nom); - itoaY(date->annee, buf); - strcat(fileName,buf); - itoaDM(date->moi, buf); - strcat(fileName, buf); - itoaDM(date->jour, buf); - strcat(fileName, buf); - strcat(fileName,"_"); - - - for(i=1; i<= 99; i++)//Le caractère 10 n'existe pas, flem de coder pour avoir plus que 9 et aloc dynamique nécessaire - { - char fileNameTmp[__STRLEN__*+16]; - sprintf(fileNameTmp,"%s%d",fileName,i); - if(!fichierExistant(fileNameTmp)) - { - printf("%s\n", fileNameTmp); - FILE * f = fopen(fileNameTmp,"w"); - if(f==NULL) - { - printf("Erreur lors de l'ouverture du fichier"); - exit(-1); - } - else - return f; - } - } - return NULL; -} -Bool fichierExistant(char * filename) -{ - FILE * f = fopen(filename, "r"); - if(f==NULL) - return FALSE; - else - return TRUE; -} -void sauvergarderFacture(FILE * file, Date * date, Client * client) -{ - int i; - float prixTot = 0; - fprintf(file,"La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n"); - fprintf(file,"\nFacture a payer\n"); - fprintf(file,"Date de facturation :"); - fprintf(file,"%02d/%02d/%02d", date->jour, date->moi, date->annee); - fprintf(file, "\n Info client :"); - sauvegarderClient(&client, file) - fprintf(file,"\n|---------------------------------------------------------------------------------------------|\ - \n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |\ - \n|---------------------------------------------------------------------------------------------|"); - - for(i=0;client->panier.nbrArt>i;i++) - { - fprintf(file,"\n|%34s|%12.2f Eur |%14d| %c |%12.2f |",\ - client->panier.article[i].deisgnation,client->panier.article[i].prixHTVA,client->panier.article[i].quant\ - ,(client->panier.article[i].quant>=20)?'x':' ',\ - (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant); - prixTot += (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant; - } - fprintf(file,"\n|---------------------------------------------------------------------------------------------|"); - fprintf(file,"\nPrix totale :%f", prixTot); -} - -void afficherFacture(Date * date, Client * client) -{ - int i; - float prixTot = 0; - printf("La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n"); - printf("\nFacture a payer\n"); - printf("Date de facturation :"); - printf("%02d/%02d/%02d", date->jour, date->moi, date->annee); - printf("\n Info client :"); - afficherClient(client); - printf("\n|---------------------------------------------------------------------------------------------|\ - \n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |\ - \n|---------------------------------------------------------------------------------------------|"); - - for(i=0;client->panier.nbrArt>i;i++) - { - printf("\n|%34s|%12.2f Eur |%14d| %c |%12.2f |",\ - client->panier.article[i].deisgnation,client->panier.article[i].prixHTVA,client->panier.article[i].quant\ - ,(client->panier.article[i].quant>=20)?'x':' ',\ - (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant); - prixTot += (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant; - } - printf("\n|---------------------------------------------------------------------------------------------|"); - printf("\nPrix totale :%f", prixTot); -} - - -void cleanFgets(char * str) -{ - char *p = strchr(str, '\n'); - if(p!=NULL) - *p = '\0'; - else - { - printf("Une erreur est arrivé lors du nettoygae \\0"); - exit(-1); - } -} -int itoaY(int i, char * buf) -{ - buf [0] = '0'; - buf [1] = '0'; - buf [2] = '0'; - buf [3] = '0'; - buf [4] = '\0'; - int j; - if(!i) - return 1; - buf [3] = '1'; - for(j=1; j<=i && j<=9999 ; j++) - { - if(!(j%1000)) - { - buf[0]++; - buf[1]='0'; - buf[2]='0'; - buf[3]='0'; - } - else if(!(j%100)) - { - buf[1]++; - buf[2]='0'; - buf[3]='0'; - } - else if(!(j%10)) - { - buf[2]++; - buf[3]='0'; - } - else - { - buf[3]++; - } - } - if(j>9999) - return 0; - else - return 1; -} -int itoaDM(int i, char * buf) -{ - buf[0] = '0'; - buf[1] = '0'; - buf[2] = '\0'; - printf("%s\n", buf); - int j; - if(!i) - return 1; - buf[1]++; - for(j=1; j<=i && j<=99 ; j++) - { - if(!(j%10)) - { - (buf[0])++; - (buf[1])='0'; - } - else - { - (buf[1])++; - } - } - if(j>99) - return 0; - else - return 1; -} +#include +#include +#include +#include +#include +#include +#include + +#define __TVA__ 1.21 +#define __REDUC__ 0.9 +#define __MAXNBRART__ 3 + +#define __STRLEN__ 34 + +typedef enum{FALSE,TRUE} Bool; +typedef struct { + char deisgnation[__STRLEN__]; + float prixHTVA; + int quant; +} Article; +typedef struct { + Article * article; + unsigned int nbrArt; +} Panier; +typedef struct{ + int jour,moi,annee; +} Date; +typedef struct{ + char rue[__STRLEN__],numero[__STRLEN__],localite[__STRLEN__]; + int codePostal; +} Adresse; +typedef struct{ + char telephone[13],email[__STRLEN__]; +} Contact; +typedef struct{ + char nom[__STRLEN__]; + Adresse adresse; + Contact contact; + Date anniversaire; + int fidelite; + Panier panier; +} Client; + + + + +void encoderDate(Date *, char *); +Bool dateValide (Date *); +void encoderArticle(Article *); +void encoderClient(Client *); +void sauvegarderClient(Client *, FILE *, Date*); +void afficherClient(Client *, Date*); +void encoderFacture(Panier *); +FILE * creerFichier(Date *, Client *); +Bool fichierExistant(char *); +void sauvergarderFacture(FILE *, Date *, Client *); +void afficherFacture(Date *, Client *); +void cleanFgets(char*); +int itoaY(int i, char*); +int itoaDM(int i, char*); +Bool clean_keyboard(); +int ageClient(Client *, Date *); +int pointsFidelite(float); + + +int main() +{ + //printf("%d\n", pointsFidelite(52.23)); + Date date; + FILE * file; + Client client; + char tmp; + time_t curTimeStamp = time(NULL); + struct tm *locTime = localtime(&curTimeStamp); + locTime->tm_mon += 1; + locTime->tm_year += 1900; + printf("Voulez utilisez le temps système %d/%d/%d (Y|n)?\n", locTime->tm_mday,locTime->tm_mon,locTime->tm_year); + scanf("%c", &tmp); + if((tmp|0b00100000) != 'y') + encoderDate(&date, "Date facturation"); + else + { + date.jour = locTime->tm_mday; + date.moi = locTime->tm_mon; + date.annee = locTime->tm_year; + // printf("%d/%d/%d\n", date.jour, date.moi, date.annee ); + } + + encoderClient(&client); + afficherClient(&client, &date); +printf("%d/%d/%d\n", date.jour, date.moi, date.annee ); + file = creerFichier(&date, &client); + + client.panier.article = (Article *)malloc(sizeof(Article)); + client.panier.nbrArt = 1; + if(client.panier.article == NULL) + { + printf("ERREUR ALLOCATION ARTICLE!"); + free(client.panier.article); + return -1; + } + + encoderFacture(&client.panier); + afficherFacture(&date, &client); + sauvergarderFacture(file, &date, &client); + // getch(); + fclose(file); + free(client.panier.article); + return 0; +} +void encoderDate(Date * date, char invite[__STRLEN__]) +{ + do { + printf("%s\n", invite); + printf("Entrez la date sous cette forme : jj/mm/aaaa\n"); + scanf("%d/%d/%d",&(date->jour),&(date->moi),&(date->annee)); + } while(!dateValide(date)); +} + +Bool dateValide(Date * date) +{ + int j = date->jour; + int m = date->moi; + int a = date->annee; + int bis; + if(m != 2) + { + if(m >= 1 && m <= 7) + { + if(m %2 == 0) + { + if(j >= 1 && j <= 30) return TRUE; + else return FALSE; + } + else + { + if(j >= 1 && j <= 31) return TRUE; + else return FALSE; + } + } + else if(m > 7 && m <= 12) + { + if(m %2 == 0) + { + if(j >= 1 && j <= 31) return TRUE; + else return FALSE; + } + else + { + if(j >= 1 && j <= 30) return TRUE; + else return FALSE; + } + } + else return FALSE; + } + else + { + if(a %100 == 0) + { + if(a %400 == 0) bis = 1; + else bis = FALSE; + } + else + { + if(a %4 == 0)bis = 1; + else bis = FALSE; + } + if(bis == 1) + { + if(j >= 1 && j <= 29) return TRUE; + else return FALSE; + } + else + { + if(j >= 1 && j <= 28) return TRUE; + else return FALSE; + } + } +} + +void encoderArticle(Article * article) +{ + printf("\nVeuillez entrer le nom : "); + clean_keyboard(); + scanf("%34s", article->deisgnation); + printf("\nVeuillez entrer le prix a l'unite hors TVA : "); + clean_keyboard(); + scanf("%f", &article->prixHTVA); + printf("\nVeuillez entrer la quantite desiree : "); + clean_keyboard(); + scanf("%d", &article->quant); +} + +void encoderClient(Client * client) +{ + printf("Encoage Client\n"); + client->fidelite = 0; + if(!(printf("Entrez la rue :") && clean_keyboard() && fgets(client->adresse.rue,__STRLEN__,stdin) != NULL && \ + printf("\nEntrez le numero :" ) && clean_keyboard() && fgets(client->adresse.numero,__STRLEN__,stdin) != NULL && \ + printf("\nEntrez la localité :") && clean_keyboard() && fgets(client->adresse.localite,__STRLEN__,stdin) != NULL && \ + printf("\nEntrez le code postal :") && clean_keyboard() && scanf("%d", &(client->adresse.codePostal)) && \ + printf("\nNom client :") && clean_keyboard() && fgets(client->nom,__STRLEN__,stdin) != NULL)) + { + printf("\nErreur lors de l'encodage de l'adresse"); + exit(-1); + } + cleanFgets(client->adresse.rue);cleanFgets(client->adresse.numero);cleanFgets(client->adresse.localite); + cleanFgets(client->nom); + if(!(printf("\n Entrez le numéro de tél. :") && clean_keyboard() &&fgets(client->contact.telephone,13,stdin) && \ + printf("\nEntrez l'adresse email :") && clean_keyboard() &&fgets(client->contact.email,__STRLEN__,stdin))) + { + printf("\nErreur lors de l'encodage des coo de contact"); + exit(-1); + } + cleanFgets(client->contact.telephone);cleanFgets(client->contact.email); + encoderDate(&(client->anniversaire), "\nAnniversaire client:"); +} +void afficherClient(Client *client, Date *date) +{ + printf("Client : %s (%d)\n", client->nom, ageClient(client, date)); + printf("rue : %s\n",client->adresse.rue); + printf("numero : %s\n",client->adresse.numero); + printf("localité : %s\n",client->adresse.localite); + printf("code postal : %d\n",client->adresse.codePostal); + printf("numéro de tél. : %s\n",client->contact.telephone); + printf("adresse email : %s\n",client->contact.email); + printf("\nPoints de fidelite aqui : %d\n", client->fidelite); +} +void sauvegarderClient(Client *client, FILE * file, Date *date) +{ + fprintf(file, "Client : %s (%d)\n", client->nom, ageClient(client, date)); + fprintf(file, "rue : %s\n",client->adresse.rue); + fprintf(file, "numero : %s\n",client->adresse.numero); + fprintf(file, "localité : %s\n",client->adresse.localite); + fprintf(file, "code postal : %d\n",client->adresse.codePostal); + fprintf(file, "numéro de tél. : %s\n",client->contact.telephone); + fprintf(file, "adresse email : %s\n",client->contact.email); + fprintf(file, "\nPoints de fidelite aqui : %d\n", client->fidelite); +} +void encoderFacture(Panier * panier) +{ + char continuer = 'y'; + do{ + if(panier->nbrArt <= __MAXNBRART__) + { + encoderArticle(&(panier->article[panier->nbrArt-1])); + printf("Y-a-t-il encore un article ?(Y|n)"); + clean_keyboard(); + scanf("%c", &continuer); + if(panier->nbrArt < __MAXNBRART__ && (continuer|0b00100000) == 'y') + { + panier->nbrArt++; + Article * tempArticle; + tempArticle = (Article*)realloc(panier->article, sizeof(Article)*(panier->nbrArt)); + if(panier->article == NULL) + { + printf("ERREUR ALLOCATION !"); + free(tempArticle); + free(panier->article); + exit(-1); + } + else + { + panier->article = tempArticle; + } + } + else if((continuer|0b00100000) == 'y') + { + system("cls"); + printf("Vous avez ateint le nombre d'article maximum !\n\n"); + break; + } + } + }while((continuer|0b00100000) == 'y' && panier->nbrArt <= __MAXNBRART__); +} +FILE * creerFichier(Date * date, Client * client) +{ + char fileName[__STRLEN__+16]; + fileName[0] = '\0'; + char dir[__STRLEN__]; + int i; + char buf[5]; + printf("Dossier d'enregistrement : "); + clean_keyboard(); + scanf("%s", dir); + //Toute cette partie aurais pus être remplacé par un sprintf + strcat(fileName,client->nom); + itoaY(date->annee, buf); + strcat(fileName,buf); + itoaDM(date->moi, buf); + strcat(fileName, buf); + itoaDM(date->jour, buf); + strcat(fileName, buf); + strcat(fileName,"_"); + + + for(i=1; i<= 99; i++) + { + char fileNameTmp[__STRLEN__+16+255]; + sprintf(fileNameTmp,"%s%s%d.txt",dir,fileName,i); + if(!fichierExistant(fileNameTmp)) + { + FILE * f = fopen(fileNameTmp,"w"); + if(f==NULL) + { + printf("Erreur lors de l'ouverture du fichier"); + return creerFichier(date, client); + } + else + return f; + } + } + return NULL; +} +Bool fichierExistant(char * filename) +{ + FILE * f = fopen(filename, "r"); + if(f==NULL) + return FALSE; + else + return TRUE; +} +void sauvergarderFacture(FILE * file, Date * date, Client * client) +{ + int i; + float prixTot = 0; + fprintf(file,"La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n"); + fprintf(file,"\nFacture a payer\n"); + fprintf(file,"Date de facturation :"); + fprintf(file,"%02d/%02d/%02d", date->jour, date->moi, date->annee); + fprintf(file, "\n Info client :"); + sauvegarderClient(client, file, date); + fprintf(file,"\n|---------------------------------------------------------------------------------------------|\ + \n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |\ + \n|---------------------------------------------------------------------------------------------|"); + + for(i=0;client->panier.nbrArt>i;i++) + { + fprintf(file,"\n|%34s|%12.2f Eur |%14d| %c |%12.2f |",\ + client->panier.article[i].deisgnation,client->panier.article[i].prixHTVA,client->panier.article[i].quant\ + ,(client->panier.article[i].quant>=20)?'x':' ',\ + (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant); + prixTot += (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant; + } + fprintf(file,"\n|---------------------------------------------------------------------------------------------|"); + fprintf(file,"\nPrix totale :%f", prixTot); + fprintf(file, "\nPoints de fidelite aqui : %d\n", client->fidelite); +} + +void afficherFacture(Date * date, Client * client) +{ + int i; + float prixTot = 0; + printf("La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n"); + printf("\nFacture a payer\n"); + printf("Date de facturation :"); + printf("%02d/%02d/%02d", date->jour, date->moi, date->annee); + printf("\n Info client :"); + afficherClient(client, date); + printf("\n|---------------------------------------------------------------------------------------------|\ + \n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |\ + \n|---------------------------------------------------------------------------------------------|"); + + for(i=0;client->panier.nbrArt>i;i++) + { + printf("\n|%34s|%12.2f Eur |%14d| %c |%12.2f |",\ + client->panier.article[i].deisgnation,client->panier.article[i].prixHTVA,client->panier.article[i].quant\ + ,(client->panier.article[i].quant>=20)?'x':' ',\ + (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant); + prixTot += (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant; + } + printf("\n|---------------------------------------------------------------------------------------------|"); + client->fidelite = pointsFidelite(prixTot); + printf("\nPrix totale :%f", prixTot); + printf("\nPoints de fidelite aqui : %d\n", client->fidelite); + +} + + +void cleanFgets(char * str) +{ + char *p = strchr(str, '\n'); + if(p!=NULL) + *p = '\0'; + else + { + printf("Une erreur est arrivé lors du nettoygae \\0"); + exit(-1); + } +} +int itoaY(int i, char * buf) +{ + buf [0] = '0'; + buf [1] = '0'; + buf [2] = '0'; + buf [3] = '0'; + buf [4] = '\0'; + int j; + if(!i) + return 1; + buf [3] = '1'; + for(j=1; j<=i && j<=9999 ; j++) + { + if(!(j%1000)) + { + buf[0]++; + buf[1]='0'; + buf[2]='0'; + buf[3]='0'; + } + else if(!(j%100)) + { + buf[1]++; + buf[2]='0'; + buf[3]='0'; + } + else if(!(j%10)) + { + buf[2]++; + buf[3]='0'; + } + else + { + buf[3]++; + } + } + if(j>9999) + return 0; + else + return 1; +} +int itoaDM(int i, char * buf) +{ + buf[0] = '0'; + buf[1] = '0'; + buf[2] = '\0'; + int j; + if(!i) + return 1; + buf[1]++; + for(j=1; j<=i && j<=99 ; j++) + { + if(!(j%10)) + { + (buf[0])++; + (buf[1])='0'; + } + else + { + (buf[1])++; + } + } + if(j>99) + return 0; + else + return 1; +} + +Bool clean_keyboard() +{ + fflush(stdin); + // char c; +//while ((c = getchar()) != '\n' && c != EOF) { } + /* do { + c = getc(stdin); + printf("%c\n", c); + } while (c != '\n' && c != EOF);*/ + return 1; +} + +int ageClient(Client * client, Date * date) +{ + if((date->moi == client->anniversaire.moi && date->jour >= client->anniversaire.jour) || (date->moi > client->anniversaire.moi))//anniversaire passé + { + return (date->annee - client->anniversaire.annee); + } + else + return (date->annee - client->anniversaire.annee - 1); +} + +int pointsFidelite(float prix) +{ + return (int)(prix/10); +} diff --git a/VANDAMME27.c b/VANDAMME27.c new file mode 100644 index 0000000..12052b1 --- /dev/null +++ b/VANDAMME27.c @@ -0,0 +1,618 @@ +#include +#include +#include +#include +#include +#include +#include + +#define __TVA__ 1.21 +#define __REDUC__ 0.9 +#define __MAXNBRART__ 3 + +#define __STRLEN__ 34 +#define __STRLEN_FILE__ 500 + +typedef enum{FALSE,TRUE} Bool; +typedef struct { + char deisgnation[__STRLEN__]; + float prixHTVA; + int quant; +} Article; +typedef struct { + Article * article; + unsigned int nbrArt; +} Panier; +typedef struct{ + int jour,moi,annee; +} Date; +typedef struct{ + char rue[__STRLEN__],numero[__STRLEN__],localite[__STRLEN__]; + int codePostal; +} Adresse; +typedef struct{ + char telephone[13],email[__STRLEN__]; +} Contact; +typedef struct{ + char nom[__STRLEN__]; + Adresse adresse; + Contact contact; + Date anniversaire; + int fidelite; + Panier panier; +} Client; + + + + +void encoderDate(Date *, char *); +Bool dateValide (Date *); +void encoderArticle(Article *); +void encoderClient(Client *); +void sauvegarderClient(Client *, FILE *, Date*); +void afficherClient(Client *, Date *); +void encoderFacture(Panier *); +FILE * creerFichier(Date *, Client *); +Bool fichierExistant(char *); +void sauvergarderFacture(FILE *, Date *, Client *); +void afficherFacture(Date *, Client *); +void cleanFgets(char*); +int itoaY(int i, char*); +int itoaDM(int i, char*); +Bool clean_keyboard(); +int ageClient(Client *, Date *); +int pointsFidelite(float); +void gestionFacture(Client *, Date *); +Client * rechercheClient(char *, FILE *, Date *); +Bool gestionClient(Client *, Date *); +FILE * localiserFichierClients(char *); +int ajouterClientBin(FILE *, Client * client); + +int main() +{ + //printf("%d\n", pointsFidelite(52.23)); + FILE * clientF; + Date date; + char tmp; + Bool w; + time_t curTimeStamp = time(NULL); + struct tm *locTime = localtime(&curTimeStamp); + locTime->tm_mon += 1; + locTime->tm_year += 1900; + printf("Voulez-vous utilisez la date système %d/%d/%d (Y|n)?\n", locTime->tm_mday,locTime->tm_mon,locTime->tm_year); + scanf("%c", &tmp); + if((tmp|0b00100000) != 'y') + encoderDate(&date, "Date facturation"); + else + { + date.jour = locTime->tm_mday; + date.moi = locTime->tm_mon; + date.annee = locTime->tm_year; + // printf("%d/%d/%d\n", date->jour, date->moi, date->annee ); + } + + Client * client; + char nomClient[__STRLEN__]; + char fichierClient[__STRLEN_FILE__]; + int choixMenu; + clientF = localiserFichierClients(fichierClient); + while(w) + { + printf("1. Nouveau client\n"); + printf("2. Client enregistré\n"); + do{ + printf("Choix (1|2):");clean_keyboard();scanf("%d", &choixMenu); + }while(!(choixMenu<=2 && choixMenu>=1)); + switch (choixMenu) + { + case 1: + client = malloc(sizeof(Client)); + encoderClient(client); + afficherClient(client, &date); + ajouterClientBin(clientF, client); + w = gestionClient(client, &date); + break; + case 2: + printf("Nom du client (sensible a la casse) : "); + clean_keyboard();scanf("%s", nomClient); + client = rechercheClient(nomClient, clientF, &date); + if(client != NULL) + { + w = gestionClient(client, &date); + } + else + { + printf("Client non trouvé !\n"); + printf("%d",(int)sizeof(Client)); + } + break; + } + } + fclose(clientF); + return 0; +} +void encoderDate(Date * date, char invite[__STRLEN__]) +{ + do { + printf("%s\n", invite); + printf("Entrez la date sous cette forme : jj/mm/aaaa\n"); + scanf("%d/%d/%d",&(date->jour),&(date->moi),&(date->annee)); + } while(!dateValide(date)); +} + +Bool dateValide(Date * date) +{ + int j = date->jour; + int m = date->moi; + int a = date->annee; + int bis; + if(m != 2) + { + if(m >= 1 && m <= 7) + { + if(m %2 == 0) + { + if(j >= 1 && j <= 30) return TRUE; + else return FALSE; + } + else + { + if(j >= 1 && j <= 31) return TRUE; + else return FALSE; + } + } + else if(m > 7 && m <= 12) + { + if(m %2 == 0) + { + if(j >= 1 && j <= 31) return TRUE; + else return FALSE; + } + else + { + if(j >= 1 && j <= 30) return TRUE; + else return FALSE; + } + } + else return FALSE; + } + else + { + if(a %100 == 0) + { + if(a %400 == 0) bis = 1; + else bis = FALSE; + } + else + { + if(a %4 == 0)bis = 1; + else bis = FALSE; + } + if(bis == 1) + { + if(j >= 1 && j <= 29) return TRUE; + else return FALSE; + } + else + { + if(j >= 1 && j <= 28) return TRUE; + else return FALSE; + } + } +} + +void encoderArticle(Article * article) +{ + printf("\nVeuillez entrer le nom : "); + clean_keyboard(); + scanf("%34s", article->deisgnation); + printf("\nVeuillez entrer le prix a l'unite hors TVA : "); + clean_keyboard(); + scanf("%f", &article->prixHTVA); + printf("\nVeuillez entrer la quantite desiree : "); + clean_keyboard(); + scanf("%d", &article->quant); +} + +void encoderClient(Client * client) +{ + printf("Encoage Client\n"); + client->fidelite = 0; + if(!(printf("Entrez la rue :") && clean_keyboard() && fgets(client->adresse.rue,__STRLEN__,stdin) != NULL && \ + printf("\nEntrez le numero :" ) && clean_keyboard() && fgets(client->adresse.numero,__STRLEN__,stdin) != NULL && \ + printf("\nEntrez la localité :") && clean_keyboard() && fgets(client->adresse.localite,__STRLEN__,stdin) != NULL && \ + printf("\nEntrez le code postal :") && clean_keyboard() && scanf("%d", &(client->adresse.codePostal)) && \ + printf("\nNom client :") && clean_keyboard() && fgets(client->nom,__STRLEN__,stdin) != NULL)) + { + printf("\nErreur lors de l'encodage de l'adresse"); + exit(-1); + } + cleanFgets(client->adresse.rue);cleanFgets(client->adresse.numero);cleanFgets(client->adresse.localite); + cleanFgets(client->nom); + if(!(printf("\n Entrez le numéro de tél. :") && clean_keyboard() &&fgets(client->contact.telephone,13,stdin) && \ + printf("\nEntrez l'adresse email :") && clean_keyboard() &&fgets(client->contact.email,__STRLEN__,stdin))) + { + printf("\nErreur lors de l'encodage des coo de contact"); + exit(-1); + } + cleanFgets(client->contact.telephone);cleanFgets(client->contact.email); + encoderDate(&(client->anniversaire), "\nAnniversaire client:"); +} +void afficherClient(Client *client, Date *date) +{ + printf("Client : %s (%d)\n", client->nom, ageClient(client, date)); + printf("rue : %s\n",client->adresse.rue); + printf("numero : %s\n",client->adresse.numero); + printf("localité : %s\n",client->adresse.localite); + printf("code postal : %d\n",client->adresse.codePostal); + printf("numéro de tél. : %s\n",client->contact.telephone); + printf("adresse email : %s\n",client->contact.email); + printf("\nPoints de fidelite aqui : %d\n", client->fidelite); +} +void sauvegarderClient(Client *client, FILE * file, Date *date) +{ + fprintf(file, "Client : %s (%d)\n", client->nom, ageClient(client, date)); + fprintf(file, "rue : %s\n",client->adresse.rue); + fprintf(file, "numero : %s\n",client->adresse.numero); + fprintf(file, "localité : %s\n",client->adresse.localite); + fprintf(file, "code postal : %d\n",client->adresse.codePostal); + fprintf(file, "numéro de tél. : %s\n",client->contact.telephone); + fprintf(file, "adresse email : %s\n",client->contact.email); + fprintf(file, "\nPoints de fidelite aqui : %d\n", client->fidelite); +} +void encoderFacture(Panier * panier) +{ + char continuer = 'y'; + do{ + if(panier->nbrArt <= __MAXNBRART__) + { + encoderArticle(&(panier->article[panier->nbrArt-1])); + printf("Y-a-t-il encore un article ?(Y|n)"); + clean_keyboard(); + scanf("%c", &continuer); + if(panier->nbrArt < __MAXNBRART__ && (continuer|0b00100000) == 'y') + { + panier->nbrArt++; + Article * tempArticle; + tempArticle = (Article*)realloc(panier->article, sizeof(Article)*(panier->nbrArt)); + if(panier->article == NULL) + { + printf("ERREUR ALLOCATION !"); + free(tempArticle); + free(panier->article); + exit(-1); + } + else + { + panier->article = tempArticle; + } + } + else if((continuer|0b00100000) == 'y') + { + system("cls"); + printf("Vous avez ateint le nombre d'article maximum !\n\n"); + break; + } + } + }while((continuer|0b00100000) == 'y' && panier->nbrArt <= __MAXNBRART__); +} +FILE * creerFichier(Date * date, Client * client) +{ + char fileName[__STRLEN__+16]; + fileName[0] = '\0'; + char dir[__STRLEN__]; + int i; + char buf[5]; + printf("Dossier d'enregistrement : "); + clean_keyboard(); + scanf("%s", dir); + //Toute cette partie aurais pus être remplacé par un sprintf + strcat(fileName,client->nom); + itoaY(date->annee, buf); + strcat(fileName,buf); + itoaDM(date->moi, buf); + strcat(fileName, buf); + itoaDM(date->jour, buf); + strcat(fileName, buf); + strcat(fileName,"_"); + + + for(i=1; i<= 99; i++) + { + char fileNameTmp[__STRLEN__+16+255]; + sprintf(fileNameTmp,"%s%s%d.txt",dir,fileName,i); + if(!fichierExistant(fileNameTmp)) + { + FILE * f = fopen(fileNameTmp,"w"); + if(f==NULL) + { + printf("Erreur lors de l'ouverture du fichier"); + return creerFichier(date, client); + } + else + return f; + } + } + return NULL; +} +Bool fichierExistant(char * filename) +{ + FILE * f = fopen(filename, "r"); + fclose(f); + if(f==NULL) + return FALSE; + else + return TRUE; +} +void sauvergarderFacture(FILE * file, Date * date, Client * client) +{ + int i; + float prixTot = 0; + fprintf(file,"La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n"); + fprintf(file,"\nFacture a payer\n"); + fprintf(file,"Date de facturation :"); + fprintf(file,"%02d/%02d/%02d", date->jour, date->moi, date->annee); + fprintf(file, "\n Info client :"); + sauvegarderClient(client, file, date); + fprintf(file,"\n|---------------------------------------------------------------------------------------------|\ + \n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |\ + \n|---------------------------------------------------------------------------------------------|"); + + for(i=0;client->panier.nbrArt>i;i++) + { + fprintf(file,"\n|%34s|%12.2f Eur |%14d| %c |%12.2f |",\ + client->panier.article[i].deisgnation,client->panier.article[i].prixHTVA,client->panier.article[i].quant\ + ,(client->panier.article[i].quant>=20)?'x':' ',\ + (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant); + prixTot += (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant; + } + fprintf(file,"\n|---------------------------------------------------------------------------------------------|"); + fprintf(file,"\nPrix totale :%f", prixTot); + fprintf(file, "\nPoints de fidelite aqui : %d\n", client->fidelite); +} + +void afficherFacture(Date * date, Client * client) +{ + int i; + float prixTot = 0; + printf("La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n"); + printf("\nFacture a payer\n"); + printf("Date de facturation :"); + printf("%02d/%02d/%02d", date->jour, date->moi, date->annee); + printf("\n Info client :"); + afficherClient(client, date); + printf("\n|---------------------------------------------------------------------------------------------|\ + \n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |\ + \n|---------------------------------------------------------------------------------------------|"); + + for(i=0;client->panier.nbrArt>i;i++) + { + printf("\n|%34s|%12.2f Eur |%14d| %c |%12.2f |",\ + client->panier.article[i].deisgnation,client->panier.article[i].prixHTVA,client->panier.article[i].quant\ + ,(client->panier.article[i].quant>=20)?'x':' ',\ + (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant); + prixTot += (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant; + } + printf("\n|---------------------------------------------------------------------------------------------|"); + client->fidelite = pointsFidelite(prixTot); + printf("\nPrix totale :%f", prixTot); + printf("\nPoints de fidelite aqui : %d\n", client->fidelite); + +} + + +void cleanFgets(char * str) +{ + char *p = strchr(str, '\n'); + if(p!=NULL) + *p = '\0'; + else + { + printf("Une erreur est arrivé lors du nettoygae \\0"); + exit(-1); + } +} +int itoaY(int i, char * buf) +{ + buf [0] = '0'; + buf [1] = '0'; + buf [2] = '0'; + buf [3] = '0'; + buf [4] = '\0'; + int j; + if(!i) + return 1; + buf [3] = '1'; + for(j=1; j<=i && j<=9999 ; j++) + { + if(!(j%1000)) + { + buf[0]++; + buf[1]='0'; + buf[2]='0'; + buf[3]='0'; + } + else if(!(j%100)) + { + buf[1]++; + buf[2]='0'; + buf[3]='0'; + } + else if(!(j%10)) + { + buf[2]++; + buf[3]='0'; + } + else + { + buf[3]++; + } + } + if(j>9999) + return 0; + else + return 1; +} +int itoaDM(int i, char * buf) +{ + buf[0] = '0'; + buf[1] = '0'; + buf[2] = '\0'; + int j; + if(!i) + return 1; + buf[1]++; + for(j=1; j<=i && j<=99 ; j++) + { + if(!(j%10)) + { + (buf[0])++; + (buf[1])='0'; + } + else + { + (buf[1])++; + } + } + if(j>99) + return 0; + else + return 1; +} + +Bool clean_keyboard() +{ + fflush(stdin); + // char c; +//while ((c = getchar()) != '\n' && c != EOF) { } + /* do { + c = getc(stdin); + printf("%c\n", c); + } while (c != '\n' && c != EOF);*/ + return 1; +} + +int ageClient(Client * client, Date * date) +{ + if((date->moi == client->anniversaire.moi && date->jour >= client->anniversaire.jour) || (date->moi > client->anniversaire.moi))//anniversaire passé + { + return (date->annee - client->anniversaire.annee); + } + else + return (date->annee - client->anniversaire.annee - 1); +} + +int pointsFidelite(float prix) +{ + return (int)(prix/10); +} + + +void gestionFacture(Client * client, Date * date) +{ + FILE * file; + + + printf("%d/%d/%d\n", date->jour, date->moi, date->annee ); + file = creerFichier(date, client); + + client->panier.article = (Article *)malloc(sizeof(Article)); + client->panier.nbrArt = 1; + if(client->panier.article == NULL) + { + printf("ERREUR ALLOCATION ARTICLE!"); + free(client->panier.article); + exit(-1); + } + + encoderFacture(&client->panier); + afficherFacture(date, client); + sauvergarderFacture(file, date, client); + // getch(); + fclose(file); + free(client->panier.article); +} + +Client * rechercheClient(char nom[__STRLEN__], FILE * clientF, Date * date) +{ + Client * client = NULL; + client = malloc(sizeof(Client)); + fseek(clientF, 0, SEEK_SET); + clearerr(clientF); //Clear EOF + do + { + fread(client, sizeof(Client), 1, clientF); + }while(!feof(clientF) && strcmp(client->nom, nom)); + if(feof(clientF)) + return NULL; + else + return client; +} + +Bool gestionClient(Client * client, Date * date) +{ + char choix; + while(1) + { + do + { + printf("A. Donnees client\n"); + printf("B. Facture\n"); + printf("C. Retour\n"); + printf("D. Quitter"); + clean_keyboard();scanf("%c", &choix); + choix |= 0b00100000; + }while(!(choix == 'a' || choix == 'b' || choix == 'c' || choix == 'd')); + switch (choix) { + case 'a': + afficherClient(client, date); + break; + case 'b': + gestionFacture(client, date); + break; + case 'c': + return 1; + break; + case 'd': + return 0; + break; + } + } +} + +FILE * localiserFichierClients(char fichierClient[__STRLEN_FILE__]) +{ + FILE * clientF; + char rep[__STRLEN_FILE__]; + char repTmp[__STRLEN_FILE__]; + printf("Repertoir ou se trouve le fichier client.dat"); + clean_keyboard(); + scanf("%s", rep); + sprintf(repTmp,"%sclients.dat", rep); + clientF = fopen(repTmp, "r"); + if(clientF == NULL) + { + fclose(clientF); + clientF = fopen(repTmp, "w"); + fclose(clientF); + } + fclose(clientF); + clientF = fopen(repTmp, "r+b"); + if(clientF == NULL) + { + printf("Erreur ouverture fichier"); + return localiserFichierClients(fichierClient); + } + strcpy(fichierClient, repTmp); + return clientF; +} + +int ajouterClientBin(FILE * clientF, Client * client) +{ + int posi; + fseek(clientF, 0, SEEK_END); + posi = ftell(clientF); + fwrite(client, sizeof(Client), 1, clientF); + fflush(clientF); + return posi; +} diff --git a/VANDAMME27.o b/VANDAMME27.o new file mode 100644 index 0000000..f7fa6bc Binary files /dev/null and b/VANDAMME27.o differ diff --git a/colin14.c b/colin14.c index e408326..cb0951d 100644 --- a/colin14.c +++ b/colin14.c @@ -1,134 +1,134 @@ -#include -#include -#define Taux 0.21 - -void EncoderDate(int*, int*, int*); -int DateValide (int, int, int); - -int main() -{ - //Declarer et initialiser les variables - float PrixU=0; - float TVA=0; - int Qte=25; - float PrixHT=0; - float PrixTTC=0; - float PrixTot=0; - int j=0; - int m=0; - int a=0; - int TorF; - - //Encoder et vérifier la date - do - { - EncoderDate(&j,&m,&a); - TorF = DateValide(j, m, a); - } - while (TorF == 0); - - //Encoder le prix et la quantité - printf("Veuillez entrer le prix a l'unite hors TVA : "); - scanf("%f", &PrixU); - printf("Veuillez entrer la quantite desiree : "); - fflush(stdin); - scanf("%d", &Qte); - - //En tête de la facture - printf("La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n"); - printf("\nFacture a payer\n"); - - //Calcul des prix - printf("\nHewlett-Packard ProBook650 : \t%10.2f Euros X%1d\n",PrixU,Qte); - PrixHT = PrixU*Qte; - printf("Prix HTVA : \t%10.2f Euros\n",PrixHT); - TVA = PrixHT*Taux; - printf("TVA (21%%) : \t%10.2f Euros\n",TVA); - PrixTTC = PrixHT + TVA; - printf("\nPrix TTC : \t%10.2f Euros\n",PrixTTC); - PrixTot = PrixTTC - PrixTTC/10; - if (Qte>=20) - {printf("Remise de 10%% a l'achat d'au moins 20 pieces\n"); - printf("Prix total : \t%10.2f Euros\n",PrixTot); - } - printf("Date de facturation :"); - if (j<10) - { - if (m<10) - printf("0%d/0%d/%d", j, m, a); - else - printf("0%d/%d/%d", j, m, a); - } - else - { - if (m<10) - printf("%d/0%d/%d", j, m, a); - else - printf("%d/%d/%d", j, m, a); - } - getch(); - return 0; -} -void EncoderDate(int *j, int *m, int *a) -{ - printf("Entrez la date sous cette forme : jj/mm/aaaa\n"); - fflush(stdin); scanf("%d/%d/%d",j,m,a); -} - -int DateValide(int j, int m, int a) -{ - int bis; - if(m != 2) - { - if(m >= 1 && m <= 7) - { - if(m %2 == 0) - { - if(j >= 1 && j <= 30) return 1; - else return 0; - } - else - { - if(j >= 1 && j <= 31) return 1; - else return 0; - } - } - else if(m > 7 && m <= 12) - { - if(m %2 == 0) - { - if(j >= 1 && j <= 31) return 1; - else return 0; - } - else - { - if(j >= 1 && j <= 30) return 1; - else return 0; - } - } - else return 0; - } - else - { - if(a %100 == 0) - { - if(a %400 == 0) bis = 1; - else bis = 0; - } - else - { - if(a %4 == 0)bis = 1; - else bis = 0; - } - if(bis == 1) - { - if(j >= 1 && j <= 29) return 1; - else return 0; - } - else - { - if(j >= 1 && j <= 28) return 1; - else return 0; - } - } -} +#include +#include +#define Taux 0.21 + +void EncoderDate(int*, int*, int*); +int DateValide (int, int, int); + +int main() +{ + //Declarer et initialiser les variables + float PrixU=0; + float TVA=0; + int Qte=25; + float PrixHT=0; + float PrixTTC=0; + float PrixTot=0; + int j=0; + int m=0; + int a=0; + int TorF; + + //Encoder et vérifier la date + do + { + EncoderDate(&j,&m,&a); + TorF = DateValide(j, m, a); + } + while (TorF == 0); + + //Encoder le prix et la quantité + printf("Veuillez entrer le prix a l'unite hors TVA : "); + scanf("%f", &PrixU); + printf("Veuillez entrer la quantite desiree : "); + fflush(stdin); + scanf("%d", &Qte); + + //En tête de la facture + printf("La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n"); + printf("\nFacture a payer\n"); + + //Calcul des prix + printf("\nHewlett-Packard ProBook650 : \t%10.2f Euros X%1d\n",PrixU,Qte); + PrixHT = PrixU*Qte; + printf("Prix HTVA : \t%10.2f Euros\n",PrixHT); + TVA = PrixHT*Taux; + printf("TVA (21%%) : \t%10.2f Euros\n",TVA); + PrixTTC = PrixHT + TVA; + printf("\nPrix TTC : \t%10.2f Euros\n",PrixTTC); + PrixTot = PrixTTC - PrixTTC/10; + if (Qte>=20) + {printf("Remise de 10%% a l'achat d'au moins 20 pieces\n"); + printf("Prix total : \t%10.2f Euros\n",PrixTot); + } + printf("Date de facturation :"); + if (j<10) + { + if (m<10) + printf("0%d/0%d/%d", j, m, a); + else + printf("0%d/%d/%d", j, m, a); + } + else + { + if (m<10) + printf("%d/0%d/%d", j, m, a); + else + printf("%d/%d/%d", j, m, a); + } + getch(); + return 0; +} +void EncoderDate(int *j, int *m, int *a) +{ + printf("Entrez la date sous cette forme : jj/mm/aaaa\n"); + fflush(stdin); scanf("%d/%d/%d",j,m,a); +} + +int DateValide(int j, int m, int a) +{ + int bis; + if(m != 2) + { + if(m >= 1 && m <= 7) + { + if(m %2 == 0) + { + if(j >= 1 && j <= 30) return 1; + else return 0; + } + else + { + if(j >= 1 && j <= 31) return 1; + else return 0; + } + } + else if(m > 7 && m <= 12) + { + if(m %2 == 0) + { + if(j >= 1 && j <= 31) return 1; + else return 0; + } + else + { + if(j >= 1 && j <= 30) return 1; + else return 0; + } + } + else return 0; + } + else + { + if(a %100 == 0) + { + if(a %400 == 0) bis = 1; + else bis = 0; + } + else + { + if(a %4 == 0)bis = 1; + else bis = 0; + } + if(bis == 1) + { + if(j >= 1 && j <= 29) return 1; + else return 0; + } + else + { + if(j >= 1 && j <= 28) return 1; + else return 0; + } + } +} diff --git a/colin22.c b/colin22.c index 383c4bb..fdeeb8d 100644 --- a/colin22.c +++ b/colin22.c @@ -1,258 +1,258 @@ -//Compl�tez le programme en respectant les consignes donn�es en commentaires. -//Biblioth�ques (2 pts) - #include - #include - -//D�finition d'une constante N de valeur 10 (2 pts) - #define N 10 - //#define __DEBUG__ - -//Prototypes des fonctions d�finies par apr�s (7 pts) -FILE* OuvrirFichier (); -void EncoderNomFichier (char[]); -char ChaineVersOctet (char[]); -void LireDonnees (FILE*, char[]); -void AfficherDonnees (char[]); -void CorrigerDonnee (char[], int); -int ParitePaire (char); - -int main() -{ - int i, erreur=0; - //D�claration d'un pointeur fichier permettant de manipuler un fichier, initialis� - //� NULL (2 pts) - FILE* fichier = NULL; - - //D�claration d'un tableau tab de N �l�ments de 8 bits (2 pts) - char tab[N]; - - //Le pointeur fichier prend la valeur retourn�e par OuvrirFichier (2 pts) - fichier = OuvrirFichier (); - - //Si la valeur du pointeur fichier indique que le fichier a pu �tre ouvert (1 pt) - if (fichier != NULL) - {//Appel de la fonction LireDonnees (2 pts) - LireDonnees(fichier, tab); - - //Fermeture du fichier (1 pt) - fclose (fichier); - - printf("\nDonnees lues :"); - //Affichage en binaire des N �l�ments de tab (1 pt) - AfficherDonnees (tab); - - for (i=0; i=0; i--) - { - //Si l��l�ment i de chaine est le caract�re 1, positionner le bit - //correspondant de la variable octet � 1, sinon le laisser � 0. (4 pts) - if (chaine[i] == '1') - octet = octet|masque; - - //D�caler masque pour traiter le bit suivant (1 pt) - masque<<=1; - } - return octet; -} - -//La fonction LireDonnees re�oit en arguments un pointeur fichier permettant -//de manipuler un fichier et un tableau tab dont chaque �l�ment est une donn�e -//cod�e sur 8 bits. Elle ne retourne aucune valeur. (3 pts) G:\PROJET_FINAL_HTML\progra\colin22.txt -void LireDonnees (FILE *fichier, char *tab) -{ - int i; - char donnee[10]; - char *p; - for(i=0; i0; j--) - { - if (tab[i] & m) - { - #ifdef __DEBUG__ - printf("DEBUG i%d j%d: DONNE tab[i] %c avec masque %x\n",i,j,tab[i], tab[i]&0xff&m); - #endif - b[j-1]='1'; - } - - else - { - #ifdef __DEBUG__ - printf("DEBUG i%d j%d: DONNE tab[i] %c avec masque %x\n",i,j,tab[i], tab[i]&0xff&m); - #endif - b[j-1]='0'; - } - m<<=1; - } - b[8]='\0'; - printf ("%s", b); - - } - printf("\n"); -} - -//La fonction CorrigerDonnee re�oit en arguments un tableau tab dont chaque �l�ment -//est une donn�e cod�e sur 8 bits et un entier i. Elle ne retourne aucune valeur. -//(3 pts) -void CorrigerDonnee(char tab[N], int i) -{ - char donnee[9]; - printf("\nLa donnee %d est erronnee; veuillez la reencoder:", i+1); - //Vider la m�moire clavier et saisir la valeur de donnee.(3 pts) - fflush (stdin); - gets(donnee); - - //Remplacer l��l�ment i de tab par la donnee r�encod�e convertie en octet. (2 pts) - tab[i] = ChaineVersOctet(donnee); -} - -//La fonction ParitePaire re�oit un argument octet cod� sur 8 bits. Elle retourne -//"vrai" ou "faux". (2 pts) -int ParitePaire (char octet) -{//D�claration et �ventuellement initialisation des variables locales (3 pts) - int i, compteur = 0, masque = 1; - - for (i=0; i<8; i++) - {//Si le bit i de l�argument octet vaut 1, incr�menter la variable compteur - //d�une unit� (3 pts) - if (octet & masque) - compteur++; - //D�caler masque pour traiter le bit suivant (1 pt) - masque <<= 1; - } - //Si compteur est impair retourner "faux", sinon retourner "vrai" (2 pts) - if (compteur%2) - return 0; - else - return 1; -} +//Compl�tez le programme en respectant les consignes donn�es en commentaires. +//Biblioth�ques (2 pts) + #include + #include + +//D�finition d'une constante N de valeur 10 (2 pts) + #define N 10 + //#define __DEBUG__ + +//Prototypes des fonctions d�finies par apr�s (7 pts) +FILE* OuvrirFichier (); +void EncoderNomFichier (char[]); +char ChaineVersOctet (char[]); +void LireDonnees (FILE*, char[]); +void AfficherDonnees (char[]); +void CorrigerDonnee (char[], int); +int ParitePaire (char); + +int main() +{ + int i, erreur=0; + //D�claration d'un pointeur fichier permettant de manipuler un fichier, initialis� + //� NULL (2 pts) + FILE* fichier = NULL; + + //D�claration d'un tableau tab de N �l�ments de 8 bits (2 pts) + char tab[N]; + + //Le pointeur fichier prend la valeur retourn�e par OuvrirFichier (2 pts) + fichier = OuvrirFichier (); + + //Si la valeur du pointeur fichier indique que le fichier a pu �tre ouvert (1 pt) + if (fichier != NULL) + {//Appel de la fonction LireDonnees (2 pts) + LireDonnees(fichier, tab); + + //Fermeture du fichier (1 pt) + fclose (fichier); + + printf("\nDonnees lues :"); + //Affichage en binaire des N �l�ments de tab (1 pt) + AfficherDonnees (tab); + + for (i=0; i=0; i--) + { + //Si l��l�ment i de chaine est le caract�re 1, positionner le bit + //correspondant de la variable octet � 1, sinon le laisser � 0. (4 pts) + if (chaine[i] == '1') + octet = octet|masque; + + //D�caler masque pour traiter le bit suivant (1 pt) + masque<<=1; + } + return octet; +} + +//La fonction LireDonnees re�oit en arguments un pointeur fichier permettant +//de manipuler un fichier et un tableau tab dont chaque �l�ment est une donn�e +//cod�e sur 8 bits. Elle ne retourne aucune valeur. (3 pts) G:\PROJET_FINAL_HTML\progra\colin22.txt +void LireDonnees (FILE *fichier, char *tab) +{ + int i; + char donnee[10]; + char *p; + for(i=0; i0; j--) + { + if (tab[i] & m) + { + #ifdef __DEBUG__ + printf("DEBUG i%d j%d: DONNE tab[i] %c avec masque %x\n",i,j,tab[i], tab[i]&0xff&m); + #endif + b[j-1]='1'; + } + + else + { + #ifdef __DEBUG__ + printf("DEBUG i%d j%d: DONNE tab[i] %c avec masque %x\n",i,j,tab[i], tab[i]&0xff&m); + #endif + b[j-1]='0'; + } + m<<=1; + } + b[8]='\0'; + printf ("%s", b); + + } + printf("\n"); +} + +//La fonction CorrigerDonnee re�oit en arguments un tableau tab dont chaque �l�ment +//est une donn�e cod�e sur 8 bits et un entier i. Elle ne retourne aucune valeur. +//(3 pts) +void CorrigerDonnee(char tab[N], int i) +{ + char donnee[9]; + printf("\nLa donnee %d est erronnee; veuillez la reencoder:", i+1); + //Vider la m�moire clavier et saisir la valeur de donnee.(3 pts) + fflush (stdin); + gets(donnee); + + //Remplacer l��l�ment i de tab par la donnee r�encod�e convertie en octet. (2 pts) + tab[i] = ChaineVersOctet(donnee); +} + +//La fonction ParitePaire re�oit un argument octet cod� sur 8 bits. Elle retourne +//"vrai" ou "faux". (2 pts) +int ParitePaire (char octet) +{//D�claration et �ventuellement initialisation des variables locales (3 pts) + int i, compteur = 0, masque = 1; + + for (i=0; i<8; i++) + {//Si le bit i de l�argument octet vaut 1, incr�menter la variable compteur + //d�une unit� (3 pts) + if (octet & masque) + compteur++; + //D�caler masque pour traiter le bit suivant (1 pt) + masque <<= 1; + } + //Si compteur est impair retourner "faux", sinon retourner "vrai" (2 pts) + if (compteur%2) + return 0; + else + return 1; +} diff --git a/colin22.txt b/colin22.txt index 4c8f72e..2bac503 100644 --- a/colin22.txt +++ b/colin22.txt @@ -1,11 +1,11 @@ -01100011 -01110010 -01100011 -01101100 -01100101 -01100110 -01101101 -01101100 -01101001 -01101111 -01101100 +01100011 +01110010 +01100011 +01101100 +01100101 +01100110 +01101101 +01101100 +01101001 +01101111 +01101100 diff --git a/test b/test new file mode 100644 index 0000000..108cb8a Binary files /dev/null and b/test differ