Cash-back offer from May 2nd to 7th, 2024: Get a flat 10% cash-back credited to your account for a minimum transaction of $50.Post Your Questions Today!

Question DetailsNormal
$ 30.00

LAB 11 | Complete Solution

Question posted by
Online Tutor Profile
request

LAB 11 LAB OVERVIEW


In this lab, you will read information about shoppers from a file and output summary information about the shopper’s purchases to another file. This lab is designed to give you practice with:
1. File I/O
2. The I/O manipulators for formatting output
3. Command line arguments
Creating functions in this program to output total lines might come in very handy!
PHASE 1 – READING AND FORMATTING THE CONTENTS OF A FILE
This phase will give you practice with reading a file of raw data and re-organizing it to produce a nicely formatted report. Specifically, you will read from a file that contains a list of items purchased for several states and print them out to the console in a nicely formatted table. Each line of the file will have the following format:


state quantityPurchased pricePerItem itemName
…where state is a capitalized, two-character state code, quantityPurchased is the number of items that were purchased, pricePerItem is the cost of a single unit of that item, and itemName is a one word description of the item. The file is sorted by state, so all items belonging to a particular state are grouped together.
An example of a line with the format depicted above could be:
AZ 10 8.75 Shampoo
This line means that the customer purchased 10 bottles of shampoo at a cost of $8.75 per bottle in Arizona.


Your program will obtain the name of the shopping cart file via the first command line argument. Your program will then open this file for input, verify that it did open, read each line, and output information about each line to the screen using cout as follows:
1. state: left justified in a field 2 characters wide
2. item name: left justified in a field 15 characters wide
3. quantity purchased: right justified in a field 3 characters wide
4. price per item: right justified in a field 6 characters wide with 2 decimal points of precision
5. total cost of the item: right justified in a field 7 characters wide with 2 decimal points of precision. This field is calculated as the quantity multiplied by the price per item.


Output the fields separated by a single space.
For example, given the following data in a shopping cart file:
AZ 10 8.75 Shampoo
AZ 3 2.50 Pen
TN 1 879.23 MacAir
TN 5 20.99 Headphones
…your program output must output:
AZ Shampoo 10 8.75 87.50
AZ Pen 3 2.50 7.50
TN MacAir 1 879.23 879.23
TN Headphones 5 20.99 104.95
We will be testing your code with numbers that do not exceed the maximum field width we have specified (i.e., the price per item will be less $1000 and the total purchase cost will be less than $10,000). However, it is worth running at least one experiment where you input price per items that are greater than 1000 so that the price per item cannot fit in a field 6 characters wide. What happens? Is this what you expect?
If the file fails to open, output the following error prompt:
somefile.dat: Unable to open input file for reading.
…and exit your program. Replace somefile.dat with the user provided input file.
If the user doesn’t provide you with a filename via the command line arguments, output the following usage prompt and exit:
mylab.exe <input file>
Replace mylab.exe with the actual name of the executable via the command line arguments. DO NOT hardcode this name.


PHASE 2 – COMPUTING SUMMARY INFORMATION FOR A STATE
In this phase you are going to extend the report produced in phase 1 by printing the total cost of the items purchased by state.
For example, given the shopping cart file shown in Phase 1 your program will output:
AZ Shampoo 10 8.75 87.50
AZ Pen 3 2.50 7.50
AZ Total 95.00
TN MacAir 1 879.23 879.23
TN Headphones 5 20.99 104.95
TN Total 984.18
Grand Total: $ 1079.18

Experiment with the setw manipulator to get your output formatted like ours justified to the right.
For the grand total line there is one blank space between the : and the $. The total should also be 9 digits including the two decimal places justified to the right.
As in phase 1, this output is to the screen using cout.


PHASE 3 – WRITING TO AN OUTPUT FILE
The final task we want your program to perform is to write a summary to an output file in addition to the screen. In this part, the user will provide a second command line argument that represents the name of the output file. You must open this file for output and then add output commands so that the total lines for each state write to this file.
For example, if the input contains the data shown in the previous phases, and the name of the output file is summary.txt, then the contents of summary.txt when your program terminates will be:
AZ Total 95.00
TN Total 984.18
Do NOT output the individual data lines or the grand total to the file. Instead, these individual data outputs will be to the screen as you did in phase 2. The distance between the l in Total and the rightmost digit is the same width you determined in phase 2.
If you are unable to open the output file output:
someoutput.dat: Unable to open output file for writing.
…and exit your program. In this error prompt, replace someoutput.dat with the user provided file name.
If the user doesn’t provide you with an output file or input file for this phase, output the following prompt and exit:
mylab.exe <input file> <output file>
As with phase 1, replace mylab.exe with the actual name of the executable using the command line arguments. DO NOT hardcode this name.

Available Answer
$ 30.00

[Solved] LAB 11 | Complete Solution

  • This solution is not purchased yet.
  • Submitted On 01 Apr, 2015 11:57:55
Answer posted by
Online Tutor Profile
solution
Output Phase_1 AZ Shampoo 10 8.75 87.50 AZ Pen 3 2.50 7.50 TN MacAir ...
Buy now to view the complete solution
Other Similar Questions
User Profile
AceTu...

LAB 11 | Complete Solution

Output Phase_1 AZ Shampoo 10 8.75 87.50 AZ Pen 3 2.50 7.50 TN MacAir 1 879.23 879.23 TN Headphones 5 20.99 104.95 Output Phase_2 AZ ...

The benefits of buying study notes from CourseMerits

homeworkhelptime
Assurance Of Timely Delivery
We value your patience, and to ensure you always receive your homework help within the promised time, our dedicated team of tutors begins their work as soon as the request arrives.
tutoring
Best Price In The Market
All the services that are available on our page cost only a nominal amount of money. In fact, the prices are lower than the industry standards. You can always expect value for money from us.
tutorsupport
Uninterrupted 24/7 Support
Our customer support wing remains online 24x7 to provide you seamless assistance. Also, when you post a query or a request here, you can expect an immediate response from our side.
closebutton

$ 629.35