Advertisement
Guest User

Untitled

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