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

I have two input files: first file (Ex4-1 Data.txt) 06/01/10 325 421 687 06/22/1

ID: 3640985 • Letter: I

Question

I have two input files:

first file (Ex4-1 Data.txt)
06/01/10
325 421 687
06/22/10
280 470 725
07/10/10
478 690 900
08/17/10
125 469 1245

second file (ex4-2 Data.txt)
08/25/11
214 639 820
09/01/11
10 300 500
09/04/11
299 160 542
09/10/11
100 480 1400

Each file contains 4 sets of data: date and number of tickets sold, where the three numbers separated by one blank represent different types of tickets; Box, Premium, and General ticket type.
The cost per ticket is :
Box ---------850.00
Premium ---425.50
General-----78.90

Ask the user for the name of the input file, and generate the following in the output file (ResultSales.txt);

Date General Box Premium Total per Date

6/1/2010 325 421 687 $ 675,811.00
6/22/2010 280 470 725 $ 730,079.50
7/10/2010 487 690 900 $ 1,007,874.30
8/17/2010 125 469 1245 $ 938,260.00

Ticket Type
Total 1217 2050 3557


Thanks a lot.







(This is what I got so far, but it is not working;


//Create correct preprocessor directives
//Include-to use input & output on the screen
#include<iostream>

//Include-to use string variables
#include<string>

//Include-to use setw, fill and precision variables
#include<iomanip>

//Include to create and use input/output files
#include<fstream>

//Use namespace using statement to use standard header files
using namespace std;

//Create a string constant for the programmer's name
const string PROGRAMMER_NAME ="CST Student";

//Create a string constant for the exercise name
const string STADIUM_NAME ="EMIRATES STADIUM";


//Create the double constants for the cost per ticket
const double BOX_TICKET=850.00;
const double PREMIUM_TICKET=425.50;
const double GENERAL_TICKET=78.90;



//Create the statement to start the main function definition
int main (void)
{

//Define the integer variables for the number of tickets sold, their totals, and number of dates counted
int boxTicketsSold;
int premiumTicketsSold;
int generalTicketsSold;
int totalBoxTicketsSold;
int totalPremiumTicketsSold;
int totalGeneralTicketsSold;
int totalNumberOfDates;

//Define the double variables for the revenue for each type of ticket, total,
double revenueBox;
double revenuePremium;
double revenueGeneral;
double totalPerDate;
double grandTotalRevenue;


string input;
string date;
string file;

//Define input and output stream variables
ifstream inFile;
ofstream outFile;

//Output a divider on the screen
cout.fill('~');
cout<< setw(60+1) <<" "<<endl;
cout.fill(' ');
cout <<endl;

//Provide the two input files for the user
cout << "Enter either: ";
cout << "Ex4-1 Data.txt ";
cout << setw(10) << "OR ";
cout << "Ex4-2 Data.txt ";
cout << "for the file name" << endl;


//Output a divider on the screen
cout.fill('~');
cout<< setw(60+1) <<" "<<endl;
cout.fill(' ');
cout <<endl;


//Get the name of the input file from the user
cout << "Enter the name of the input file ";
cin >> input ;
cout << "The file " << input << ".txt has been successfully opened for processing" <<endl;


//Output a divider on the screen
cout.fill('~');
cout<< setw(60+1) <<" "<<endl;
cout.fill(' ');
cout <<endl;




//Determine if the input file is Ex4-1 or Ex4-2
if (input == "Ex4-1 Data.txt")
{
//Open the first input and report files
inFile.open("Ex4-1 Data.txt");
outFile.open("ReportSales.txt");

//Set up floating point output to the output file
outFile << fixed << setprecision(2);

//Output a divider on the screen
outFile.fill('~');
outFile<< setw(60+1) <<" "<<endl;
outFile.fill(' ');
outFile <<endl;

outFile << setw(45) << STADIUM_NAME <<endl;
outFile << setw (50) << PROGRAMMER_NAME<<endl;

//Output a divider on the screen
outFile.fill('~');
outFile<< setw(60+1) <<" "<<endl;
outFile.fill(' ');
outFile <<endl;

//Read information for first file
inFile>> date;
outFile << "Ticket Sales for : " << date <<endl;
outFile << "Day # 1"<<endl;

//Close the files
inFile.close();
outFile.close();


}

else
{
//Open the second input and report files
inFile.open("Ex4-2 Data.txt");
outFile.open("ReportSales.txt");

//Close the files
inFile.close();
outFile.close();
}







//Create the statement to end the main function definition
//End the program
return 0;
}

Explanation / Answer

Try this out, hope it helps! : #include #include #include using namespace std; //Define some constants const float GENERAL_PRICE = 78.90; const float PREMIUM_PRICE = 425.50; const float BOX_PRICE = 850.00; int main() { int month, day, year; float box, premium, general, totalP = 0, totalB = 0, totalG = 0; string fileName, temp; cout > fileName; ifstream infile(fileName); //Create an input file stream ofstream outfile("ResultSales.txt"); //Create an output file stream outfile