AnasB

D&A w/ cpp min / max class

Oct 22nd, 2021
745
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Pseudo-Code
  2. //min of set element
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int minOfTheSet();
  7.  
  8. int const n = 5;
  9. int A[n]; // int * a;
  10.  
  11. void main() {
  12.     cout << "Type set of elements\n";
  13.     for (int i = 0; i < n; i++) {
  14.         cin >> A[i];
  15.     }
  16.     cout << minOfTheSet() << endl;
  17.     system("pause");
  18. }
  19.  
  20. int minOfTheSet() {
  21.     int min = A[0];
  22.     for (int i = 1; i < n; i++) //n=5
  23.     {
  24.         cout << "min=" << min << " A[" << i << "]=" << A[i] << endl;
  25.         if (min > A[i])
  26.             min = A[i];
  27.     }
  28.  
  29.     return min;
  30. }
  31.  
  32. ------------------------------------------------------------------------
  33. //Pseudo-Code
  34. //max of set element
  35. #include <iostream>
  36. using namespace std;
  37.  
  38. int maxOfTheSet();
  39.  
  40. int const n = 5;
  41. int A[n]; // int * a;
  42.  
  43. void main() {
  44.     cout << "Type set of elements\n";
  45.     for (int i = 0; i < n; i++) {
  46.         cin >> A[i];
  47.     }
  48.     cout << maxOfTheSet() << endl;
  49.     system("pause");
  50. }
  51.  
  52. int maxOfTheSet() {
  53.     int max = A[0];
  54.     for (int i = 1; i < n; i++) //n=5
  55.     {
  56.         cout << "max=" << max << " A[" << i << "]=" << A[i] << endl;
  57.         if (max < A[i])
  58.             max = A[i];
  59.     }
  60.  
  61.     return max;
  62. }
RAW Paste Data