Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #define rozmiar 5
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9. /*Zdefiniuj typ strukturalny oraz 100-elementową tablicę
  10. pozwalającą przechowywać informacje o książkach w bibliotece
  11. (tytuł, autor, indeks, cena) oraz napisz funkcję, która wyświetli na ekranie
  12. wszystkie dane tanich książek (tzn. cena<10zł)*/
  13.  
  14. struct ksiazka
  15. {
  16.     char tytul[50];
  17.     char autor[32];
  18.     unsigned int indeks;
  19.     double cena;
  20. };
  21.  
  22. void wypisanie(ksiazka books[]);
  23.  
  24.  
  25. int main()
  26. {
  27.     ksiazka books[rozmiar];
  28.  
  29.     for (int i = 0; i < rozmiar; i++)
  30.     {
  31.         books[i].indeks = i + 1;
  32.         cout << "Podaj tytul " << i + 1 << " ksiazki : ";
  33.         cin.getline(books[i].tytul, 50);
  34.         cout << "Podaj autora " << i + 1 << " ksiazki : ";
  35.         cin.getline(books[i].autor, 32);
  36.         cout << "Podaj cene " << i + 1 << " ksiazki : ";
  37.         cin >> books[i].cena;
  38.         cin.ignore(INT_MAX, '\n');
  39.         system("cls");
  40.     }
  41.  
  42.     wypisanie(books);
  43.  
  44.     system("pause");
  45.     return 0;
  46. }
  47.  
  48.  
  49. void wypisanie(ksiazka books[])
  50. {
  51.     cout << "Wszystkie tanie ksiazki (<10zl) :\n";
  52.     for (int i = 0; i < rozmiar && books[i].cena < 10; i++)
  53.     {
  54.         cout << "\"" << books[i].tytul << "\" autorstwa " << books[i].autor << ". Cena - " << books[i].cena << " zl." << endl;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement