Heretiiik

Untitled

Apr 7th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.36 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. //#include <string> // neni potreba
  4. /*******************************************/
  5. using namespace std;                            //používá cout
  6. /*******************************************/
  7. //typedef int xArray[20]; // fuj                
  8. //xArray pole;            // fuj                
  9. const int SIZE = 10;                            //konstanta pro práci v cyklech
  10. /*******************************************/
  11.  
  12. void fill(int* vstup) { // víc generickej přístup
  13.     for(int i = 0; i < SIZE; i++){            
  14.         cout<<"Zadej "<<i+1<<". číslo."<<endl;    
  15.         cin >> vstup[i];                        
  16.         }    
  17.     }
  18. /*******************************************/
  19. //int findMinus (xArray vstup){                  
  20. int findMinus (const int * vstup) { // nekopirujes cely pole (&) a rikas tomu, ze se na puvodni pole nebude sahat (const)
  21.     int count = 0;                              
  22.     for(int i = 0; i < SIZE; i++){            
  23.         if(vstup[i] < 0){                      
  24.             //count++;                            
  25.             ++count; // je to rychlejší
  26.         }
  27.     }
  28.     return count;                              
  29. }
  30. /*******************************************/
  31. //float average(xArray vstup){                  //POČÍTÁ ARITMETICKÝ PRŮMĚR
  32. float average(const int * vstup){              
  33.     float sum = 0;                                                        
  34.     for(int i = 0; i < SIZE; i++){            
  35.         if (vstup[i] > 0)                  
  36.             sum += vstup[i];                                            
  37.     }
  38.    
  39.     return sum/(SIZE - findMinus(vstup));    // pokud je v deleni aspon jedno cislo float/double vrátí to zase float/double
  40.                                       // a uz mas funkci ktera pocita zaporny cisla, tak proc ji nevyuzit
  41. }
  42. /*******************************************/
  43. int main()                                      
  44. {
  45.     int pole[SIZE];
  46.    
  47.     fill(pole);                                 //spouští funkci fill, do které vstupuje s polem s názvem pole
  48.     cout<<findMinus(pole)<<endl;                //spouští a na konci vypíšu výsledek funkce findMinus a vstupuje s polem s názvem pole
  49.     cout<<average(pole)<<endl;                  //spouští a vypíše funkci average (samotný aritmetický průměr)
  50. }
Add Comment
Please, Sign In to add comment