Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.25 KB | None | 0 0
  1.  
  2.  
  3. /* ------------------------- */
  4. /* LES #include DU PROGRAMME */
  5. /* ------------------------- */
  6.  
  7. #include <iostream>
  8. #include <iomanip>
  9. #include <conio.h>
  10. #include <string>
  11. #include <windows.h>
  12. #include <time.h> // utile pour les types "time_t" et "tm", et pour les fonctions "time(...)" et "localtime_s(...)"
  13. #include "../console(v1.9).h"
  14.  
  15. using namespace std;
  16.  
  17. /* ------------------------------------ */
  18. /* LES CONSTANTES GLOBALES DU PROGRAMME */
  19. /* ------------------------------------ */
  20.  
  21. const double MARGE_CREDIT_MAX = 10000;   // marge de crédit maximun d'un compte du client, attibuée lors de la création du client [0..10000]
  22. const double SOLDE_COMPTE_MAX = 1000000; // maximun à ne pas dépasser dans un compte d'un client
  23.  
  24. // Nombre maximal de clients.
  25. const int NB_CLIENTS_MAX = 70;
  26.  
  27. // Nombre de comptes par client.
  28. const int NB_COMPTES_PAR_CLIENT_MAX = 3;
  29.  
  30.  
  31. /* -------------------------------------- */
  32. /* LES STRUCTURES DE DONNÉES DU PROGRAMME */
  33. /* -------------------------------------- */
  34.  
  35. enum Commandes {
  36.     ajouter,
  37.     depot,
  38.     retrait,
  39.     virement,
  40.     afficherInfo,
  41.     listerClients,
  42.     supprimer,
  43.     quitter
  44. };  
  45.  
  46.  
  47. // Représente le nom complet d'un client
  48. struct Nom
  49. {
  50.     string prenom;
  51.     string nom;
  52. };
  53.  
  54. // Représente une adresse postale
  55. struct Adresse
  56. {
  57.     string noCivique;
  58.     string rue;
  59.     string ville;
  60.     string codePostal;
  61. };
  62.  
  63. // Contient les informations personnelles d'un client
  64. struct InfoPersonnel
  65. {
  66.     Nom     nom;
  67.     Adresse adresse;
  68.     string  telephone;
  69.     string  nas;
  70. };
  71.  
  72. // Informations d'un seul compte de banque
  73. struct Compte
  74. {
  75.     double solde;
  76.     double margeCredit;
  77. };
  78.  
  79. // Contient toutes les informations relatives à un client  (informations personnelles, comptes, date d'inscription)
  80. struct Client /// this puts together all the info from the client, including his 3 accounts and since when has he been a client
  81. {
  82.     InfoPersonnel   info;
  83.     Compte          compte[NB_COMPTES_PAR_CLIENT_MAX];
  84.     time_t          clientDepuis;
  85. };
  86.  
  87. // La base de données des clients
  88. struct BaseDeDonnées
  89. {
  90.     int nombreDeClients;
  91.     Client clients[NB_CLIENTS_MAX];
  92. };
  93.  
  94. /* ----------------------------------- */
  95. /* LES VARIABLES GLOBALES DU PROGRAMME */
  96. /* ----------------------------------- */
  97.  
  98. // Les variables globales ne sont pas permises
  99.  
  100.  
  101. /* ---------------------------- */
  102. /* LES PROTOTYPES DES FONCTIONS */
  103. /* ---------------------------- */
  104.  
  105. void IU_FlushTampons();
  106. double arrondir(double v, int p);
  107. void IU_Bip();
  108. void IU_Bip_DialogueErreur(string message);
  109.  
  110. // OBLIGATOIRE : Écrire les prototypes de toutes vos fonctions ici ...
  111.  
  112.  
  113.  
  114. /* ----------------------------------------- */
  115. /* LES FONCTIONS TRÈS GÉNÉRALES DU PROGRAMME */
  116. /* ----------------------------------------- */
  117.  
  118. void IU_FlushTampons() // pour vider les 2 tampons
  119. {
  120.     if (cin.fail()) cin.clear();            // s'assure que le cin est remis en marche
  121.     cin.ignore(cin.rdbuf()->in_avail());    // vide le tampon du cin
  122.     while (_kbhit()) _getch();              // vide l'autre tampon
  123. }
  124.  
  125. double arrondir(double v, int p = 2) // input v et précision p
  126. {
  127.     double e = pow(10, p);
  128.     return round(v * e) / e;
  129. }
  130.  
  131. // FONCTIONS GÉNÉRALES POUR LE SIGNALEMENT D'ERREURS (exemples)
  132.  
  133. void IU_Bip() { cout << "\a"; }
  134.  
  135. void IU_Bip_DialogueErreur(string message)
  136. {
  137.     IU_Bip();
  138.     MessageBoxA( NULL, message.c_str(), "ERREUR", MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL );
  139. }
  140.  
  141. /*   Écrire vos fonctions générales ici ...   */
  142.  
  143. /// unsure about this
  144.  
  145. //int verificationChiffreValide(int chiffre, int coordonnee_x, int coordonnee_y)
  146. //{
  147. //  do
  148. //  {
  149. //      gotoxy(coordonnee_x, coordonnee_y);
  150. //      cin >> chiffre;
  151. //  } while (cin.fail());
  152. //  return chiffre;
  153. //}
  154.  
  155.  
  156. //string dateAString(time_t date) //conversion de seconde en date; fonction tiree de stackoverflow et modifiee un peu.
  157. //{
  158. //  string date_en_lettres;
  159. //  tm *ltm = localtime(&date);
  160. //
  161. //  // print various components of tm structure.
  162. //  date_en_lettres = to_string(ltm->tm_mday) + "/" + to_string(1 + ltm->tm_mon) + "/" + to_string(1900 + ltm->tm_year);
  163. // 
  164. //  return date_en_lettres;
  165. //}
  166.  
  167. string dateAString(time_t date)
  168. {
  169.     string date_en_lettres;
  170.     tm ltm;
  171.     localtime_s(&ltm, &date);
  172.  
  173.     date_en_lettres = to_string(ltm.tm_mday) + "/" + to_string(1 + ltm.tm_mon) + "/" + to_string(1900 + ltm.tm_year);
  174.  
  175.     return date_en_lettres;
  176. }
  177.  
  178.  
  179.  
  180. /* ----------------------------------------------------------------------- */
  181. /* FONCTIONS GÉNÉRALES POUR L'INTERFACE USAGER (IU) EN LECTURE OU ÉCRITURE */
  182. /* ----------------------------------------------------------------------- */
  183.  
  184. void IU_AfficherMenuPrincipal()
  185. {
  186.     gotoxy(16, 0); cout << "Compagnie 420-B21";
  187.     gotoxy(16, 4); cout << "1. Ajouter un client";
  188.     gotoxy(16, 6); cout << "2. Dépôt";
  189.     gotoxy(16, 8); cout << "3. Retrait";
  190.     gotoxy(16, 10); cout << "4. Virement";
  191.     gotoxy(16, 12); cout << "5. Afficher les informations d'un client";
  192.     gotoxy(16, 14); cout << "6. Lister les clients et leur crédit actuel";
  193.     gotoxy(16, 16); cout << "7. Supprimer un client";
  194.     gotoxy(16, 18); cout << "8. Quitter";
  195.     gotoxy(16, 24); cout << "Entrez votre choix: ";
  196. }
  197.  
  198. Commandes IU_LireUnChoixValideDuMenuPrincipal()
  199. {
  200.     Commandes cmd = quitter; // Commande par défaut
  201.     COORD choixCoord = { wherex(),wherey() };
  202.     bool choixValide = false;
  203.     int choix;
  204.     char lettre_choix;
  205.     do
  206.     {  
  207.         clreol();
  208.         IU_FlushTampons();
  209.         gotoxy(choixCoord.X, choixCoord.Y);
  210.         choix = _getch();
  211.        
  212.         if (isdigit(choix))
  213.         {
  214.             choix = choix - '0';
  215.             choixValide = true;
  216.             cout << choix;
  217.         }
  218.         else {
  219.             lettre_choix = choix;
  220.             cout << lettre_choix;
  221.         }
  222.        
  223.     } while (choix < 1 || choix > 8 || !choixValide); //lecture et validation du choix
  224.  
  225.     switch (choix)
  226.     {
  227.     case 1:
  228.         cmd = ajouter;
  229.         break;
  230.     case 2:
  231.         cmd = depot;
  232.         break;
  233.     case 3:
  234.         cmd = retrait;
  235.         break;
  236.     case 4:
  237.         cmd = virement;
  238.         break;
  239.     case 5:
  240.         cmd = afficherInfo;
  241.         break;
  242.     case 6:
  243.         cmd = listerClients;
  244.         break;
  245.     case 7:
  246.         cmd = supprimer;
  247.         break;
  248.     case 8:
  249.         cmd = quitter;
  250.     }
  251.     return cmd;
  252. }
  253.  
  254. void IU_MessageDeFinDuProgramme()
  255. {
  256.     // Écrire le code ici ...
  257. }
  258.  
  259.  
  260. // Suggestion de fonctions, sous la forme de prototypes, pour décomposer votre programme en plus petits traitements réutilisables
  261. int IU_LireUnNoDeClient(int max);
  262. int IU_LireUnNoDeCompteValide();
  263. double IU_LireUnMontantValide(double max);
  264. void IU_AfficherLesInformationsDuClient(Client client);
  265. Client UI_LireLesInfosNouveauClient();
  266.  
  267.  
  268. /* ---------------------------------------------------------------- */
  269. /* LES FONCTIONS OBLIGATOIRES POUR CHAQUE TRANSACTION DU PROGRAMME */
  270. /* ---------------------------------------------------------------- */
  271.  
  272.  
  273. // TRANSACTION : CREATION D'UN NOUVEAU CLIENT
  274. void Transact_AjouterUnNouveauClient(BaseDeDonnées base)
  275. {
  276.    
  277.     IU_FlushTampons();
  278.     clrscr();
  279.     int affichage_x;
  280.     base.nombreDeClients++;
  281.     string date;
  282.     char c;
  283.  
  284.    
  285.  
  286.     base.clients[base.nombreDeClients - 1].clientDepuis = time(0);
  287.     date = dateAString(base.clients[base.nombreDeClients - 1].clientDepuis);
  288.        
  289.    
  290.  
  291.     //example of struct -> client_no.info.nom.prenom = "ste-catherine";
  292.  
  293.     gotoxy(0, 0); cout << "Transaction: ajouter un nouveau client";
  294.     gotoxy(0, 2); cout << "Création du client #" << base.nombreDeClients;
  295.  
  296.     gotoxy(0, 4); cout << left << setw(21) << "Prénom" << ": ";
  297.     cin >> base.clients[base.nombreDeClients - 1].info.nom.prenom;
  298.     gotoxy(0, 5); cout << left << setw(21) << "Nom" << ": ";
  299.     cin >> base.clients[base.nombreDeClients - 1].info.nom.nom;
  300.  
  301.     gotoxy(0, 7); cout << left << setw(21) << "Numéro civique" << ": ";
  302.     cin >> base.clients[base.nombreDeClients - 1].info.adresse.noCivique;
  303.     gotoxy(0, 8); cout << left << setw(21) << "Rue" << ": ";
  304.     cin >> base.clients[base.nombreDeClients - 1].info.adresse.rue;
  305.     gotoxy(0, 9); cout << left << setw(21) << "Ville" << ": ";
  306.     cin >> base.clients[base.nombreDeClients - 1].info.adresse.ville;
  307.     gotoxy(0, 10); cout << left << setw(21) << "Code postal" << ": ";
  308.     cin >> base.clients[base.nombreDeClients - 1].info.adresse.codePostal;
  309.     gotoxy(0, 11); cout << left << setw(21) << "Téléphone" << ": ";
  310.     cin >> base.clients[base.nombreDeClients - 1].info.telephone;
  311.  
  312.     gotoxy(0, 13); cout << left << setw(21) << "Numéro d'assurance sociale" << ": ";
  313.     cin >> base.clients[base.nombreDeClients - 1].info.nas;
  314.  
  315.     gotoxy(0, 15); cout << "Marge de crédit du compte #1 (Max de " << fixed << setprecision(2) << MARGE_CREDIT_MAX << " $)" << ": "; affichage_x = wherex();
  316.     cin >> base.clients[base.nombreDeClients - 1].compte[1].margeCredit;
  317.     gotoxy(affichage_x, 15); cout << base.clients[base.nombreDeClients - 1].compte[1].margeCredit;
  318.    
  319.  
  320.     gotoxy(0, 16); cout << "Marge de crédit du compte #2 (Max de " << fixed << setprecision(2) << MARGE_CREDIT_MAX << " $)" << ": "; affichage_x = wherex();
  321.     cin >> base.clients[base.nombreDeClients - 1].compte[2].margeCredit;
  322.     gotoxy(affichage_x, 16); cout << base.clients[base.nombreDeClients - 1].compte[2].margeCredit;
  323.    
  324.     gotoxy(0, 17); cout << "Marge de crédit du compte #3 (Max de " << fixed << setprecision(2) << MARGE_CREDIT_MAX << " $)" << ": "; affichage_x = wherex();
  325.     cin >> base.clients[base.nombreDeClients - 1].compte[3].margeCredit;
  326.     gotoxy(affichage_x, 17); cout << base.clients[base.nombreDeClients - 1].compte[3].margeCredit;
  327.  
  328.     gotoxy(0, 19); cout << "Date de création de ce dossier: " << date;
  329.  
  330.     gotoxy(0, 22); cout << "Appuyez sur une touche pour continuer";
  331.     c = _getch();
  332. }
  333.  
  334. // TRANSACTION : FAIRE UN DÉPÔT
  335. void Transact_FaireUnDepot( /* Paramètres ? */ )
  336. {
  337.     // Écrire le code ici ...
  338. }
  339.  
  340. // TRANSACTION : FAIRE UN RETAIT
  341. void Transact_FaireUnRetrait( /* Paramètres ? */ )
  342. {
  343.     // Écrire le code ici ...
  344. }
  345.  
  346. // TRANSACTION : FAIRE UN VIREMENT
  347. void Transact_FaireUnVirement( /* Paramètres ? */ )
  348. {
  349.     // Écrire le code ici ...
  350. }
  351.  
  352. // TRANSACTION : AFFICHER LES INFOS
  353. void Transact_AfficherTouteslesInfosDuClient( /* Paramètres ? */ )
  354. {
  355.     // Écrire le code ici ...
  356. }
  357.  
  358. // TRANSACTION : AFFICHER LE RAPPORT
  359. void Transact_ListerLesClientsEtLeurCréditActuel( /* Paramètres ? */ )
  360. {
  361.     // Écrire le code ici ...
  362. }
  363.  
  364. // TRANSACTION : SUPPRIMER UN CLIENT
  365. void Transact_SupprimerUnClient( /* Paramètres ? */ )
  366. {
  367.     // Écrire le code ici ...
  368. }
  369.  
  370.  
  371. /* ---------------------- */
  372. /* LA FONCTION PRINCIPALE */
  373. /* ---------------------- */
  374.  
  375. void main()
  376. {
  377.     // À FAIRE: dans la fenêtre de la console : boutton de droite, propriété, font = LUCIDA CONSOLE
  378.     // Permet d'écrire enfin vos string avec les accents !!!
  379.     SetConsoleCP(1252);
  380.     SetConsoleOutputCP(1252);
  381.  
  382.     BaseDeDonnées BD;  // Utiliser cette définition de variable et elle DOIT RESTER ICI, c'est-à-dire local à main()
  383.     BD.nombreDeClients = 0;  // représente le nombre actuel de clients dans la base de données BD.
  384.     Commandes cmd;
  385.     do
  386.     {
  387.         IU_AfficherMenuPrincipal();
  388.         cmd = IU_LireUnChoixValideDuMenuPrincipal();
  389.        
  390.         switch (cmd)
  391.         {
  392.             case ajouter: Transact_AjouterUnNouveauClient(BD); break;
  393.             case depot: Transact_FaireUnDepot(); break;
  394.             case retrait: Transact_FaireUnRetrait(); break;
  395.             case virement: Transact_FaireUnVirement(); break;
  396.             case afficherInfo: Transact_AfficherTouteslesInfosDuClient(); break;
  397.             case listerClients: Transact_ListerLesClientsEtLeurCréditActuel(); break;
  398.             case supprimer: Transact_SupprimerUnClient(); break;
  399.             case quitter: IU_MessageDeFinDuProgramme(); break;
  400.         }
  401.  
  402.     } while(cmd != quitter );
  403.     _getch();
  404. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement