Advertisement
wa12rior

asdasdas

Nov 26th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. struct Piosenki {
  7.         string tytul, autor, gatunek;
  8.         float czas;
  9.         int ocena;
  10.        
  11.         void sprawdz() {
  12.                 if (ocena < 1 || ocena > 5) {
  13.                         ocena = 1;
  14.                 }
  15.         }
  16.         void pokaz() {
  17.                 cout << "Tytul: " << tytul <<  " - " << "Autor: " << autor << " - " << "Gatunek: " << gatunek << " - " << "Czas: " << czas << " - " << "Ocena: " << ocena << endl << endl;
  18.         }
  19. };
  20.  
  21. class Klient {
  22.         private:
  23.                 string imie, nazwisko;
  24.                 int indeks;
  25.  
  26.         public:
  27.                 int id;
  28.                 const int plimit = 3;
  29.                 int licz_piosenke;
  30.                 Klient() {};
  31.  
  32.                 Klient(int idx, string a, string b) {
  33.                         imie = a;
  34.                         nazwisko = b;
  35.                         indeks = idx;
  36.                 }
  37.                
  38.                 Klient & operator =(Klient &klient) {
  39.                     Klient kl;
  40.                     kl.set_indeks(klient.get_indeks());
  41.                     kl.set_nazwisko(klient.get_nazwisko());
  42.                     kl.set_imie(klient.get_imie());
  43.                    
  44.                     return kl;
  45.                 }
  46.  
  47.                 Piosenki* piosenka = new Piosenki[plimit];    
  48.                
  49.                 string get_imie() {
  50.                         return imie;
  51.                 }
  52.                 string get_nazwisko() {
  53.                         return nazwisko;
  54.                 }
  55.                 int get_indeks() {
  56.                         return indeks;
  57.                 }
  58.                
  59.                 void set_imie(string i) {
  60.                         imie = i;
  61.                 }
  62.                 void set_nazwisko(string n) {
  63.                         nazwisko = n;
  64.                 }
  65.                 void set_indeks(int in) {
  66.                         indeks = in;
  67.                 }  
  68.  
  69.                 void name() {
  70.                         cout << "Imie: " << imie << " | Nazwisko: " << nazwisko << " | Indeks: " << indeks << " - Ilosc dodanych piosenek wynosi = " << licz_piosenke << endl << endl;
  71.                 }
  72.                
  73.                 void dodaj_piosenke();
  74.                 void pokaz_piosenke();
  75. };
  76.  
  77. class Klienci : public Klient{
  78.         friend class Klient;
  79.         public:
  80.                 const int Limit = 1;
  81.                 int licz_klienta = 0;
  82.                 int indeks_klienta = 0;
  83.  
  84.                 Klient *klci = new Klient[Limit];
  85.  
  86.                 int liczba_klientow() {
  87.                         cout << "Ilosc dodanych klientow wynosi = ";
  88.                         return licz_klienta;
  89.                         cout << endl;
  90.                 }
  91.                 int liczba_piosenek() {
  92.                         cout << "Ilosc dodanych piosenek wynosi = ";
  93.                         return licz_piosenke;
  94.                 }
  95.                
  96.                 void dodaj_klienta(const Klient &);
  97.  
  98.                 //void sortuj_ponazwisku();
  99.  
  100.                 Klienci() {};
  101. };
  102. /*
  103. void Klienci::sortuj_ponazwisku() {
  104.         cout << "Sortowanie" << endl;
  105.         for (int i = 0; i < licz_klienta; i++) {
  106.                 tab->name();
  107.                 *tab++;
  108.         }
  109. }
  110. */
  111.  
  112. void Klienci::dodaj_klienta(Klient * klient) {
  113.     klci[indeks_klienta] = klient;
  114.     indeks_klienta++;
  115. }
  116.  
  117. void Klient::dodaj_piosenke() {
  118.        
  119.         string check = "";
  120.         cout << "DODAJ PIOSENKE " << endl;
  121.         for (int i = 0; i < plimit; i++) {
  122.                 cout << "Podaj tytul: ";
  123.                 cin >> piosenka[i].tytul;
  124.                 cout << "Podaj autora: ";
  125.                 cin >> piosenka[i].autor;
  126.                 cout << "Podaj gatunek: ";
  127.                 cin >> piosenka[i].gatunek;
  128.                 cout << "Podaj czas trwania: ";
  129.                 cin >> piosenka[i].czas;
  130.                 cout << "Podaj ocene: ";
  131.                 cin >> piosenka[i].ocena;
  132.                 cout << endl;
  133.                                
  134.                 piosenka[i].sprawdz();
  135.  
  136.                 if (i < plimit-1) {
  137.                         cout << "CZY CHCESZ DODAC PIOSENKE? Wpisz 'tak' lub 'nie'." << endl;
  138.                         cin >> check;
  139.                 }                                              
  140.                
  141.                 licz_piosenke++;
  142.  
  143.                 if (check == "nie") {
  144.                         break;
  145.                 }                      
  146.         }      
  147. }
  148.  
  149. void Klient::pokaz_piosenke() {
  150.         for (int i = 0; i < licz_piosenke; i++) {
  151.                 cout << "Piosenka " << i+1 << " | ";
  152.                
  153.                 piosenka[i].pokaz();
  154.  
  155.         }
  156. }
  157.  
  158. int main() {
  159.         Klienci nowi;
  160.         string q, w;
  161.         cout << "DODAJ KLIENTA" << endl;
  162.         for (int i = 0; i < nowi.Limit; i++) {
  163.                 cout << "Podaj imie: ";
  164.                 cin >> q;
  165.                 cout << "Podaj nazwisko: ";
  166.                 cin >> w;
  167.                 cout << endl;
  168.                 Klient kl(nowi.indeks_klienta, q, w);
  169.                 nowi.dodaj_klienta(kl);
  170.         }
  171.         cout << nowi.liczba_klientow() << endl;
  172.         cout << nowi.liczba_piosenek() << endl;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement