HW Answer Sheet LMCh3
HW Answer Sheet LMCh3
* Be sure to paste code and screenshots of your executable (black) screen when asked.
1. Answer:
2. Answer:
3. Answer:
4. Answer:
5. Answer:
6. Answer:
7. Answer:
8. Answer:
9. Answer:
1. Complete the program so that a sample run inputting 22 for the number of items bought and 10.98
for the price of each item will produce the results below.
a. Copy of Code & Screenshot:
3. Now put the fixed attribute back in and change the instruction to make the precision 4. Rerun the
program with the same data given in Exercise 1 and record your results. What do you think the
setprecision( ) attribute in the cout statement does?
a. Answer:
4. Add the following directive to the program: #include <string> in the header. Alter the program
so that the program first asks for the name of the product (which can be read into a string
object) so that the following sample run of the program will appear….see lab manual for further
details
a. Copy of Code & Screenshot:
tabledata.cpp (5 pts)
1. Finish the code above by filling in the blanks and the instructions necessary to execute the following
sample run. Note that two or more data items can be input at one time by having at least one blank
space between them before hitting the enter key.
a. Copy of Code & Screenshot:
1. Fill in the missing statement so that the following sample run is implemented:
a. Copy of Code and Screenshot
2. Alter the program so that the sample run now looks like the following:
1. Run this program and record the results. The batting average is ______________________.
2. There is a logic error in this program centering around data types. Does changing the data type
of batavg from int to float solve the problem?
a. Answer:
b. Make that change and run the program again and record the result.
i. Answer: The batting average is _______________________.
3. Continue to work with this program until you get the correct result. The correct result should be
0.292162. Do not change the data type of the two named constants. Instead, use a typecast to
solve the problem.
a. Copy of Code and Screenshot: