Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Algorytmy.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- #include<fstream>
- #include<string>
- #include<cstdlib>
- using namespace std;
- struct dane
- {
- string id;
- float kwota;
- };
- int main()
- {
- ifstream infile;
- ofstream outfile;
- const int N = 5;
- dane* tab = new dane[N];
- string id;
- string kwota;
- dane pom;
- infile.open("pracownicy.txt");
- outfile.open("wynik.txt");
- if (!infile.is_open())
- {
- return 0;
- }
- else
- {
- int x = 0;
- while (!infile.eof())
- {
- getline(infile, id);
- getline(infile, kwota);
- for (int j = 0; j < N; j++)
- {
- if (tab[j].id == id)
- {
- tab[j].id = id;
- tab[j].kwota += stof(kwota.c_str());
- }
- else
- {
- tab[j].id = id;
- tab[j].kwota = stof(kwota.c_str());
- }
- }
- for (int i = 0; i < N; i++)
- {
- for (int j = N - 1; j > 0; j--)
- {
- if (tab[j].id < tab[j - 1].id)
- {
- tab[j] = pom;
- tab[j] = tab[j - 1];
- tab[j - 1] = pom;
- }
- }
- }
- for (int i = 0; i < N; i++)
- {
- outfile << tab[i].id << endl;
- outfile << tab[i].kwota << endl;
- }
- outfile.close();
- infile.close();
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement