Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- //#include <string> // neni potreba
- /*******************************************/
- using namespace std; //používá cout
- /*******************************************/
- //typedef int xArray[20]; // fuj
- //xArray pole; // fuj
- const int SIZE = 10; //konstanta pro práci v cyklech
- /*******************************************/
- void fill(int* vstup) { // víc generickej přístup
- for(int i = 0; i < SIZE; i++){
- cout<<"Zadej "<<i+1<<". číslo."<<endl;
- cin >> vstup[i];
- }
- }
- /*******************************************/
- //int findMinus (xArray vstup){
- int findMinus (const int * vstup) { // nekopirujes cely pole (&) a rikas tomu, ze se na puvodni pole nebude sahat (const)
- int count = 0;
- for(int i = 0; i < SIZE; i++){
- if(vstup[i] < 0){
- //count++;
- ++count; // je to rychlejší
- }
- }
- return count;
- }
- /*******************************************/
- //float average(xArray vstup){ //POČÍTÁ ARITMETICKÝ PRŮMĚR
- float average(const int * vstup){
- float sum = 0;
- for(int i = 0; i < SIZE; i++){
- if (vstup[i] > 0)
- sum += vstup[i];
- }
- return sum/(SIZE - findMinus(vstup)); // pokud je v deleni aspon jedno cislo float/double vrátí to zase float/double
- // a uz mas funkci ktera pocita zaporny cisla, tak proc ji nevyuzit
- }
- /*******************************************/
- int main()
- {
- int pole[SIZE];
- fill(pole); //spouští funkci fill, do které vstupuje s polem s názvem pole
- cout<<findMinus(pole)<<endl; //spouští a na konci vypíšu výsledek funkce findMinus a vstupuje s polem s názvem pole
- cout<<average(pole)<<endl; //spouští a vypíše funkci average (samotný aritmetický průměr)
- }
Add Comment
Please, Sign In to add comment