Starting from:

$29.99

COP3331 Lab 3 Solution

Directions:
• Create a folder named Lab3 LastName FirstInitial (e.g. Lab3 Neal T).
• In your folder, place a PDF file containing your answers to questions with a ♦.
• Ensure that all programs have block comments at the very beginning (starting at the first line) in the file containing main() with your name and the program’s description. The block comment’s format should be identical to what’s provided in Figure 2-1.
• Use single-line comments to describe your code’s functionality as needed.
• Do not submit anything for questions with a ♣.
• Zip the folder and submit it via Canvas.
Points: ♦ = 5 points each, ♠ = 15 points each

1. ♣ Read Chapter 5: How to work with I/O streams and files.
2. ♦ A buffer is
a. a location in memory where stream data is stored after it’s read or written
b. a location on disk where stream data is stored after it’s read or written
c. a location in memory where stream data is stored as it’s read or written
d. a location on disk where stream data is stored as it’s read or written
3. ♠ Create a program that reads the sales for 12 months from a file and calculates the total yearly sales as well as the average monthly sales. The user can enter ‘m’, ‘y’, or ‘x’ as commands to view the sales, yearly summary, or exit the program, respectively. Place your solution file(s) in folder lab3 q3 for submission.
Console
Monthly Sales
COMMAND MENU m - View monthly sales y - View yearly summary x - Exit program Command: m
MONTHLY SALES
Jan 14317.41
Feb 3903.32
Mar 1073.01
Apr 3463.28
Jun 4324.70
Jul 9762.31
Aug 25578.39
1
Sep 2437.95
Oct 6735.63
Nov 288.11
Dec 2497.49
Command: a Invalid command. Try again.
Command: y
YEARLY SUMMARY
Yearly total: 76811.12
Monthly average: 6400.93
Command: x Bye!
Specifications
• I’ve provide a tab-delimited file named monthly sales.txt that contains the month and sales data shown above.
• Round the results of the monthly average to a maximum of 2 decimal digits and make sure that a minimum of 2 decimal digits are displayed on the console.
• Right-align the columns that display the monthly sales, the yearly total, and the monthly average.
Note for Xcode users
• To get this to work correctly on your system, you can set a full path to the file in your code, or you can change the working directory for the Xcode project to the directory that contains the text file.
• To change the working directory for the Xcode project, open the project and select the Product→Scheme→Edit Scheme item. Then, select the Run category, check the Use Custom Working Directory box, and specify the working directory.
4. ♣ Read Chapter 7: How to code functions.
5. ♣ Read Chapter 8: How to test, debug, and deploy a program.
6. ♦ What line number of the following code contains an error and what type of error is it?
1. double sales_tax(amt) {
2. double sale = amt + (amt * .06);
3. return amt;
4. }
5.
6. int main() {
7. cout << "Welcome to the 6% tax calculator! ";
8. double total;
9. cout << "Please enter the total amount: ";
10. cin >> total;
11. cout << "The total amount after tax is: " << sales_tax(total);
12. }
a. line 1, runtime error
b. line 1, syntax error
c. line 3, syntax error
d. line 11, logic error
2

More products