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

In C++ able to go to code blocks Jason, Samantha, Ravi, Sheila, and Ankit are pr

ID: 3857316 • 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 <iostream>

#include <string>

#include <fstream>

#include <iomanip>

using namespace std;

//declare the gobal array of type double

double average[5];

//declare the function prototypes

void getData(ifstream& inf, string n[], double runData[][8],int count);

void calculateAverage(double runData[][8], int count);

void print(string n[], double runData[][8], int count);

int main()

{

    string names[5];

    double runningData[5][8];

    ifstream inputfile("runs.txt");

    if(inputfile)

    {

         //call themethod getData

        getData(inputfile, names, runningData, 5);

    }

    else

    {

         //errormessage

        cout<<"Sorry! Unable to open the file."<<endl;

        system("pause");

         return 0;

    }

    //close the file

    inputfile.close();

    //call the method calculateAverage to computethe

    //average miliage of each runner

    calculateAverage(runningData, 5);

    //call display the names and their weekly runrate and their averages

    print(names, runningData, 5);

    system("pause");

    return 0;

}

//definition of method getData that reads the data from the fileand

//stores the names into array n and run data into runDataarray

//simultaneously.

void getData(ifstream& inf, string n[], double runData[][8],int count)

{

    while(!inf.eof())

    {

         for(inti=0;i<count; i++)

         {

            inf>>n[i];

            for(int j=0;j<7;j++)

            {

                inf>>runData[i][j];

            }

         }

    }

}

//definition of method calculateAverage that comptes the totalfirst

//then stores the value of average into the average array

void calculateAverage(double runData[][8], int count)

{

    double total;

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

    {

         total=0;

         for(intj=0;j<7;j++)

         {

            total+=runData[i][j];

        }     

        average[i]=total/7;    

    }

}

//definition of method print that prints the output

//in a tabular format

void print(string n[], double runData[][8], int count)

{

   cout<<setfill('=')<<setw(80)<<"=";

    cout<<setfill(' ');

    cout<<endl;

   cout<<"Name"<<setw(6)<<"";

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

        cout<<setw(7)<<"Day "<<(i+1);

   cout<<setw(12)<<"Average"<<endl;

   cout<<setfill('=')<<setw(80)<<"=";

    cout<<setfill(' ')<<endl;

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

    {

        cout<<n[i]<<setw(8)<<fixed<<"";

         for(intj=0;j<7; j++)

         {

            cout<<setprecision(2)<<fixed<<runData[i][j]<<setw(3)<<"";

         }

        cout<<setw(8)<<average[i];

        cout<<endl;

    }

   cout<<setfill('=')<<setw(80)<<"=";

    cout<<endl;

}