Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. // Algorytmy.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include<iostream>
  6. #include<fstream>
  7. #include<string>
  8. #include<cstdlib>
  9. using namespace std;
  10. struct dane
  11. {
  12.     string id;
  13.     float kwota;
  14. };
  15. int main()
  16. {
  17.     ifstream infile;
  18.     ofstream outfile;
  19.     const int N = 5;
  20.     dane* tab = new dane[N];
  21.     string id;
  22.     string kwota;
  23.     dane pom;
  24.  
  25.     infile.open("pracownicy.txt");
  26.     outfile.open("wynik.txt");
  27.     if (!infile.is_open())
  28.     {
  29.         return 0;
  30.     }
  31.     else
  32.     {
  33.         int x = 0;
  34.         while (!infile.eof())
  35.         {
  36.            
  37.                 getline(infile, id);
  38.                 getline(infile, kwota);
  39.                 for (int j = 0; j < N; j++)
  40.                 {
  41.                     if (tab[j].id == id)
  42.                     {
  43.                         tab[j].id = id;
  44.                         tab[j].kwota += stof(kwota.c_str());
  45.                     }
  46.                     else
  47.                     {
  48.                         tab[j].id = id;
  49.                         tab[j].kwota = stof(kwota.c_str());
  50.                     }
  51.                 }
  52.  
  53.        
  54.             for (int i = 0; i < N; i++)
  55.             {
  56.                 for (int j = N - 1; j > 0; j--)
  57.                 {
  58.                     if (tab[j].id < tab[j - 1].id)
  59.                     {
  60.                         tab[j] = pom;
  61.                         tab[j] = tab[j - 1];
  62.                         tab[j - 1] = pom;
  63.                     }
  64.                 }
  65.             }
  66.             for (int i = 0; i < N; i++)
  67.             {
  68.                 outfile << tab[i].id << endl;
  69.                 outfile << tab[i].kwota << endl;
  70.             }
  71.             outfile.close();
  72.             infile.close();
  73.             return 0;
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement