Advertisement
Guest User

futar.cpp

a guest
May 18th, 2012
1,156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. struct fuvar{
  6.     int nap;
  7.     int sorszam;
  8.     int tav;
  9. };
  10. int ar(int tav)
  11. {
  12.     if(tav<=2) return 500;
  13.     if(tav<=5) return 700;
  14.     if(tav<=10) return 900;
  15.     if(tav<=20) return 1400;
  16.     return 2000;
  17. }
  18.  
  19. int main(int argc, char **argv)
  20. {
  21.     fuvar ft[300]; // eleg lenne 280 is
  22.     int napok[8]={0}, tavok[8]={0}; // eleg lenne 7 is
  23.     ifstream be;
  24.     be.open("tavok.txt");
  25.     int db=0;
  26.     while(be >> ft[db].nap >> ft[db].sorszam >> ft[db].tav)
  27.     {
  28.         napok[ft[db].nap]++; // 4. és 5. feladathoz
  29.         tavok[ft[db].nap]+=ft[db].tav; // 6. feladathoz
  30.         db++;
  31.     }
  32.     be.close();
  33.     // rendezés a 2. és 3. feladathoz
  34.     for(int i=0; i<db-1; i++)
  35.     {
  36.         for(int j=0; j<db-i; j++)
  37.         {
  38.             if( (ft[j].nap>ft[j+1].nap) or ((ft[j].nap==ft[j+1].nap) and (ft[j].sorszam>ft[j+1].sorszam)) )
  39.             {
  40.                 swap(ft[j], ft[j+1]);
  41.             }
  42.         }
  43.     }
  44.     cout << "F2: " << ft[0].tav << endl;
  45.     cout << "F3: " << ft[db-1].tav << endl;
  46.     cout << "F4: ";
  47.     int maxnap=1;
  48.     for(int i=1; i<=7; i++)
  49.     {
  50.         if(napok[i]==0) { cout << i << " ";}
  51.         if(napok[i]>napok[maxnap]) { maxnap=i; }
  52.     }
  53.     cout << endl;
  54.     cout << "F5: " << maxnap << endl;
  55.     cout << "F6: ";
  56.     for(int i=1; i<=7; i++)
  57.     {
  58.         cout << i << ".nap: " << tavok[i] << " km" << endl;
  59.     }
  60.     cout << "F7: Add meg a tavot! ";
  61.     int tavolsag;
  62.     cin >> tavolsag;
  63.     cout << ar(tavolsag) << endl;
  64.     ofstream ki;
  65.     ki.open("dijazas.txt");
  66.     int osszeg=0;
  67.     for(int i=0; i<db; i++)
  68.     {
  69.         ki << ft[i].nap << ". nap " << ft[i].sorszam << ". ut " << ar(ft[i].tav) << " Ft" << endl;
  70.         osszeg+=ar(ft[i].tav);
  71.     }
  72.     ki.close();
  73.     cout << "F9: " << osszeg << endl;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement