Create an application containing an array that stores 10 integers. The application should call five methods that in turn:
a) Display all integers in the array
b) Display all integers in reverse order
c) Display the sum of the integers
d) Display all values that ae high than the calculated average value
#include <iostream>
using namespace std;
void Display(int x[10]){
cout<<"\nThe digits in the order they were input are; \n";
for(int i = 0; i < 10; i++){
cout<<x[i];
if(i != 9) cout<<", ";
}
cout<<endl;
}
void DisplayReverse(int x[10]){
cout<<"\nThe digits displayed in reverse are; \n";
for(int i = 9; i >= 0; i--){
cout<<x[i];
if(i != 0) cout<<", ";
}
cout<<endl;
}
int DisplaySum(int x[10]){
int sum = 0;
for(int i = 0; i < 10; i++) sum += x[i];
cout<<"\nThe total of the integers is "<<sum<<endl;
return sum;
}
void DisplayHigherThanAverage(int x[10]){
float average = (float)DisplaySum(x) / 10;
cout<<"\nThe integers higher than average are;\n";
for(int i = 9; i >= 0; i--){
if(i != 0 && x[i] > average && i != 9) cout<<", ";
if(x[i] > average) cout<<x[i];
}
cout<<"\n\n";
}
int main(){
int x[10];
cout<<"Input 10 integers; \n";
for(int i = 0; i < 10; i++){
cin>>x[i];
}
Display(x);
DisplayReverse(x);
DisplayHigherThanAverage(x);
return 0;
}
Comments
Leave a comment