SHARE
TWEET

Untitled

a guest Mar 20th, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. void fillArray(int a[], int size) {
  7.     srand((int)time(0));
  8.     for (int i = 0; i<size; i++)
  9.         a[i] = (rand() % 100) + 1;
  10. }
  11.  
  12. double getMean( int a[], int size) {
  13.     int sum = 0;
  14.     for (int i = 0; i<size; i++) {
  15.         sum += a[i];
  16.     }
  17.     return sum/size;
  18. }
  19.  
  20. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  21. void getMode( int a[], int size) {
  22.     int maxV = 0;
  23.     int maxC=0;
  24.     for (int i = 0; i<size; i++) {
  25.         int c=0;
  26.         for(int z =0;z<size;z++){
  27.             if(a[z] == a[i]){
  28.                 c++;
  29.             }
  30.         }
  31.         if(c-1> maxC){
  32.                maxC=c;
  33.                maxV=a[i];
  34.            }
  35.  
  36.     }
  37.     if(maxC == 0){
  38.         cout << "****N/A There are no repeating numbers*****" <<endl ;
  39.        
  40.     }
  41.     else{
  42.         for (int i = 0; i < size; i++) {
  43.         int count = 0;
  44.         for (int j = 0; j < size; j++) {
  45.             if (a[j] == a[i])
  46.                 count++;
  47.             }
  48.        
  49.         if (count == maxC) {
  50.             cout<< a[i]<<" ";
  51.         }
  52.    
  53.      }
  54.     }
  55.        
  56.        
  57.        
  58.          
  59.        
  60. }
  61.  
  62.  
  63. //////////////////////////////////////////////////////////////////
  64. double getHighV( int a[], int size) {
  65.     double maxxV=0;
  66.     for(int i = 0;i<size;i++){
  67.         if(a[i]>maxxV){
  68.             maxxV=a[i];
  69.         }
  70.     }
  71.     return maxxV;
  72. }
  73. double getLowV( int a[], int size) {
  74.     double lowV=a[0];
  75.     for(int i = 0;i<size;i++){
  76.         if(a[i]<lowV){
  77.             lowV=a[i];
  78.         }
  79.     }
  80.     return lowV;
  81. }
  82.  
  83.  
  84. int main() {
  85.    
  86.     int ary[15];
  87.     int size = 15;
  88.     fillArray(ary, size);
  89.  
  90.     cout << "Random values: " << endl;
  91.     for (int i = 0; i<15; i++){
  92.         cout << ary[i]<<endl;
  93.         }
  94.     cout<< endl;
  95.     cout << "Mean of the array: " << getMean(ary, size) << endl;
  96.     cout << "Mode(s) of the array(modes will be displayed"<<endl;
  97.     cout<< "the same number of times they appear in the array): ";  
  98.     getMode(ary, size);
  99.     cout<< endl;
  100.     cout << "Highest value of the array: "<< getHighV(ary, size) << endl;
  101.     cout << "Lowest value of the array: "<< getLowV(ary, size) << endl;
  102.    
  103.    
  104. }
RAW Paste Data
Want to get better at C++?
Learn to code C++ in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top