Advertisement
wasaberg

lab7_q2

Mar 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. string tabPays[10];
  8. float tabCoutInit[10];
  9.  
  10. void lireInfoUtilisateur(string &nomPays, float &dureeAppel);
  11. int initDonnees(string nomFichier);
  12.  
  13. int main() {
  14.     string nomFichier = "data.txt";
  15.     int nbrPays = 0; // nombre de pays dans le fichier data.txt
  16.  
  17.                      // Initailisation des donnees des tableaux
  18.     int nbPays = initDonnees(nomFichier);
  19.                      // Lire les information utlisateur
  20.     float dureeAppel;
  21.     string nomPays;
  22.     lireInfoUtilisateur(nomPays, dureeAppel);
  23.  
  24.     // Retrouver le cout unit du pays
  25.     bool trouve = false;
  26.     for (int i = 0; i < nbPays; i++)
  27.     {
  28.         if (nomPays == tabPays[i])
  29.         {
  30.             trouve = true;
  31.             float coutAppel = tabCoutInit[i] * dureeAppel;
  32.             cout << "Le pays est : " << tabPays[i] << " cout initiale est : " << tabCoutInit[i] << " votre appel coute:" << coutAppel << endl;
  33.         }
  34.     }
  35.  
  36.     if (trouve == false)
  37.     {
  38.         cout << "too bad!" << endl;
  39.     }
  40.     //float coutUnitPays = coutParPays(nomPays, nbrPays);
  41.  
  42.     system("pause");
  43.    
  44.     return 0;
  45. }
  46.  
  47. void lireInfoUtilisateur(string &nomPays, float &dureeAppel)
  48. {
  49.     cout << "Vous voulez appeler quel pays ? ";
  50.     cin >> nomPays;
  51.  
  52.     cout << "\nDuree de votre appel ?";
  53.     cin >> dureeAppel;
  54. }
  55.  
  56. int initDonnees(string nomFichier)
  57. {
  58.     int i = 0;
  59.     ifstream fluxsortie("data.txt");
  60.  
  61.     if (fluxsortie)
  62.     {
  63.         while (!fluxsortie.eof())
  64.         {
  65.             fluxsortie >> tabPays[i] >> tabCoutInit[i];
  66.             if (!fluxsortie.eof())
  67.             {
  68.                 i++;
  69.             }
  70.         }
  71.     }
  72.     else
  73.     {
  74.         return -1;
  75.     }
  76.  
  77.     return i;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement