In C++ able to go to code blocks Jason, Samantha, Ravi, Sheila, and Ankit are pr
ID: 3857314 • Letter: I
Question
In C++ able to go to code blocks
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, the total miles for the week, and average miles run each day. Write a modular 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.The results should be displayed as a table. The input data is stored in a file which is attached (marathon.txt) and each line of data contains the name of the runner and the number of days he/she ran that week (each runner ran every day of the week).
maraton.txt
Needed structure chart, source code and output showing test results (screen shot or picture)
Please have
Structure chart included.
File name included as comment at top of source file
IPO chart included as comments following the file name
Variable names are meaningful
Appropriate data structures are used
IPO charts for functions incorporated as comments before each function
Program compiles
Program prompts for input and validates as needed.
Program output is formatted neatly
Program produces correct results
Program is thoroughly tested with test output included
Explanation / Answer
#include <fstream>
#include <sstream>
#include <string>
#include <iomanip>
#include <iostream>
using namespace std;
//variables before main function(global variables)
double matr[4][8];
double avg;
const int noofcols = 8;
const int noofrows = 4;
double row, col;
void openFile(ifstream& afile, double matr[][noofcols]);//function prototypes
void avgs(ifstream& afile, double matr[noofrows][noofcols]);
void prinMat(ifstream& afile, double matr[noofrows][noofcols]);
int main()
{
ifstream afile;
openFile (afile, matr);// function to open file
return 0;
}
void openFile(ifstream& afile, double matr[][noofcols])
{
string inpfile;//used to see inputing file name
cout << "Enter the input file name:";
cin >> inpfile; //open the file
afile.open(inpfile);
if(!afile) //If no file there then this will proceed
{
cout << "Input file opening failed.";
}
while(!afile.eof())//while for checking the end of file
{
for(int i=0; i<row; i++){
for(int j=0; j<col; j++){
afile >> matr[i][j]; // attempt to pass information from file into array
}
}
}
avgs(afile, matr); // function averages to calculate sum and average
}
void avgs(ifstream& afile, double matr[noofrows][noofcols])//this function doesnt work at all
{
cout << fixed << showpoint;
cout << setprecision(2);
double sum=0;
double avg=0;
for (int row=0; row < noofrows; row++)
{
for (int col = 0; col < noofcols; col++)
{
sum = sum + matr[row][col];
avg = sum / 7; //finding the average
}
prinMat(afile, matr);
}
}
void prinMat(ifstream& afile, double matr[][noofcols])
{
cout << fixed << showpoint;
cout << setprecision(2);
// making a array to display this information
string Days[9]= {"Name", "Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6", "Day 7", "Averages"};
cout << Days;
cout << endl;
cout << matr[4][8];
}