Advertisement
MarcinMolenda

Sprawdzian

Nov 20th, 2020 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.61 KB | None | 0 0
  1. Zadanie 1
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     float x = 25;
  10.     float *wsk_x;
  11.     wsk_x=&x;
  12.     *wsk_x = x * 10;
  13.     cout << *wsk_x;
  14.     return 0;
  15. }
  16.  
  17. Zadanie 2
  18.  
  19. #include <iostream>
  20.  
  21. using namespace std;
  22.  
  23. struct Posciel{
  24. float szerokosc;
  25. float dlugosc;
  26. string kolor;
  27. int cena;
  28. string producent;
  29. };
  30.  
  31. int main()
  32. {
  33.     Posciel posciel1;
  34.     posciel1.szerokosc=1.8;
  35.     posciel1.dlugosc=2.1;
  36.     posciel1.kolor="Zielony";
  37.     posciel1.cena=99;
  38.     posciel1.producent="PoscielPOL";
  39.     cout << "Szerokosc: " << posciel1.szerokosc << endl;
  40.     cout << "Dlugosc: " << posciel1.dlugosc << endl;
  41.     cout << "Kolor: " << posciel1.kolor << endl;
  42.     cout << "Cena: " << posciel1.cena << endl;
  43.     cout << "Producent: " << posciel1.producent << endl;
  44.  
  45.     return 0;
  46. }
  47.  
  48. Zadanie 3
  49.  
  50. #include <iostream>
  51.  
  52. using namespace std;
  53.  
  54. class Posciel{
  55. public:
  56. float szerokosc;
  57. float dlugosc;
  58. string kolor;
  59. int cena;
  60. string producent;
  61. void wyswietl()
  62. {
  63.     cout << "Szerokosc: " << szerokosc << endl;
  64.     cout << "Dlugosc: " << dlugosc << endl;
  65.     cout << "Kolor: " << kolor << endl;
  66.     cout << "Cena: " << cena << endl;
  67.     cout << "Producent: " << producent << endl;
  68. }
  69.  
  70. float oblicz_powierzchnie(float szerokosc, float dlugosc)
  71. {
  72.     float p;
  73.     if(szerokosc<=0)
  74.     {
  75.         cout << "Blad podana szerokosc jest mniejsza lub rowna zero";
  76.         return 0;
  77.     }
  78.     else if(dlugosc<=0)
  79.     {
  80.         cout << "Blad podana dlugosc jest mniejsza lub rowna zero";
  81.         return 0;
  82.     }
  83.     else
  84.     {
  85.     p = szerokosc * dlugosc;
  86.     cout << "Powierzchnia wynosi: "<<p;
  87.     return p;
  88.     }
  89.  
  90.  
  91. }
  92.  
  93. };
  94.  
  95. int main()
  96. {
  97.     Posciel posciel1;
  98.     posciel1.szerokosc=1.8;
  99.     posciel1.dlugosc=2.1;
  100.     posciel1.kolor="Zielony";
  101.     posciel1.cena=99;
  102.     posciel1.producent="PoscielPOL";
  103.  
  104.     posciel1.wyswietl();
  105.     posciel1.oblicz_powierzchnie(posciel1.szerokosc,posciel1.dlugosc);
  106.  
  107.     return 0;
  108. }
  109.  
  110. Zadanie 4
  111.  
  112. #include <iostream>
  113.  
  114. using namespace std;
  115.  
  116. class Posciel{
  117. public:
  118. float szerokosc;
  119. float dlugosc;
  120. string kolor;
  121. int cena;
  122. string producent;
  123.  
  124. Posciel(float, float, string, int, string)
  125. {
  126. cout << "Szerokosc: " << szerokosc << endl;
  127. cout << "Dlugosc: " << dlugosc << endl;
  128. cout << "Kolor: " << kolor << endl;
  129. cout << "Cena: " << cena << endl;
  130. cout << "Producent: " << producent << endl;
  131. }
  132. }
  133. Posciel::Posciel (float s, float d, string k, int c, string p)
  134. {
  135. szerokosc=s;
  136. dlugosc=d;
  137. kolor=k;
  138. cena=c;
  139. producent=p;
  140. }
  141.  
  142. int main()
  143. {
  144.     Posciel okno(1.8, 2.1, "Zielony", 99, "PoscielPOL");
  145.    
  146.     okno.wyswietl();
  147.     return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement