Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Which to use? Use a while loop when you don t know exactly how many times the loop will repeat ( indefinite loop ) Use

Which to use?
Use a while loop when you dont know exactly how many times the loop will repeat (indefinite loop)
Use a for loop when you know exactly how many times the loop will repeat (definite loop)
Both these loops are pre-test loops which means that if the first test fails (is false) then the statements in the loop body are never executed.
The do while loop is also indefinite but is post test so that loop runs the code block at least once before the first test. Every time you get input you do this. You collect data and plan to loop back only to correct it!
Lab:
1. Just submit this document (See directions below.) and insert your work after each task description.
2. For each of the following tasks, provide the complete pseudo code including all elements that we have been using (i.e. class, end class, main return, output prompt). Be sure to declare your variables and use symbolic constants where appropriate. Determine if each task requires a definite or indefinite loop and use the correct one. Use the do while loop for loops that you want to execute at least once, like getting input.
a. Task 1(3 pts): an application program where the user enters the price of a series of items (assume at least one.)(Prompt user for additional items until they are done, so we dont know ahead how many items there will be. This is the looping part! ;) ) The program computes shipping costs. If the total price of all items is $100 or more, then shipping is free otherwise it is 2% of the price. The program should output the total price of all items, the shipping cost, and the total cost.
b. Task 2(4 pts): A program that prompts the user for an initial balance and a monthly interest rate and then displays each new monthly balance for a 12 month period. (Interest is compounded. Print inside the loop so you display each of the 12 balances not just the final.)
c. Task 3(3 pts): A program that collects a series of grades (ranging 0100) until the user indicates that they dont want to continue entering values useing a sentinel value. -1 is a good choice for a sentinel here.)
The program should display the average of the grades entered.
d. Task 4(5 pts): Rock Paper Scissors: The game repeats as long as the user enters Y to a prompt to continue. Get a move from player A and then from player B. Assume that the move is valid so it has to be one of the 3 choices (R P or S). Your program should compute the winner with an appropriate output string: Rock Breaks Scissors Player A wins, etc... And then prompt to play again...
Extra Credit Options:
e. Task 5(4 pts): Code a number guessing game. The user picks a number between 1 and 10 and the computer guesses the value. Each time, the player indicates if the guess is larger or smaller by entering a plus or a minus sign. If the computer guesses the value correctly then the user enters a exclamation point !. Assume in this case that the player/user it truthful.
f. Task 6(2 pts): A program that displays the 12 by 12 multiplication table. This is a bit of a challenge as it requires a nested loop so Ill grant you extra credit if you complete it!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions

Question

The company encourages a balance between work and personal life.

Answered: 1 week ago