In: Computer Science
Summary
Jason, Samantha, Ravi, Sheila, and Ankit are preparing for an upcoming marathon. Each day of the week, they run a certain number of miles and write them into a notebook. At the end of the week, they would like to know the number of miles run each day and average miles run each day.
Instructions
Write a program to help them analyze their data. Your program must contain parallel arrays: an array to store the names of the runners and a two-dimensional array of five rows and seven columns to store the number of miles run by each runner each day. Furthermore, your program must contain at least the following functions:
Note: Could you plz go through this code and let me know if u
need any changes in this.Thank You
_________________
// Lab9_data.txt
Jason 5 6 3 4 8 3 4
Samantha 3 4 5 6 3 4 5
Ravi 3 4 5 6 5 5 5
Sheila 5 5 4 3 4 2 2
Ankit 7 6 5 7 6 5 6
____________________
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
// constant variable declaration
const int COUNT = 5;
const int DAYS = 7;
// This functions stores the names of runners and number of
miles run each day
void inputData(string names[], int sizeOfName, double
numOfMiles[][DAYS], int rowSize)
{
//Create input file name
ifstream infile;
infile.open("Lab9_data.txt");
int checkNames, checkMiles;
for(checkNames = 0;checkNames <
sizeOfName;checkNames++)
{
infile >> names[checkNames];
for(checkMiles=0;checkMiles < DAYS;checkMiles++)
{
infile >> numOfMiles[checkNames][checkMiles];
}
}
}
/* This function is to find the total miles run by each runner
and the
avg number of miles run each day*/
void computeMiles(double status[][2], double numOfMiles[][DAYS],
int rowSize)
{
// declare variables
double total = 0, avg = 0;
int runCount = 0, num = 0;
cout << fixed << showpoint << setprecision(2)
<< endl;
while (runCount < rowSize)
{
while (num < DAYS)
{
total = total + numOfMiles[runCount][num];
num++;
}
avg = (total / DAYS);
status[runCount][0] = total;
status[runCount][1] = avg;
total = 0;
avg = 0;
num = 0;
runCount++;
}
}
// function displays runner's names, total miles and avg of
runners
void displayResult(double status[][2], string names[], int
sizeOfName)
{
cout << setw(10) << "Runner Name" <<
setw(12)
<< "Total miles" << setw(10) << "Average"
<< endl;
int runCount = 0;
while (runCount < sizeOfName)
{
cout << setw(10) << names[runCount] << setw(12)
<< status[runCount][0]
<< setw(10) << status[runCount][1] << endl;
runCount++;
}
}
// main function
int main()
{
// Declare array variables
string names[COUNT];
double milesStatus[COUNT][DAYS];
double output[COUNT][2];
// call the function
inputData(names, 5, milesStatus, 5);
computeMiles(output, milesStatus, 5);
displayResult(output, names, 5);
// pause the system
system("PAUSE");
return 0;
}
__________________________
Output:
_________________Thank You