Question: Task : One Dimensional Arrays #include using namespace std; int main() { int tests[6]; // array declaration int sum = 0; float avg; //input test

Task : One Dimensional Arrays

#include

using namespace std;

int main()

{

int tests[6]; // array declaration

int sum = 0;

float avg;

//input test scores

cout << " Enter " << 6 << " test scores: " << endl;

for (int i = 0; i < 6; i++)

{

cout << "Enter Test " << i + 1 << ": ";

cin >> tests[i];

}

return 0;

}

1. Type in the above program as array1.cpp. Add a comment to include your name and date. Compile and run. Draw a picture showing what the array looks like in memory.

2. Add code to print the first test score. Add the following comment://2. Print the first test score

3. Add code to print the last test score. Add the following comment://3. Print the last test score

4. Add the code to print all of the test scores. Add a comment: //4. Print all scores

5. Add code to sum the test scores. Print the sum. Add a comment: //5. Sum all scores

6. Add code to calculate and print the average test score. Add a comment: //6. Calculate the average

Save the above code and paste it here before going further.

7. This time, change the program so the average calculation takes place in a function. Remove the sum and average calculation from above and add the following function and the appropriate call (add a comment: //7). You will also need to add a prototype. Run.

//******************************************************

void CalcAvg(int tests[], int numTests/* must be > 0 */, float& avg)

{

int sum=0;

for (int i = 0; i < numTests; i++)

{

sum = sum + tests[i];

}

avg = (float)sum/numTests;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!