Guest User

Untitled

a guest
Aug 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. // Ernest Bursa 2010
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. // Maksimum
  9. float max(int t[], int n){
  10. float max = (float)t[0];
  11. for(int i = 1; i < n; i++)
  12. if(t[i]>max)
  13. max = (float)t[i];
  14. return max;
  15. }
  16.  
  17. // Minimum
  18. float min(int t[], int n){
  19. int min = (float)t[0];
  20. for(int i = 1; i < n; i++)
  21. if(t[i]<min)
  22. min = (float)t[i];
  23. return min;
  24. }
  25.  
  26. // Średnia
  27. float avg(int t[], int n){
  28. float avg = 0;
  29. for(int i=0;i<n;i++){
  30. avg += (float)t[i];
  31. }
  32. avg = avg/(float)n;
  33. return avg;
  34. }
  35.  
  36. // Suma
  37. float sum(int t[], int n){
  38. float sum = (float)0;
  39. for(int i = 0; i<n; i++)
  40. sum+=(float)t[i];
  41. return sum;
  42. }
  43.  
  44. // Statystyki
  45. void staty(int t[], int n, float *maxi, float *mini, float *sumi, float *avgi){
  46. *maxi = max(t, n);
  47. *mini = min(t, n);
  48. *sumi = sum(t, n);
  49. *avgi = avg(t, n);
  50. }
  51.  
  52. // Suma macierzy
  53. void sum_matrix(int m, int n, int **matrix1, int **matrix2, int **matrix3){
  54. for(int i = 0; i<m; i++)
  55. for(int j = 0; j<n; j++)
  56. matrix1[i][j] = matrix2[i][j] + matrix3[i][j];
  57. }
  58.  
  59. // Odejmowanie macierzy
  60. void minus_matrix(int m, int n, int **matrix1, int **matrix2, int **matrix3){
  61. for(int i=0; i < m; i++)
  62. for(int j=0; j < n; j++)
  63. matrix1[i][j] = matrix2[i][j]-matrix3[i][j];
  64. }
  65.  
  66. // Mnożenie macierzy
  67. void multi_matrix(int m, int n, int **matrix1, int **matrix2, int **matrix3){
  68. for(int i=0; i<m; i++)
  69. for(int j=0; j<n; j++)
  70. matrix1[i][j] = matrix2[i][j]*matrix3[i][j];
  71. }
  72.  
  73. // ToDo: Wczytywanie wektora
  74. void read_vector(int *vector){
  75. int n, tmp_value;
  76. cout << "Wprowadz dlugosc wektora: ";
  77. cin >> n;
  78. cout << "\nWprowadz kolejno wartosci wektora: ";
  79. for(int i=0; i<n;i++){
  80. cin >> tmp_value;
  81. vector[i] = tmp_value;
  82. }
  83. }
  84.  
  85. // ToDo: Wczytywanie macierzy
  86. void read_matrix(int **matrix){
  87. int m,n, tmp_value;
  88. cout << "Podaj wymiar m: ";
  89. cin >> m;
  90. cout << "\nPodaj wymiar n: ";
  91. cin >> n;
  92.  
  93. for(int i=0; i<n; i++)
  94. matrix[i] = new int[n];
  95.  
  96. for(int i=0; i<m; i++){
  97. for(int j=0; j<n; j++){
  98. cout << "Wprowadz wartosc: ";
  99. cin >> tmp_value;
  100. matrix[i][j] = tmp_value;
  101. cout << "\n";
  102. }
  103. }
  104. }
  105.  
  106. // Wyświetlanie wczytanego wektora
  107. void display_vector(int t[], int n){
  108. cout << "Wyswietlam wczytany wektor: [";
  109. for(int i=0; i<n; i++){
  110. cout << t[i];
  111. if(i!=(n-1))
  112. cout << ", ";
  113. }
  114. cout << "]";
  115. }
  116.  
  117. // Wyświetlanie wczytanej macierzy
  118. void display_matrix(int m, int n, int **matrix1){
  119. cout << "Wyświetlam wczytaną macierz: [";
  120. for(int i=0; i<m; i++){
  121. for(int j=0; j<n; j++){
  122. cout << matrix1[i][j];
  123. if(j!=(n-1))
  124. cout << ", ";
  125. }
  126. cout << "\n";
  127. }
  128. }
  129.  
  130.  
  131. int main(int argc, char**argv)
  132. {
  133. bool loop = 1;
  134. while(loop){
  135. cout << "| Menu: \n";
  136. cout << "- [1] - Min \n";
  137. cout << "- [2] - Max \n";
  138. cout << "- [3] - Avg \n";
  139. cout << "- [4] - Statystyka \n";
  140. cout << "- [5] - Suma macierzy \n";
  141. cout << "- [6] - Odejmowanie macierzy \n";
  142. cout << "- [7] - Mnozenie macierzy \n";
  143.  
  144. cout << "-----------------------------------\n";
  145. cout << "Na dobry poczatek wylosowalem tablice [";
  146.  
  147. int n = 5;
  148. int *tablica = new int[n];
  149.  
  150. for(int i=0; i<n; i++){
  151. tablica[i] = rand() % 25 + 3;
  152. cout << tablica[i];
  153. if(i+1!=n)
  154. cout << ", ";
  155. }
  156.  
  157. // Można alternatywnie użyć gotowej funkcji display_vector()
  158.  
  159. cout << "]\n-----------------------------------\n";
  160. cout << "\n Wybierz opcje nr: ";
  161.  
  162. int input;
  163. cin >> input;
  164. cout << "\n\n";
  165. switch(input){
  166.  
  167. case 1:
  168. cout << "Min: " << min(tablica, n) << "\n";
  169. break;
  170.  
  171. case 2:
  172. cout << "Max: " << max(tablica, n) << "\n";
  173. break;
  174.  
  175. case 3:
  176. cout << "Avg: " << avg(tablica, n) << "\n";
  177. break;
  178.  
  179. case 4:
  180. cout << "Statystyka: ";
  181. float maxi, mini, sumi, avgi;
  182. staty(tablica, n, &maxi, &mini, &sumi, &avgi);
  183.  
  184. cout << "Min: " << mini << "\n";
  185. cout << "Max: " << maxi << "\n";
  186. cout << "Suma: " << sumi << "\n";
  187. cout << "Avg: " << avgi << "\n";
  188.  
  189. break;
  190.  
  191. case 5: // Suma macierzy
  192.  
  193. break;
  194.  
  195. case 6: // Odejmowanie macierzy
  196.  
  197. break;
  198.  
  199. case 7: // Mnozenie macierzy
  200.  
  201. break;
  202.  
  203. default:
  204. loop = 0;
  205. break;
  206.  
  207. }
  208. cout << "\n-----------------------------------\n";
  209. }
  210.  
  211. cin.get();
  212. return 0;
  213. }
Add Comment
Please, Sign In to add comment