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

This is a rework of a previous exercise, I am almost done with the program excep

ID: 3677507 • Letter: T

Question

This is a rework of a previous exercise, I am almost done with the program except for some compiler errors. here is the question:

Redo programming exercise 12 at the end of chapter 8 using dynamic arrays. Creation of dynamic two-dimension arrays is discussed on page 836 of your textbook.

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 program to help them analyze their data. Your program must contain parallel array (in this revision use dynamic array): 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: a function to read and store the runners’ names and the numbers of miles run each day; a function to find the total miles run by each runner and the average number of miles run each day; and a function to output the results. (You may assume that the input data is stored in a file and each line of data is in the following form: runnerName milesDay1 milesDay2 milesDay3 milesDay4 milesDay5 milesDay6 milesDay7.) The catch here is, instead of using parallel arrays, the program must use dynamic arrays

Here is the data file for runs.txt: (this is only an example, can be changed to any value you want)

Jason 7 12 30 9 3 40 55

Samantha 20 11 39 1 24 70 33

Ravi 10 9 8 7 6 5 4

Sheila 25 27 28 21 30 10 22

Ankit 12 18 38 40 11 35 6

The OUTPUT should look like this:

Name Day 1 Day 2 Day 3 Day 4 Day 5 Day 6 Day 7 Total miles   Average

Jason 10.00 15.00 20.00 25.00 18.00 20.00 26.00        134.00        19.14

Samantha 15.00 18.00 29.00 16.00 26.00 20.00 23.00 147.00      21.00

Ravi 20.00 26.00 18.00 29.00 10.00 12.00 20.00           135.00    19.29

Sheila 17.00 20.00 15.00 26.00 18.00 25.00 12.00         130.00     19.00

Ankit 16.00 8.00 28.00 20.00 11.00 25.00 21.00            129.00      18.43

Special Note: Don’t forget to use functions. The program needs to be run on dynamic arrays. This must be on C++. I have the program almost done, except for some compiler errors. I will post my program below, and i will also post the compiler errors i received. If the compiler errors are resolved, then the program is done. So when doing this, please, please compile it and check it first, before posting the solution (I really dont want to waste another of my question). I would really appreciate the help for this.

Compiler errors list:

Line            Col                            Message

                                                   In function 'int main()':

47              50                             [Error] cannot convert 'double**' to 'double (*)[8]' for argument '3' to 'void getData(std::ifstream&, std::string*, double (*)[8], int)'

73              36                             [Error] cannot convert 'double**' to 'double (*)[8]' for argument '1' to 'void calculateAverage(double (*)[8], int)'

77              32                             [Error] cannot convert 'double**' to 'double (*)[8]' for argument '2' to 'void print(std::string*, double (*)[8], int)'

Here is my program:

#include <iostream>

#include <string>

#include <fstream>

#include <iomanip>

using namespace std;

//declare the global array of type double

double *average = new double[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 = new string[5];

    //memory allocated for elements of rows

    double **runningData = new double*[5];

    //memory allocated for elements of each column

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

          runningData[i] = new double[8];

    ifstream inputfile("runs.txt");

    if(inputfile)

    {

         //call the method getData

         getData(inputfile, names, runningData, 5);

    }

    else

    {

         //error message

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

         system("pause");

         return 0;

    }

    //close the file

    inputfile.close();

    //call the method calculateAverage to compute the

    //average miliage of each runner

    calculateAverage(runningData, 5);

    //call display the names and their weekly run rate and their averages

    print(names, runningData, 5);

    system("pause");

    return 0;

}

//definition of method getData that reads the data from the file and

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

//simultaneously.

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

{

    while(!inf.eof())

    {

         for(int i=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 total first

//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(int j=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(int j=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;

}

Explanation / Answer

Hi, I have solved the problem of compiling error. I have not gone through your logic.

Please rum this program with your data, and let me knoe if any need.

#include <iostream>

#include <string>

#include <fstream>

#include <stdlib.h>

#include <iomanip>

using namespace std;

//declare the global array of type double

double *average = new double[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 = new string[5];

    //memory allocated for elements of rows

    double **runningData = new double*[5];

    //memory allocated for elements of each column

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

          runningData[i] = new double[8];

    ifstream inputfile("runs.txt");

    if(inputfile)

    {

         //call the method getData

         getData(inputfile, names, runningData, 5);

    }

    else

    {

         //error message

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

         system("pause");

         return 0;

    }

    //close the file

    inputfile.close();

    //call the method calculateAverage to compute the

    //average miliage of each runner

    calculateAverage(runningData, 5);

    //call display the names and their weekly run rate and their averages

    print(names, runningData, 5);

    system("pause");

    return 0;

}

//definition of method getData that reads the data from the file and

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

//simultaneously.

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

{

    while(!inf.eof())

    {

         for(int i=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 total first

//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(int j=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(int j=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;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote