Advertisement
Guest User

Zadanie#9

a guest
Apr 6th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cctype>
  5. #include <cstdlib>
  6. #include <cstring>
  7.  
  8.  
  9. using namespace std;
  10. struct wplacajacy
  11. {
  12.     string nazwisko;
  13.     double kwota = 0;
  14. };
  15.  
  16. int main()
  17. {
  18.  
  19.     // zapis do pliku
  20.     string dane;    
  21.     ofstream outFile;
  22.     outFile.open("file.txt");
  23.     cout << "Podaj dane do pliku('-+' konczy wprowadzanie):  ";
  24.     cout << "\n1. Wartosc - liczba sposorow [enter]";
  25.     cout << "\n2. Wartosc - Sponsor[enter]";
  26.     cout << "\n3. Wartosc - Wplata[enter]";
  27.     cout << "\n4. Krok 2 i 3 powtorzyc n razy.\n";
  28.     getline(cin, dane,'+');
  29.     outFile << dane;
  30.     outFile.close();
  31.  
  32.     //odczyt z pliku
  33.     ifstream inFile;
  34.     string dane2;
  35.     inFile.open("file.txt");
  36.     if (!inFile.is_open())
  37.     {
  38.         cout << "Otwarcie pliku nie powiodlo sie!";
  39.         cout << "\nProgram zostanie zakonczony.\n";
  40.         exit(EXIT_FAILURE);
  41.     }    
  42.     getline(inFile, dane2, '+');
  43.     inFile.close();
  44.  
  45.     //cout << "Cale dane2: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! = " <<dane2;    //wyświetla dane2 zgadza sie
  46.  
  47.  
  48.     int licznik;
  49.     int n = atoi(dane2.c_str());    // JAK TO DZIALA???? Ale dziala..
  50.     licznik = n;
  51.     wplacajacy* osoba = new wplacajacy[n];
  52.    
  53.     //cout << "Zmienna n = " << n;  //wyswietla tyle ile powinna czyli pierwsza wprowadzona dana
  54.  
  55.     int sn = dane2.length();
  56.     cout << "Oto dane2[1] = " << dane2[1];
  57.     //cout << "Oto dane2[2] = " << dane2[2];    //dane2[2] to 1 litera wprowadzonego imienia zgadza sie
  58.  
  59.     int q = 1;
  60.     for (int i = 0; i < n; i++)
  61.     {
  62.         while(dane2[q] != '-')
  63.         {            
  64.         if (dane2[q] == NULL || dane2[q] == ' ' || dane2[q] == dane2[1])    //
  65.         {
  66.             cout << "NULL SIE WYKONAL" << endl;
  67.             q++;
  68.         }
  69.         else if (isalpha(dane2[q]))
  70.         {
  71.             string czlonek;
  72.             int czloneklicz = 0;
  73.             while (dane2[q] != NULL)
  74.             {
  75.                 czlonek[czloneklicz] = dane2[q];
  76.                 q++;
  77.                 czloneklicz++;                                
  78.                 //cout << osoba[i].nazwisko;
  79.             }
  80.             cout << "OTO CZLONEK: " << czlonek;
  81.             osoba[i].nazwisko = czlonek;
  82.         }
  83.         else if (isdigit(dane2[q]))
  84.         {
  85.             string pieniandz;
  86.             int pieniandzlicz = 0;
  87.             while (dane2[q] != NULL)
  88.             {
  89.                 pieniandz[pieniandzlicz] = dane2[q];
  90.                 pieniandzlicz++;                
  91.                 q++;
  92.                 //cout << osoba[i].kwota;
  93.             }
  94.             cout << "OTO PIENIANDZ: " << pieniandz;
  95.             osoba[i].kwota = stod(pieniandz);
  96.             if (dane2[q] == NULL)
  97.             {
  98.                 break;
  99.             }
  100.         }
  101.         else
  102.         {
  103.             cout << "Oto arr[q] = " << dane2[q];
  104.             cout << "Co sie dzieje O:O?";
  105.             break;
  106.         }
  107.         }      
  108.     }
  109.  
  110.    
  111.     for (int i = 0; i < n; i++)
  112.     {
  113.         cout << "Osoba:" << osoba[i].nazwisko << " z kwota: " << osoba[i].kwota << endl;
  114.     }
  115.     /*
  116.     int z = 0;
  117.     cout << "\nNasi Najwspanialszy Sponsorzy:\n";
  118.     for (int i = 0; i < n; i++)
  119.     {
  120.         if (osoba[i].kwota >= 10000)
  121.         {
  122.             cout << osoba[i].nazwisko << " z kwota: " << osoba[i].kwota << endl;
  123.             licznik--;
  124.         }
  125.         if (z == 0)
  126.         {
  127.             cout << "\nNasi wspaniali sponsorzy:\n";
  128.             z++;
  129.         }
  130.         else if (osoba[i].kwota < 10000 && osoba[i].kwota > 0)
  131.         {
  132.             cout << osoba[i].nazwisko << " z kwota: " << osoba[i].kwota << endl;
  133.             licznik--;
  134.         }
  135.     }
  136.     for (int i = 0; i < licznik; i++)
  137.     {
  138.         cout << "---Brak---" << endl;
  139.     }
  140.     */
  141. }
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement