Question
C++ help you will use C++ filestreams to read from a file which will contain ticket prices and amount sold and output the results to
C++ help you will use C++ filestreams to read from a file which will contain ticket prices and amount sold and output the results to an output file. The input file that is given will contain two integers on each line separated with a blank space and the line will be terminated with an end of line character.However, there could be negative values and/or non digit characters on each line in which your program needs to handle those situations. The next section will go over the details of the program. Implementation details In the program you will need to create a function int read(istream& in)which takes in the input filestream variable and will return an integer read from the line, it will perform the following: Create astring variable Read in a string (this could be a number string or a non number string) Convert the string into a number using atoi function, so if you have a string called input, then atoi(input.c_str())will return the integer of that string, if this is not an integer, it will simply return a 0 Return the integer using the atoi function, if the atoi function returns a negative value, you will return a 0 So if this function returns a 0, then from main you can determine that there was some kind of input failure Using this function, your main will perform the following: 1. Prompt the user for an input file name 2. Prompt the user for an output file name 3. Open the input and output filestreams. 4. If the input file from step 1 does not exist, out the error and terminate the program 5. Call the read function and store the result into a price variable. 6. If at the end of the file go to step 11 7. Call the read function and store the result into a amount sold variable 8. If the result retrieved from the read function in steps 5 or 7 were 0, then set the price and amount sold both to 0 (this means one or both of the items on that particular line were either a negative number or a non number) 9. Update the total amount of tickets sold and the total prot made 10. Go to step 511. Close the input filestream 12. Using the output filestream variable, output the amount of tickets sold and the prot made nicely formatted and the numbers need to outputted to two decimal places (you may need to convert from integer to double) using the appropriate manipulators 13. Close the output filestream.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started