Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/P10_3.cpp - This program will ask a runner for her/his fastest 5 times for 6 // different distances and will display them using a 2-D

/P10_3.cpp - This program will ask a runner for her/his fastest 5 times for 6 // different distances and will display them using a 2-D array.

#include using namespace std;

int find_distance(int j); //a function that returns a distance based on the choice j

int main( ) { int i =0; int distance[6]; double data[6][5]; //This array will keep 30 values in 6 rows and 5 columns // 6 events and 5 times for each one of the events

for(int j = 0; j < 6; j++) { distance[j] = find_distance(j); cout << " Enter 5 of your best running times for " << distance[j] << " m "; for(i = 0; i < 5; i++) { cout << "Enter a time "; cin >> data[j][i]; }

}

cout << "Here is your best 5 times: "; for(j = 0; j < 6; j++) { cout << " Distance : " << distance[j] << " m "; for(i = 0; i < 5; i++) {

cout << data[j][i] << "\t"; } cout << endl; }

return 0; }

int find_distance(int j) { switch (j) { case 0: // 100 meter return 100; break; case 1: // 150 meter return 150; break; case 2: // 200 meter return 200; break; case 3: // 400 meter return 400; break; case 4: // 500 meter return 800; break; default: // 1600 meter return 1600; } }

In the above program, we can access the 3rd time of the 4th event (400 m) in:

data[3][2]; // note that the 3rd time is stored in column with index 2 // and the 4th event is stored in row with index 3

The 4th event was 400 meter.

To access the 5 times for 150 m event, we can use:

data[1][0], data[1][1], data[1][2], data[1][3], data[1][4]

Or use a for loop to access them:

for(i = 0; i < 5; i++) data[1][i];

Exercise 10.4 Modify the above program such that it finds the best, the worst, and the average time for each of the six events. The program, named ex10_4.cpp, should display, for each event, all five times, the worst, the best, and the average.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

More Books

Students also viewed these Databases questions

Question

LO3 Name the seven categories of HR functions.

Answered: 1 week ago