I have a C project due tonight and Im almost done with progr

I have a C++ project due tonight and I\'m almost done with program, it just will not compile. Here is the prompt

Write a program that reads sales data from a file.  The program outputs the totals sales, average sales, lowest and highest sales.   

Outcomes:

1.      Read data from a file into an array.

2.      Process data in a partially filled array via functions.

3.      Pass an array as a parameter to a function.

4.      Use for and while loops when processing an array.

Specifications:

1.      Use an array to store the sales data.  Sales data should be stored as a double.

2.      The company has at most 20 locations. (Max capacity of the array)

3.      The input file contains a sales report that list the number of stores reporting data and the sales data.

4.      Sample Input file format: (samplefile1 and samplefile2)

3

27648.92 234.83 23458.32  

The \'3\' means that this file contains data for three locations. The numbers represent the sales for each location.  

5.      The main function should be modular so the main tasks must be handled by functions. Note: this is only an outline of the function requirements. You will need to decide on function names, parameter lists and return types on your own.

6.      The tasks are:  

a.      Ask the user for the file name that contains the sales data. Fill the array with the sales data from a file.

b.      Total the sales data.

c.       Average the sales data.

d.      Determine the highest sales in the report.

e.      Determine the lowest sales from the report

7.      The main function should output the data to the user.

8.      Add code to the main function to allow the user to rerun the program.   

9.      Sample output:

Enter file name: sales.dat

The total sales are $755260.00

The average sales amount is $ 75526.00

The highest sales amount is $124569.00

The lowest sales amount  is $ 35678.00

Here is what I have of my code:

#include <iostream>
#include <fstream>
using namespace std;

const int LOCATIONS = 20;


void readdata(double a[], int size, ifstream& data);

double avg_array(const double a[], double data);
double sum_array(const double a[], double data);
double find_high(const double a[], double data);
double find_low(const double a[], double data);

int main()
{

ifstream in;
char in_file[256];

double avg_sales, high_sales, low_sales, total_sales;

double salesdata[LOCATIONS];


cout << \"Enter the input file name:\ \";
cin >> in_file;

in.open(in_file);
if(in.fail( ))
{
cout << \"Input file opening failed.\ \";
exit(1);
}


readdata(salesdata,LOCATIONS, in);

total_sales = sum_array(salesdata, LOCATIONS);
cout << endl << \"The total sales are $\" << total_sales << endl;

avg_sales = avg_array(salesdata, LOCATIONS);
cout << \"The average sales amount is $\" << avg_sales <<endl;

high_sales = find_high(salesdata, LOCATIONS);
cout << \"The highest sales amount is $\" << high_sales << endl;

low_sales = find_low(salesdata, LOCATIONS);
cout << \"The lowest sales amount is $\" << low_sales << endl;

system(\"pause\");
return 0;
}

double sum_array(const double sales[], double n)
{
double sum = 0;
for(int count = 0; count < n; count++)
sum += sales[count];
return(sum);
}


double avg_array(const double sales[], double n)
{
return((double)sum_array(sales, n)/n);
}

double find_high(const double sales[], double n)
{
double highest;

highest = sales[0];

for(int count = 1; count < n; count++)

if(highest < sales[count])
highest = sales[count];
return(highest);
}

double find_low(const double sales[], double n)
{
double lowest;

lowest = sales[0];

for(int count = 1; count < n; count++)

if(lowest > sales[count])
lowest = sales[count];

return(lowest);
}


void readdata(double a[], int size, ifstream& in_data)
{

int index=0;
while(index<size)
{
in_data>>a[index];
index++;
}
}

Solution

correct program with output ,i am taking sales.txt as input file you may take .dat also.

#include <iostream>
#include <fstream>
using namespace std;

const double LOCATIONS = 20;


void readdata(double a[], int size, ifstream& data);

double avg_array(const double a[], double data);
double sum_array(const double a[], double data);
double find_high(const double a[], double data);
double find_low(const double a[], double data);

int main()
{

ifstream in;
char in_file[256];

double avg_sales, high_sales, low_sales, total_sales;

double salesdata[LOCATIONS];


cout << \"Enter the input file name:\ \";
cin >> in_file;

in.open(in_file);
if(in.fail( ))
{
cout << \"Input file opening failed.\ \";
exit(1);
}


readdata(salesdata,LOCATIONS, in);

total_sales = sum_array(salesdata, LOCATIONS);
cout << endl << \"The total sales are $\" << total_sales << endl;

avg_sales = avg_array(salesdata, LOCATIONS);
cout << \"The average sales amount is $\" << avg_sales <<endl;

high_sales = find_high(salesdata, LOCATIONS);
cout << \"The highest sales amount is $\" << high_sales << endl;

low_sales = find_low(salesdata, LOCATIONS);
cout << \"The lowest sales amount is $\" << low_sales << endl;

system(\"pause\");
return 0;
}

double sum_array(const double sales[], double n)
{
double sum = 0;
for(int count = 0; count < n; count++)
sum += sales[count];
return(sum);
}


double avg_array(const double sales[], double n)
{
return((double)sum_array(sales, n)/n);
}

double find_high(const double sales[], double n)
{
double highest;

highest = sales[0];

for(int count = 1; count < n; count++)

if(highest < sales[count])
highest = sales[count];
return(highest);
}

double find_low(const double sales[], double n)
{
double lowest;

lowest = sales[0];

for(int count = 1; count < n; count++)

if(lowest > sales[count])
lowest = sales[count];

return(lowest);
}


void readdata(double a[], int size, ifstream& in_data)
{

int index=0;
while(index<size)
{
in_data>>a[index];
index++;
}

output :

  

Enter the input file name:                                                                                                    

sales.txt                                                                                                                     

                                                                                                                              

The total sales are $2.45678e+06                                                                                              

The average sales amount is $122839                                                                                           

The highest sales amount is $2.45678e   

The lowest sales amount is $4.00687   

sh: pause: command not found   

}

I have a C++ project due tonight and I\'m almost done with program, it just will not compile. Here is the prompt Write a program that reads sales data from a fi
I have a C++ project due tonight and I\'m almost done with program, it just will not compile. Here is the prompt Write a program that reads sales data from a fi
I have a C++ project due tonight and I\'m almost done with program, it just will not compile. Here is the prompt Write a program that reads sales data from a fi
I have a C++ project due tonight and I\'m almost done with program, it just will not compile. Here is the prompt Write a program that reads sales data from a fi
I have a C++ project due tonight and I\'m almost done with program, it just will not compile. Here is the prompt Write a program that reads sales data from a fi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site