Guest User

https://ehazi.hu/q/117580

a guest
Oct 10th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <iostream> // cout, endl
  2. #include <iomanip>  // setw
  3. #include <cstdlib>  // rand, srand, RAND_MAX
  4. #include <ctime>    // time, NULL
  5.  
  6. #define D 30
  7.  
  8. using namespace std;
  9.  
  10. void init(float arr[], unsigned n) {
  11.     srand(time(NULL));
  12.    
  13.     for(int i = 0; i < n; i++) {
  14.         arr[i] = rand()/float(RAND_MAX) * 15 - 5;
  15.         cout << setw(2) << i+1 << ". " << arr[i] << endl;
  16.     }
  17. }
  18.  
  19. float atlag(float arr[], unsigned n) {
  20.     float sum = 0.0;
  21.     int cnt = 0;
  22.     for(int i = 0; i < n; i++) {
  23.         sum += arr[i];
  24.         cnt++;
  25.     }
  26.    
  27.     return sum/cnt;
  28. }
  29.  
  30. bool fagyos_e(float arr[], unsigned n) {
  31.     for(int i = 0; i < n; i++) {
  32.         if(arr[i] <= 0.0) {
  33.             return true;
  34.         }
  35.     }
  36.    
  37.     return false;
  38. }
  39.  
  40. float legmelegebb(float arr[], unsigned n) {
  41.     float max = -5.0;
  42.     for(int i = 0; i < n; i++) {
  43.         if(arr[i] > max) {
  44.             max = arr[i];
  45.         }
  46.     }
  47.    
  48.     return max;
  49. }
  50.  
  51. bool futes(float arr[], unsigned n) {
  52.     // és mégis milyen hűvösre kellene bekapcsolni a fűtést? csinálok egy küszöböt, hogy be lehessen állítani...
  53.     float kuszob = 5.0;
  54.     for(int i = 0; i < 15; i++) {
  55.         if(arr[i] < kuszob) {
  56.             return true;
  57.         }
  58.     }
  59.    
  60.     return false;
  61. }
  62.  
  63. int main() {  
  64.     float data[D] = {};
  65.    
  66.     init(data, D);
  67.    
  68.     cout << endl << "Átlag: " << atlag(data, D);
  69.     cout << endl << "Fagyos-e? " << (fagyos_e(data, D) ? "Igen" : "Nem");
  70.     cout << endl << "Csúcshő: " << legmelegebb(data, D);
  71.     cout << endl << "15-e előtt fűtés kell-e? " << (futes(data, D) ? "Igen" : "Nem");
  72.    
  73.     return 0;
  74. }  
Advertisement
Add Comment
Please, Sign In to add comment