Please write a c++ code with proper use of constants for my pseudo code. I am ta
ID: 3727623 • Letter: P
Question
Please write a c++ code with proper use of constants for my pseudo code. I am take a class that is teaching me flow charts and pseudocode and I would like to see the actual code so that I can start preparing myself for next semester’s classes. Here is the pseudo code:
// main module
Module main()
// Local variables
Constant Integer SIZE = 20
Declare Integer numbers[SIZE], high, low, average, total = 0
// Get numbers
For index = 0 to SIZE - 1
Display “Enter number “, index + 1, “: “
Input numbers[index]
End For
// Get statistics
For index = 0 to SIZE – 1
Set total = total + numbers [index]
If index == 0 Then
Set high = numbers [index]
Set low = numbers [index]
End If
If high < numbers [index] Then
Set high = numbers [index]
End If
If low > numbers [index] Then
Set low = numbers [index]
End If
End For
Set average = total / SIZE
// Show statistics
Call showStats(high, low, total, average)
End Module
// The showStats module shows high, low, average number
Module showStats(Integer high, low, total, average)
Display “High number is: ”, high
Display “Low number is: ”, low
Display “Total of numbers is: ”, total
Display “Average of numbers is: ”, average
End Module
Output should like this:
THIS PROBLEM IS MODIFIED AS FOLLOWS:
DO NOT ASK FOR THE USER TO ENTER 20 NUMBERS.
Instead, initialize an array with these specific 20 numbers: 26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51
The array was initialized to:
26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51
The lowest number is: 5
The highest number is: 93
The total of the numbers is: 965
The average of the numbers is: 48.25
Explanation / Answer
#include<iostream>
using namespace std;
void showStats(int high,int low,int total,int average){
cout<<"High number is: "<<high<<endl;
cout<<"Low number is: "<<low<<endl;
cout<<"Total of numbers is: "<<total<<endl;
cout<<"Average of numbers is: "<<average<<endl;
}
int main(){
//local variables
const int SIZE = 20;
int numbers[]={26,45,56,12,78,74,39,22,5,90,87,32,28,11,93,62,79,53,22,51};
int high,low,average,total=0;
cout<<"The array was initialized to: "<<endl;
for(int index=0;index<=SIZE-1;index++){
cout<<numbers[index]<<" ";
}
cout<<endl;
//get statistics
for(int index=0;index<=SIZE-1;index++){
total = total + numbers[index];
if(index==0){
high=numbers[index];
low=numbers[index];
}
if(high<numbers[index]){
high=numbers[index];
}
if(low>numbers[index]){
low=numbers[index];
}
}
average=total/SIZE;
//show statistics
showStats(high,low,total,average);
}