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

#include<iostream> #include <string> #include <fstream> #include <iomanip> using

ID: 3610899 • Letter: #

Question

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

const int SIZE = 25;//Size of arrays

int main()
{
double SalesAmounts [SIZE]; //Sales amounts array
string SalesReps [SIZE]; //Names of sales representativesarray
ifstream infile; //Input filestream variable
string fnameopen, fnameclose; //Variables to hold actualname of file
double sum;
int counter=0; //used in for loops
double average; //average of sales amount
int MaxIndex; //used to find the array with the largestvalue
double LargestSale; //variable to hold the largestvalue

cout<<"Pleaseenter name of input file"<<endl;
cin>>fnameopen;
infile.open(fnameopen.c_str());
cout<<"Please enter name of outputfile"<<endl;
cin>>fnameclose;
cout<<"Hubbard Payroll Summary forNewTech"<<endl;

sum = 0;
for (counter=0; counter<SIZE&&infile;counter++)
    {
     infile>>SalesAmounts[counter];
     infile>>SalesReps[counter];
      sum = sum +SalesAmounts[counter];
    }
counter--;
average = sum/counter;
cout<<fixed<<showpoint<<setprecision(2);
cout<<"Average sales: "<<setw(8)<<"$"
     <<setw(10)<<average<<endl;

MaxIndex = 0;
for(counter=1; counter<SIZE; counter++)
    if(SalesAmounts[MaxIndex] <SalesAmounts[counter])
      MaxIndex = counter;
LargestSale = SalesAmounts[MaxIndex];

cout<<"Highest sales total:"<<setw(2)<<"$"<<setw(10)
     <<LargestSale<<endl;

return 0;
}

Explanation / Answer

#include #include #include #include using namespace std; const int SIZE = 25; //Size of arrays int main() { double SalesAmounts [SIZE]={0.0}; //Sales amounts array string SalesReps [SIZE]; //Names of sales representativesarray ifstream infile; //Input filestream variable string fnameopen, fnameclose; //Variables to hold actualname of file double sum; int counter=0; //used in for loops double average; //average of sales amount int MaxIndex; //used to find the array with the largestvalue double LargestSale; //variable to hold the largest value cout