Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem: 1) read an unknown number of positive integers, but 50 or less 2) print

ID: 3635680 • Letter: P

Question

Problem:
1) read an unknown number of positive integers, but 50 or less
2) print out some statistics (how many numbers were read, the largest number, the
smallest number, and an average. Note that the average is a whole number.
Except for the total number of errors, invalid data has no effect on anything else.)
3) use a function called process_array to process the array
a) this function prints out the table below (including the lines and table headings)
b) the column Sum of RestEven is computed using a NESTED “FOR” LOOP.
This column is calculated by summing all of the rest of the numbers in the
array which are even, after the number you are currently processing.
For example. suppose there are 10 items in the array, subscripted 0 thru 9.
Suppose that you are on subscript 5. You are then supposed to sum the
values at subscripts 6 thru 9 which are even, since these are the numbers in
the array AFTER the number you are currently processing. (HINTS:
What is the first subscript of this nested “for” loop? It is 6. How do you
build a “for” loop that starts at subscript 6, and ends at the appropriate
place?)
4) use a function called last_statement to print out the final statement.
This function uses a switch statement to print out how many integers there are, by
“tens”. For instance, if there are less than 10 integers, it prints out “The number
of numbers read was in the single digits”. If there are between 10 and 19 integers
(inclusive), it prints out “The number of numbers read was in the tens”. If there
are between 20 and 29 integers, it prints out “The number of numbers read was in
the twenties”, etc.

SAMPLE INPUT: 100 49 -26 64 16

SAMPLE OUTPUT:
4 integers were read
There was 1 error
Largest: 100
Smallest: 16
Average: 57
-----------------------------------------------
Seq Number Sum of RestEven
-----------------------------------------------
1 100 80
2 49 80
3 64 16
4 16 0
-----------------------------------------------
The number of numbers read was in the single digits

Explanation / Answer

Please rate:Thanks

#include<iostream.h>
void largest(int a[],int );
void smallest(int a[],int);
void average(int a[],int);
void RestEven(int a[] ,int);
void last_statement(int);

void main()
{
int a[50];
int len=0,neg=0;
cout<<"Enter integers or 0 to exit";
for(int i=0;i<50;i++)
{
cin>>a[i];
if(a[i]==0)
break;
else if(a[i]<0)
neg++;
else
len++;
}
void process_Array(int a[],int,int);
process_Array(a,len,neg);
}
void process_Array(int a[],int len,int neg){

cout<<len<<" Integers were read "<<endl;
cout<<"There was "<<neg<<" error"<<endl;
largest(a,len+neg);
smallest(a,len+neg);
average(a,len+neg);
cout<<"------------------------------------------"<<endl;
cout<<"Seq number sum of Rest Even "<<endl;
cout<<"------------------------------------------"<<endl;
RestEven(a,len+neg);
cout<<"------------------------------------------"<<endl;
last_statement(len+neg);

}
void RestEven(int a[], int num){
int sum;
for(int j=0;j<num;j++)
{
if(a[j]>0){
sum=0;
for(int k=j+1;k<num ;k++)
{
if(a[k]%2==0 && a[k]>0)
sum=sum+a[k];
}
cout<<(j+1)<<" "<<a[j]<<" "<<sum<<endl;
}
}

}

void average(int a[],int num)
{
int avg,sum=0,n=0;
for(int i=0;i<num;i++){
if(a[i]>0){
n++;
sum=sum+a[i];
}          }
avg=sum/n;
cout<<"Average: "<<avg<<endl;
}
void smallest(int a[],int num)
{
int min=a[0];
for(int i=0;i<num;i++)
{
if(a[i]<min && a[i]>0)
min=a[i];
}
cout<<"Smallest: "<<min<<endl;
}
void largest(int a[],int num)
{
int max=a[0];
for(int i=0;i<num;i++)
{
if(a[i]>max)
max=a[i];
}
cout<<"Largest: "<<max<<endl;
}
void last_statement(int len){
int a=0;
if(len<10)
a=1;
else if(len>=10 && len<=19)
a=2;
else if(len>=20 && len<=29)
a=3;
else if(len>=30 && len<=39)
a=4;
else if(len>=40 && len<=49)
a=5;
else if(len==50)
a=6;
switch(a)
{
case 1: cout<<"The number of numbers read was in the single digits";break;
case 2: cout<<"The number of numbers read was in the tens";break;
case 3: cout<<"The number of numbers read was in the twenties";break;
case 4: cout<<"The number of numbers read was in the thirties";break;
case 5: cout<<"The number of numbers read was in the fourties";break;
case 6: cout<<"The number of numbers read was fifty";break;
default:cout<<"Invalid";
}
}

------------------------------------------------------

Output:

 

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote