Advertisement
xTheEc0

3. Mokesčiai. (Vad 110psl.)

Jan 13th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. /*
  2. 4
  3. Rimas           2.5    13.0   -5.0
  4. Robertas        18.7   -13.95 -25.0
  5. Jurgis          -205.0 -36.0  -0.5
  6. Matas           58.45  50.16  14.45
  7. */
  8. #include <iostream>
  9. #include <cmath>
  10. #include <iomanip>
  11. #include <fstream>
  12. using namespace std;
  13.  
  14. const char duomF[] = "1.txt";
  15. const char rezF[] = "rez1.txt";
  16. const int CPav = 15;
  17. const int CMax = 51;
  18.  
  19. struct mokesciai
  20. {
  21.     string vardas;
  22.     double siluma;
  23.     double telefonas;
  24.     double vanduo;
  25.     double suma;
  26. };
  27.  
  28. void skaitymas(mokesciai A[], int &n)
  29. {
  30.     char eil[CPav+1];
  31.     ifstream df(duomF);
  32.     df >> n;
  33.     for (int i = 0; i < n; i++)
  34.     {
  35.         df.ignore(80, '\n');
  36.         df.get(eil, CPav);
  37.         A[i].vardas = eil;
  38.         df >> A[i].siluma >> A[i].telefonas >> A[i].vanduo;
  39.     }
  40.     df.close();
  41. }
  42.  
  43. void sprendimas(mokesciai A[], int n)
  44. {
  45.     double siluma = 0, telefonas = 0, vanduo = 0;
  46.  
  47.     for (int i = 0; i < n; i++) // Silumos suma
  48.     {
  49.         if (A[i].siluma >= 0)
  50.         {
  51.             siluma += A[i].siluma;
  52.             A[i].suma += A[i].siluma;
  53.         }
  54.     }
  55.     for (int i = 0; i < n; i++) // Telefono suma
  56.     {
  57.         if (A[i].telefonas >= 0)
  58.         {
  59.             telefonas += A[i].telefonas;
  60.             A[i].suma += A[i].telefonas;
  61.         }
  62.     }
  63.     for (int i = 0; i < n; i++) // Vandens suma
  64.     {
  65.         if (A[i].vanduo >= 0)
  66.         {
  67.             vanduo += A[i].vanduo;
  68.             A[i].suma += A[i].vanduo;
  69.         }
  70.     }
  71.  
  72.     cout << " " << endl;
  73.     cout << " ----------------------------------------- " << endl;
  74.     cout << " Uz siluma turi buti sumoketa:   " << siluma << endl;
  75.     cout << " Uz telefona turi buti sumoketa: " << telefonas << endl;
  76.     cout << " Uz vandeni turi buti sumoketa:  " << vanduo << endl;
  77.     cout << " ----------------------------------------- " << endl;
  78.     cout << " Vardas             Turi sumoketi          " << endl;
  79.     cout << " ----------------------------------------- " << endl;
  80.     for (int i = 0; i < n; i++)
  81.     {
  82.         if (A[i].suma != 0) cout << " " << A[i].vardas << "     " <<  A[i].suma << endl;
  83.     }
  84.     cout << " ----------------------------------------- " << endl;
  85.     cout << " " << endl;
  86. }
  87.  
  88. void reset (mokesciai A[])
  89. {
  90.     for (int i = 0; i < CMax; i++)
  91.     {
  92.         A[i].suma = 0;
  93.     }
  94. }
  95.  
  96. int main ()
  97. {
  98.     mokesciai A[CMax];
  99.     int n;
  100.  
  101.     reset(A);
  102.     skaitymas(A, n);
  103.     sprendimas(A, n);
  104.  
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement