Advertisement
Freak187

zadania9

Dec 12th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.54 KB | None | 0 0
  1. Zadanie 1
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. struct osoba
  8.     {
  9.         char imie[10];
  10.         char nazwisko[20];
  11.         int wiek;
  12.     };
  13.  
  14.  
  15. int main()
  16. {
  17.     struct osoba os1;
  18.     cout << "Podaj imie: ";
  19.     cin >> os1.imie;
  20.     cout << "Podaj nazwisko: ";
  21.     cin >> os1.nazwisko;
  22.     cout << "Podaj wiek: ";
  23.     cin >> os1.wiek;
  24.     cout << "Imie: " << os1.imie << endl << "Nazwisko: " << os1.nazwisko << endl << "Wiek: " << os1.wiek;
  25.     return 0;
  26. }
  27.  
  28.  
  29.  
  30. Zadanie 2
  31.  
  32. #include <iostream>
  33. #include <cstring>
  34. #include <fstream>
  35.  
  36. using namespace std;
  37.  
  38. struct pies
  39.     {
  40.         char imie[10];
  41.         int wiek;
  42.         double masa;
  43.     };
  44.  
  45. pies set1()
  46. {
  47.     pies p1;
  48.     cout << "Podaj imie: ";
  49.     cin >> p1.imie;
  50.     cout << "Podaj wiek: ";
  51.     cin >> p1.wiek;
  52.     cout << "Podaj mase: ";
  53.     cin >> p1.masa;
  54.     return p1;
  55. }
  56.  
  57. pies set2(char imie[10], int wiek, double masa)
  58. {
  59.     pies p2;
  60.     strncpy(p2.imie, imie, 10);
  61.     p2.wiek=wiek;
  62.     p2.masa=masa;
  63.     return p2;
  64. }
  65.  
  66. void get1(pies p)
  67. {
  68.     cout << "Pies " << p.imie << " ma " << p.wiek << " lat(a) i wazy " << p.masa << " kg." << endl;
  69. }
  70.  
  71. int main()
  72. {
  73.     pies pupile[3];
  74.     pupile[0]=set1();
  75.     pupile[1]=set2("Burek", 10, 30);
  76.     pupile[2]=set2("Reksio", 5, 25);
  77.     for(int i=0;i<3;i++)
  78.     {
  79.         get1(pupile[i]);
  80.     }
  81.     ofstream plik("plik.txt", ios::out);
  82.     plik << pupile[0].imie << endl <<pupile[1].imie << endl << pupile[2].imie;
  83.     plik.close();
  84.     return 0;
  85. }
  86.  
  87.  
  88.  
  89. Zadanie 3
  90.  
  91.  
  92.  
  93. #include <iostream>
  94. #include <cstring>
  95. #include <fstream>
  96.  
  97. using namespace std;
  98.  
  99. struct Pisarz
  100.     {
  101.         int rok_urodzenia;
  102.         char imie[12];
  103.         char nazwisko[20];
  104.     };
  105.  
  106. struct Ksiazka
  107. {
  108.     char tytul[20];
  109.     int rok_wydania;
  110.     Pisarz* autor;
  111. };
  112.  
  113. void getPisarz(Pisarz autor)
  114. {
  115.     cout << autor.imie << " " << autor.nazwisko << ", urodzony w " << autor.rok_urodzenia << " roku." <<endl;
  116. }
  117.  
  118. void getKsiazka(Ksiazka dzielo)
  119. {
  120.     cout << "Tytul: " << dzielo.tytul << ", Rok wydania: " << dzielo.rok_wydania << ", Autor: ";
  121.     getPisarz(*dzielo.autor);
  122. }
  123.  
  124. int main()
  125. {
  126.     Pisarz Autorzy[3]={{1140,"Gall","Anonim"},{1809,"Juliusz","Slowacki"},{1798,"Adam","Mickiewicz"}};
  127.     Ksiazka Pozycje[4]={{"Pan Tadeusz",1834,&Autorzy[2]},{"Ballady i romanse",1822,&Autorzy[2]},{"Balladyna",1834,&Autorzy[1]},{"Kordian",1833,&Autorzy[1]}};
  128.     for(int i=0;i<3;i++)
  129.     {
  130.         getPisarz(Autorzy[i]);
  131.     }
  132.     for(int i=0;i<4;i++)
  133.     {
  134.         getKsiazka(Pozycje[i]);
  135.     }
  136.     return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement