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

this question has been answered previously and it works The problem is its writt

ID: 3685200 • Letter: T

Question

this question has been answered previously and it works The problem is its written with commands from the #include<stdio.h> and #include<float.h> directories. That is much more advance than anything I have worked with thus far in C++. So I am asking this question again to be rewritten in commands from #include <iostream> and #include <fstream>( i.e. cout, in_stream.open, if (in_stream.fail()) ; and still have the ability to run sample files as the question requires. Thank you so much guys.

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
   

10.      Extra Credit (15 points) – Write two additional functions:

a.       Write a function that sorts the arrays sales data in ascending order. You may not use selection sort.   Bubble sort example.

b.      Write a function that displays all the elements of the array in a nicely formatted output.   

Explanation / Answer

This below C++ program will work as specified in given program with functions
and with detailed comments

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

void findtotal(int temp2[], int count)
{
    int i, toatl = 0;
    double avg = 0;
    for(i = 0; i < count; i++)
    {
        total + = temp2[i];
    }
    cout<<"Total is : "<<total<<endl;
    cout<<"Average is :"<<(total/count)<<endl;
  
  
}

void bubblesort(int arr[], int n)
{

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n - i - 1; ++j)
        {
            if (arr[j] > arr[j + 1])
            {
                int temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }
  
    for(int i =0; i< n ; i++)
        cout<<arr[i] <<" ";
}

void BigSmall(int values[], int count)
{
    int small,big; //declares integer
    big=small=values[0]; //assigns element to be highest or lowest value

    for (int i = 0; i < count; i++) //works out bigggest number
    {
        if(values[i]>big) //compare biggest value with current element
        {
            big=values[i];
        }
    }

    for (int i = 0; i < count; i++) //works out smallest number
    {
        if(values[i]<small) //compares smallest value with current element
        {
            small=values[i];
        }
    }

    cout << "The biggest number is " << big << endl; //prints outs biggest no
    cout << "The smallest number is " << small << endl; //prints out smalles no
}

}
int main()
{
    // Declaring temporary buffers to store the contents of files into array
    int temp[100], count=0;
    int temp1 = 0;
    double total = 0, avg = 0 ;
    int high = 0, low = 0;  
    // File opening in read name
    ifstream in("file1.txt");
    // Checking the file is exit or not
    if(!in)
    {
        cout<<"File Does not Exist";
        return 0;
    }
    // Read the data from the file and stored in temporary arrays
    while(in.eof()==0)
    {
        in>>temp1;
        temp[i] = temp1;
        i++;
        count++;
    }

    // function passing the arguments to calling function.
    findtotal(temp,temp1);
    bubblesort(temp,temp1);
    BigSmall(temp, temp1);

    // Closing the file
    in.close();
    return 1;
}