cosc1315_l4_lab5_2

.docx

School

Central Texas College *

*We aren’t endorsed by this school

Course

COSC 1315

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

3

Uploaded by JusticeUniverse2467

Lesson 4 Lab 5.2 –Repetition Structures Pseudocode: Counter Controlled Loops Critical Review A count-controlled loop repeats a specific number of times. The loop keeps a count of the number of times that it iterates, and when the count reaches a specified amount the loop stops. A variable, known as a counter variable, is used to store the number of iterations that it has performed. The three actions that take place are initialization, test, and increment. Initialization: Before the loop begins, the counter variable is initialized to a starting value. Test: The loop tests the counter variable by comparing it to a maximum value. Increment: To increment a variable means to increase its value. This is done by adding one to the loop control variable. Any loop can be used with a count-controlled loop. A running total is a sum of numbers that accumulates with each iteration of a loop. The variable used to keep the running total is called an accumulator. This lab requires you to write a complete program using a condition controlled loop, a counter controlled loop, and an accumulator. The program is a follows: Write a program that will allow a grocery store to keep track of the total number of bottles collected for seven days. The program should allow the user to enter the total number of bottles returned for seven days. The program will calculate the total number of bottles returned for the week and the amount paid out (the total returned times .10 cents). The output of the program should include the total number of bottles returned and the total paid out. Step 1: In the pseudocode below, declare the following variables under the documentation for Step 1. A variable called totalBottles that is initialized to 0 o This variable will store the accumulated bottle values A variable called counter and that is initialized to 1 o This variable will control the loop A variable called todayBottles that is initialized to 0 o This variable will store the number of bottles returned on a day A variable called totalPayout that is initialized to 0 o This variable will store the calculated value of totalBottles times .10
A variable called keepGoing that is initialized to “y” o This variable will be used to run the program again Step 2: In the pseudocode below, make calls to the following functions under the documentation for Step 2. A function call to getBottles that passes totalBottles, todayBottles, and counter. A function called calcPayout that passes totalPayout and totalBottles. A function called printInfo that passes totalBottles and totalPayout Step 3: In the pseudocode below, write a condition controlled while loop around your function calls using the keepGoing variable under the documentation for Step 3. Complete Steps 1-3 below: Module main () //Step 1: Declare variables below Declare Integer totalBottles = 0 Declare Integer counter = 1 Declare Integer todayBottles = 0 Declare Real totalPayout = 0 Declare String keepGoing = "y" //Step 3: Loop to run program again While keepGoing == "y" //Step 2: Call functions Call getBottles(totalBottles, todayBottles, counter) Call calcPayout(totalPayout, totalBottles) Call printInfo(totalBottles, totalPayout) Display “Do you want to run the program again? (Enter y for yes).” Input keepGoing End While End Module Step 4: In the pseudocode below, write the missing lines, including: a. The missing parameter list b. The missing condition (Hint: should run seven iterations) c. The missing input variable d. The missing accumulator e. The increment statement for the counter //getBottles module Module getBottles( a. totalBottles, todayBottles, counter ) While b . counter <= 7 Display “Enter number of bottles returned for the day: Input c. todayBottles
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help