Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cctype>
- #include <cstdlib>
- #include <cstring>
- using namespace std;
- struct wplacajacy
- {
- string nazwisko;
- double kwota = 0;
- };
- int main()
- {
- // zapis do pliku
- string dane;
- ofstream outFile;
- outFile.open("file.txt");
- cout << "Podaj dane do pliku('-+' konczy wprowadzanie): ";
- cout << "\n1. Wartosc - liczba sposorow [enter]";
- cout << "\n2. Wartosc - Sponsor[enter]";
- cout << "\n3. Wartosc - Wplata[enter]";
- cout << "\n4. Krok 2 i 3 powtorzyc n razy.\n";
- getline(cin, dane,'+');
- outFile << dane;
- outFile.close();
- //odczyt z pliku
- ifstream inFile;
- string dane2;
- inFile.open("file.txt");
- if (!inFile.is_open())
- {
- cout << "Otwarcie pliku nie powiodlo sie!";
- cout << "\nProgram zostanie zakonczony.\n";
- exit(EXIT_FAILURE);
- }
- getline(inFile, dane2, '+');
- inFile.close();
- //cout << "Cale dane2: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! = " <<dane2; //wyświetla dane2 zgadza sie
- int licznik;
- int n = atoi(dane2.c_str()); // JAK TO DZIALA???? Ale dziala..
- licznik = n;
- wplacajacy* osoba = new wplacajacy[n];
- //cout << "Zmienna n = " << n; //wyswietla tyle ile powinna czyli pierwsza wprowadzona dana
- int sn = dane2.length();
- cout << "Oto dane2[1] = " << dane2[1];
- //cout << "Oto dane2[2] = " << dane2[2]; //dane2[2] to 1 litera wprowadzonego imienia zgadza sie
- int q = 1;
- for (int i = 0; i < n; i++)
- {
- while(dane2[q] != '-')
- {
- if (dane2[q] == NULL || dane2[q] == ' ' || dane2[q] == dane2[1]) //
- {
- cout << "NULL SIE WYKONAL" << endl;
- q++;
- }
- else if (isalpha(dane2[q]))
- {
- string czlonek;
- int czloneklicz = 0;
- while (dane2[q] != NULL)
- {
- czlonek[czloneklicz] = dane2[q];
- q++;
- czloneklicz++;
- //cout << osoba[i].nazwisko;
- }
- cout << "OTO CZLONEK: " << czlonek;
- osoba[i].nazwisko = czlonek;
- }
- else if (isdigit(dane2[q]))
- {
- string pieniandz;
- int pieniandzlicz = 0;
- while (dane2[q] != NULL)
- {
- pieniandz[pieniandzlicz] = dane2[q];
- pieniandzlicz++;
- q++;
- //cout << osoba[i].kwota;
- }
- cout << "OTO PIENIANDZ: " << pieniandz;
- osoba[i].kwota = stod(pieniandz);
- if (dane2[q] == NULL)
- {
- break;
- }
- }
- else
- {
- cout << "Oto arr[q] = " << dane2[q];
- cout << "Co sie dzieje O:O?";
- break;
- }
- }
- }
- for (int i = 0; i < n; i++)
- {
- cout << "Osoba:" << osoba[i].nazwisko << " z kwota: " << osoba[i].kwota << endl;
- }
- /*
- int z = 0;
- cout << "\nNasi Najwspanialszy Sponsorzy:\n";
- for (int i = 0; i < n; i++)
- {
- if (osoba[i].kwota >= 10000)
- {
- cout << osoba[i].nazwisko << " z kwota: " << osoba[i].kwota << endl;
- licznik--;
- }
- if (z == 0)
- {
- cout << "\nNasi wspaniali sponsorzy:\n";
- z++;
- }
- else if (osoba[i].kwota < 10000 && osoba[i].kwota > 0)
- {
- cout << osoba[i].nazwisko << " z kwota: " << osoba[i].kwota << endl;
- licznik--;
- }
- }
- for (int i = 0; i < licznik; i++)
- {
- cout << "---Brak---" << endl;
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement