Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. 1.
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. namespace arytmetyczne
  7. {
  8. float dodaj(float a, float b)
  9. {
  10. return a+b;
  11. }
  12.  
  13. float odejmij(float a, float b)
  14. {
  15. return a-b;
  16. }
  17. float pomnoz(float a, float b)
  18. {
  19. return a*b;
  20. }
  21. float podziel(float a, float b)
  22. {
  23. return a/b;
  24. }
  25. float modulo(int a, int b)
  26. {
  27. return a%b;
  28. }
  29. float wczytaj()
  30. {
  31. float a;
  32. cout << "Podaj liczbe: ";
  33. cin >> a;
  34. return a;
  35. }
  36. int float_to_int(float *a)
  37. {
  38. return *a;
  39. }
  40. }
  41. using namespace arytmetyczne;
  42. void kalkulator(float a, float b)
  43. {
  44. cout << "Dzialania"<<endl;
  45. cout << "a+b: "<< dodaj(a,b)<<endl;
  46. cout << "a-b: "<< odejmij(a,b)<<endl;
  47. cout << "a*b: "<< pomnoz(a,b)<<endl;
  48. cout << "a/b: "<< podziel(a,b)<<endl;
  49. cout << "a%b: "<< modulo(float_to_int(&a),float_to_int(&b))<<endl;
  50. }
  51.  
  52. int main()
  53. {
  54.  
  55.  
  56. float a, b;
  57. cout << "Wczytywanie a"<<endl;
  58. a=wczytaj();
  59. cout << "Wczytywanie b"<<endl;
  60. b=wczytaj();
  61. cout << endl;
  62. kalkulator(a,b);
  63. return 0;
  64. }
  65. 2.
  66. #include <iostream>
  67. #include <conio.h>
  68. using namespace std;
  69.  
  70. int norma(int **t, int n, int m, int b=119)
  71. {
  72. if(b==119)
  73. {
  74. int maxi=0;
  75. for(int i=0; i<m; i++)
  76. {
  77. int norma=0;
  78. for(int j=0; j<n; j++)
  79. {
  80. norma += t[j][i];
  81. }
  82. if(norma>maxi)
  83. maxi=norma;
  84. }
  85. return maxi;
  86. }
  87. else
  88. {
  89. int maxi=0;
  90. for(int i=0; i<n; i++)
  91. {
  92. int norma=0;
  93. for(int j=0; j<m; j++)
  94. {
  95. norma+=t[i][j];
  96. }
  97. if(norma>maxi)
  98. maxi=norma;
  99. }
  100. return maxi;
  101. }
  102. }
  103.  
  104. void podaj_wielkosc(int *n, int *m)
  105. {
  106. cout << "Podaj ilosc wierszy: ";
  107. cin >> *n;
  108. cout << "Podaj ilosc kolumn: ";
  109. cin >> *m;
  110. }
  111. void podaj_tablice(int **t, int n, int m)
  112. {
  113. for(int i=0; i<m; i++)
  114. for(int j=0; j<n; j++)
  115. {
  116. cout << "["<<i+1<<"]["<<j+1<<"]: ";
  117. cin >> t[i][j];
  118. }
  119. }
  120.  
  121. int main()
  122. {
  123. int n,m;
  124. int **tab;
  125. podaj_wielkosc(&n, &m);
  126. tab = new int*[m];
  127. for(int i=0; i<m; i++)
  128. tab[i]= new int[n];
  129. podaj_tablice(tab, n,m);
  130. int wybor;
  131. cout << "Mam liczyc z wierszy(w) czy z kolumn(k)?? ";
  132. wybor=getch();
  133. cout << endl;
  134. if(wybor==119||wybor==107)
  135. {
  136. cout << "Norma: "<<norma(tab, n, m, wybor);
  137. }
  138. else
  139. {
  140. cout << "Norma: "<<norma(tab, n, m);
  141. }
  142. return 0;
  143. }
  144. 3.
  145. #include <iostream>
  146. using namespace std;
  147. #include "drugi.h"
  148.  
  149. int main()
  150. {
  151. int n;
  152. towary *t;
  153. cin >> n;
  154. t = new towary[n];
  155. w_tablica(n, t);
  156. wypisz_nazwa(n, t);
  157. wypisz_naj(n, t);
  158. return 0;
  159. }
  160. h.
  161. struct towary
  162. {
  163. string nazwa;
  164. string dostawca;
  165. float cena;
  166. };
  167.  
  168. void w_tablica(int n, towary *t)
  169. {
  170. for(int i=0; i<n; i++)
  171. {
  172. cin >> t[i].nazwa;
  173. cin >> t[i].dostawca;
  174. cin >> t[i].cena;
  175. }
  176. }
  177.  
  178. void wypisz_nazwa(int n, towary *t)
  179. {
  180. string nazwa;
  181. cin >> nazwa;
  182. for(int i=0; i<n; i++)
  183. if(t[i].nazwa==nazwa)
  184. cout << t[i].nazwa<<" "<<t[i].dostawca<<" "<<t[i].cena<<endl;
  185. }
  186.  
  187. void wypisz_naj(int n, towary *t)
  188. {
  189. string nazwa;
  190. cin >> nazwa;
  191. float najmiejsza=1000000;
  192. int naj;
  193. for(int i=0; i<n; i++)
  194. if(t[i].nazwa==nazwa&&najmiejsza>t[i].cena)
  195. naj = i;
  196. cout << t[naj].nazwa<<" "<<t[naj].dostawca<<" "<<t[naj].cena;
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement