Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. // Strucure de type article
  6. typedef struct{
  7. char libelle[19];
  8. int codeArticle, codeR;
  9. float prixU,total;
  10. struct article *suivant;
  11. }article;
  12.  
  13. // Structure de type rayon
  14. typedef struct{
  15. char nom[11];
  16. int codeRayon;
  17. struct rayon *rsuivant;
  18. }rayon;
  19.  
  20. main(){
  21. /*Déclarations des fichiers*/
  22. FILE *fdat, *fdat2, *fres;
  23. fdat2 = fopen("produit.dat","r");
  24. fdat = fopen("rayon.dat","r");
  25. fres = fopen("ticket.res","w");
  26.  
  27. /* Déclarations des données*/
  28. char nomArt[50][19], extra[4];
  29. int cpt=1, i, choixRayon[50]={1},n=1,quant[50],choixArt,a=1,nbArt=1,j,vid=0;
  30. float total=0.,red = 0.;
  31. article *deb, *courant, *suivant;
  32. rayon *rdeb, *rcourant, *rsuivant;
  33. rdeb = malloc(sizeof(rayon));
  34. rcourant = rdeb;
  35.  
  36. //Lecture des rayons dans le premier fichier
  37. fscanf(fdat,"%1d",&rcourant->codeRayon);
  38. while(!feof(fdat))
  39. {
  40. fscanf(fdat,"%10s",&rcourant->nom);
  41. rsuivant = malloc(sizeof(rayon));
  42. rcourant->rsuivant = rsuivant;
  43. cpt++;
  44. rcourant = rsuivant;
  45. fscanf(fdat,"%1d",&rcourant->codeRayon);
  46. }
  47. cpt-=1;
  48.  
  49. rcourant=rdeb;
  50. for(i=1;i<=cpt;i++)
  51. {
  52. rcourant=rcourant->rsuivant;
  53. }
  54. (*rcourant).rsuivant = NULL;
  55.  
  56. //Lecture des articles dans le second fichier
  57. deb = malloc(sizeof(article));
  58. courant = deb;
  59. fscanf(fdat2,"%1d",&courant->codeR);
  60.  
  61. while(!feof(fdat2))
  62. {
  63.  
  64. fscanf(fdat2,"%5d",&courant->codeArticle);
  65. fscanf(fdat2,"%19s",courant->libelle);
  66. fscanf(fdat2,"%5f",&courant->prixU);
  67. suivant = malloc(sizeof(article));
  68. courant->suivant = suivant;
  69. n++;
  70. courant = suivant;
  71. fscanf(fdat2,"%1d",&courant->codeR);
  72. }
  73. n--;
  74. courant=deb;
  75. for(i=1;i<=n;i++)
  76. {
  77. courant=courant->suivant;
  78. }
  79. (*courant).suivant = NULL;
  80.  
  81. /*Interarction console*/
  82. printf("Votre magasin Colruyt vous souhaite la bienvenue !\n");
  83. printf("Commencez vos achats en choisissant un rayon !\n\n");
  84. printf("Appuyez a tout moment sur 0 pour quitter le programme !\n\n");
  85.  
  86. rcourant=rdeb;
  87. for(i=1;i<=cpt;i++)
  88. {
  89. printf("%d : %-10s\n",rcourant->codeRayon,rcourant->nom);
  90. rcourant=rcourant->rsuivant;
  91. }
  92. printf("\nTapez le numero correspondant a l'action souhaitee : ");
  93. scanf("%d",&choixRayon[nbArt]);
  94. printf("\n");
  95. while(choixRayon[nbArt]!=0){
  96. courant = deb;
  97. for(i=1;i<=n;i++){
  98. if(courant->codeR == choixRayon[nbArt]){
  99. printf("%-18s %5.2f Eur\n",courant->libelle,courant->prixU);
  100. courant = courant->suivant;
  101. }else{
  102. courant = courant->suivant;
  103. }
  104. }
  105. printf("\nEncodez le nom de l'article : ");
  106. scanf("%19s",&nomArt[nbArt]);
  107. printf("\nVeuillez indiquer la quantite desiree : ");
  108. scanf("%d",&quant[nbArt]);
  109. printf("\n");
  110. nbArt++;
  111. rcourant=rdeb;
  112.  
  113. for(i=1;i<=cpt;i++)
  114. {
  115. printf("%d : %-10s\n",rcourant->codeRayon,rcourant->nom);
  116. rcourant=rcourant->rsuivant;
  117. }
  118. printf("\nTapez le numero correspondant a l'action souhaitee : ");
  119. scanf("%d",&choixRayon[nbArt]);
  120. }
  121. printf("Avez-vous la carte extra ? ( Oui/Non ) ");
  122. scanf("%s",&extra);
  123. if(strcmp(extra,"oui") == 0 || strcmp(extra,"Oui")==0){
  124. red = 0.05;
  125. }
  126. fprintf(fres," COLRUYT\n\n");
  127. 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");
  128. fprintf(fres," Vous avez ete servi par Marc et Loic\n");
  129. fprintf(fres,"+-------+------------------------+----------+--------+------------+-------------+\n");
  130. fprintf(fres,"| N° art| Dénomination | Vidanges | Quant. | Prix U Eur | Montant Eur |\n");
  131. fprintf(fres,"+-------+------------------------+----------+--------+------------+-------------+\n");
  132. for(j=1;j<nbArt;j++){
  133. courant=deb;
  134. for(i=1;i<=n;i++){
  135. if(choixRayon[j]==courant->codeR){
  136. if(strcmp(nomArt[j],courant->libelle)== 0)
  137. {
  138. fprintf(fres,"|%5d |%-18s | | %1d | %5.2f | %6.2f |\n",courant->codeArticle,courant->libelle,quant[j],courant->prixU,courant->prixU*quant[j]);
  139. total += courant->prixU*quant[j];
  140. courant = courant->suivant;
  141. }
  142. else{
  143. courant = courant->suivant;
  144. }
  145. }
  146. else{
  147. courant = courant->suivant;
  148. }
  149. }
  150. }
  151. printf("\n\nCa vous fera %6.2f euros. Votre ticket est en cours d'impression !\nMerci de votre achat !\n\n",total);
  152. fprintf(fres,"+-------+------------------------+----------+--------+------------+-------------+\n");
  153. fprintf(fres," | A payer %6.2f Euros |\n",total*(1-red));
  154. fprintf(fres," +--------------------------+\n");
  155. fprintf(fres,"Vous avez epargne %6.2f euros avec votre carte Xtra !\n\n",total*red);
  156. fprintf(fres,"Merci de vote visite et a bientot !\nColruyt\n");
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement