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

PURPOSE : To do simple array manipulation. To use functions with arrays PROBLEM

ID: 3569568 • Letter: P

Question

PURPOSE:     To do simple array manipulation. To use functions with arrays

PROBLEM:

                        1.         Write a C ++ program to read numbers (using the count technique or a sentinel loop) into an array of floats, and then manipulate the array. Declare the array of size 25 (range 0 to 24). Use a function to read the array. Then do the following exercises.

                        2.         (1 and 2 are worth 20%) Print the array, writing the indexes and components. Use a setprecision of 3 set in the main program.

                        3.         (30%) Find the mean average of the array, using a function, and print the result in the main.

                        4.         (40%) After finding the average, store the differences between each array element and the average in another array. Some of the differences will be negative.

                        5.         (10%) Print the result step 4 above in the printlist procedure

                        6.         Each of the above algorithms should be coded with a subroutine with an appropriate message before the output. The parameters should be in correct form. Partial credit will be given if some of the functions are completed but not all.

                        7.         (See prototypes for functions on page 2. The data is also on page 2.)

INPUT:           (See page 2)

OUTPUT:       As described above, with appropriate messages:

CSC 110 C ++ Introd. To Computing   Program 4   Version D   Page 2/3                 Parallel Arrays

Data for array program

                        17   Number of array values to read

            85, 80, 53, 79, 30, 3, 37 ,76 9, 48, 1, 8, 89, 41, 36, 10, 25, 48, 30, 37, 76, 9,48, 1, 8, 89, 41, 36, 10, 25, 48

Prototypes for the functions:

void getlist (float [], int &);

void printlist (const float [], int);

float mean_average (const float [], int);

void find_differences (float, const float [], float [], int); // store differences from average

                                                                                         // for each array element

            First argument is the average, the second is the original array, the third is the

            array holding the differences, the last is the significant values in the arrays.

CSC 110 C ++ Introd. To Computing   Program 4   Version D   Page 3/3                 Parallel Arrays

Pseudocode for Find_Differences algorithm

Note

Explanation / Answer

#include<iostream>
#include <iomanip>
using namespace std;

void getlist(float a [],int x)
{
int i;
for(i=0;i<x;i++)
cin>>a[i];
}

void printlist(const float b[],int y)
{
int i;
for(i=0;i<y;i++)
cout<<setprecision(3)<<i<<"->"<<b[i]<<" ";
}

float mean_average(const float c[],int z)
{
int i;
float sum=0;
for(i=0;i<z;i++)
sum=sum+c[i];
sum=sum/z;
return(sum);
}

void find_differences(float average, const float original[], float diff[],int w)
{
int i;
for(i=0;i<w;i++)
diff[i]=original[i]-average;
}


int main()
{
int number=25,i;
float arr[number];
float mean,arr_diff[number];
getlist(arr,number);
printlist(arr,number);
mean=mean_average(arr,number);
cout<<"mean: "<<mean<<endl;
find_differences(mean,arr,arr_diff,number);
printlist(arr_diff,number);
}