Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- // Strucure de type article
- typedef struct{
- char libelle[19];
- int codeArticle, codeR;
- float prixU,total;
- struct article *suivant;
- }article;
- // Structure de type rayon
- typedef struct{
- char nom[11];
- int codeRayon;
- struct rayon *rsuivant;
- }rayon;
- main(){
- /*Déclarations des fichiers*/
- FILE *fdat, *fdat2, *fres;
- fdat2 = fopen("produit.dat","r");
- fdat = fopen("rayon.dat","r");
- fres = fopen("ticket.res","w");
- /* Déclarations des données*/
- char nomArt[50][19], extra[4];
- int cpt=1, i, choixRayon[50]={1},n=1,quant[50],choixArt,a=1,nbArt=1,j,vid=0;
- float total=0.,red = 0.;
- article *deb, *courant, *suivant;
- rayon *rdeb, *rcourant, *rsuivant;
- rdeb = malloc(sizeof(rayon));
- rcourant = rdeb;
- //Lecture des rayons dans le premier fichier
- fscanf(fdat,"%1d",&rcourant->codeRayon);
- while(!feof(fdat))
- {
- fscanf(fdat,"%10s",&rcourant->nom);
- rsuivant = malloc(sizeof(rayon));
- rcourant->rsuivant = rsuivant;
- cpt++;
- rcourant = rsuivant;
- fscanf(fdat,"%1d",&rcourant->codeRayon);
- }
- cpt-=1;
- rcourant=rdeb;
- for(i=1;i<=cpt;i++)
- {
- rcourant=rcourant->rsuivant;
- }
- (*rcourant).rsuivant = NULL;
- //Lecture des articles dans le second fichier
- deb = malloc(sizeof(article));
- courant = deb;
- fscanf(fdat2,"%1d",&courant->codeR);
- while(!feof(fdat2))
- {
- fscanf(fdat2,"%5d",&courant->codeArticle);
- fscanf(fdat2,"%19s",courant->libelle);
- fscanf(fdat2,"%5f",&courant->prixU);
- suivant = malloc(sizeof(article));
- courant->suivant = suivant;
- n++;
- courant = suivant;
- fscanf(fdat2,"%1d",&courant->codeR);
- }
- n--;
- courant=deb;
- for(i=1;i<=n;i++)
- {
- courant=courant->suivant;
- }
- (*courant).suivant = NULL;
- /*Interarction console*/
- printf("Votre magasin Colruyt vous souhaite la bienvenue !\n");
- printf("Commencez vos achats en choisissant un rayon !\n\n");
- printf("Appuyez a tout moment sur 0 pour quitter le programme !\n\n");
- rcourant=rdeb;
- for(i=1;i<=cpt;i++)
- {
- printf("%d : %-10s\n",rcourant->codeRayon,rcourant->nom);
- rcourant=rcourant->rsuivant;
- }
- printf("\nTapez le numero correspondant a l'action souhaitee : ");
- scanf("%d",&choixRayon[nbArt]);
- printf("\n");
- while(choixRayon[nbArt]!=0){
- courant = deb;
- for(i=1;i<=n;i++){
- if(courant->codeR == choixRayon[nbArt]){
- printf("%-18s %5.2f Eur\n",courant->libelle,courant->prixU);
- courant = courant->suivant;
- }else{
- courant = courant->suivant;
- }
- }
- printf("\nEncodez le nom de l'article : ");
- scanf("%19s",&nomArt[nbArt]);
- printf("\nVeuillez indiquer la quantite desiree : ");
- scanf("%d",&quant[nbArt]);
- printf("\n");
- nbArt++;
- rcourant=rdeb;
- for(i=1;i<=cpt;i++)
- {
- printf("%d : %-10s\n",rcourant->codeRayon,rcourant->nom);
- rcourant=rcourant->rsuivant;
- }
- printf("\nTapez le numero correspondant a l'action souhaitee : ");
- scanf("%d",&choixRayon[nbArt]);
- }
- printf("Avez-vous la carte extra ? ( Oui/Non ) ");
- scanf("%s",&extra);
- if(strcmp(extra,"oui") == 0 || strcmp(extra,"Oui")==0){
- red = 0.05;
- }
- fprintf(fres," COLRUYT\n\n");
- fprintf(fres,"La garantie des meilleurs prix pour chaque produit a chaque instant.\nVous avez malgre tout, vu moins cher ailleurs ?\nAppelez notre telephone rouge au 02 345 23 45 ou envoyez un e-mail a info@colruyt.be\n\n");
- fprintf(fres," Vous avez ete servi par Marc et Loic\n");
- fprintf(fres,"+-------+------------------------+----------+--------+------------+-------------+\n");
- fprintf(fres,"| N° art| Dénomination | Vidanges | Quant. | Prix U Eur | Montant Eur |\n");
- fprintf(fres,"+-------+------------------------+----------+--------+------------+-------------+\n");
- for(j=1;j<nbArt;j++){
- courant=deb;
- for(i=1;i<=n;i++){
- if(choixRayon[j]==courant->codeR){
- if(strcmp(nomArt[j],courant->libelle)== 0)
- {
- fprintf(fres,"|%5d |%-18s | | %1d | %5.2f | %6.2f |\n",courant->codeArticle,courant->libelle,quant[j],courant->prixU,courant->prixU*quant[j]);
- total += courant->prixU*quant[j];
- courant = courant->suivant;
- }
- else{
- courant = courant->suivant;
- }
- }
- else{
- courant = courant->suivant;
- }
- }
- }
- printf("\n\nCa vous fera %6.2f euros. Votre ticket est en cours d'impression !\nMerci de votre achat !\n\n",total);
- fprintf(fres,"+-------+------------------------+----------+--------+------------+-------------+\n");
- fprintf(fres," | A payer %6.2f Euros |\n",total*(1-red));
- fprintf(fres," +--------------------------+\n");
- fprintf(fres,"Vous avez epargne %6.2f euros avec votre carte Xtra !\n\n",total*red);
- fprintf(fres,"Merci de vote visite et a bientot !\nColruyt\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement