Question: This is a combination Lab (based on Chapter 5) and JavaScript Assignment. Please complete the lab and the JavaScript program as outlined in the attached.
This is a combination Lab (based on Chapter 5) and JavaScript Assignment.
Please complete the lab and the JavaScript program as outlined in the attached.
Lab 5: Repetition Structures
This lab accompanies Chapter 5 of Starting Out with Programming Logic & Design.
Name: ___________________________
Lab 5.1 Repetition Structures Pseudocode: Condition Controlled Loops
| Critical Review A repetition structure causes a statement or set of statements to execute repeatedly.
Repetition structures are used to perform the same task over and over.
Repetition structures are commonly called loops
A condition-controlled loop uses a true/false condition to control the number of times that it repeats.
The general structure of a While loop with a condition-controlled statement is:
//Declare loop control variable While condition Statement Statement Etc. //Ask Question that changes the loop control variable End While
The general structure of a Do While loop with a condition-controlled statement is:
//Declare loop control variable Do Statement Statement Etc. //Ask Question that changes the loop control variable While Condition
|
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
This variable will store the accumulated bottle values
A variable called counter and that is initialized to 1
This variable will control the loop
A variable called todayBottles that is initialized to 0
This variable will store the number of bottles returned on a day
A variable called totalPayout that is initialized to 0
This variable will store the calculated value of totalBottles times .10
A variable called keepGoing that is initialized to y
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
___________________________________________________
___________________________________________________
___________________________________________________
___________________________________________________
___________________________________________________
//Step 3: Loop to run program again
While _________________________________
//Step 2: Call functions
_____________________________________________
_____________________________________________
_____________________________________________
Display Do you want to run the program again? (Enter y for yes).
Input _________________________________
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.______________________________________)
While b._______________________________
Display Enter number of bottles returned for the day:
Input c.______________________________
d. ___________________________________
e. _____________________________________
End While
End Module
Step 5: In the pseudocode below, write the missing lines, including:
a.The missing parameter list
b.The missing calculation
//getBottles module
Module calcPayout(a.______________________________________)
totalPayout = 0 //resets to 0 for multiple runs
b. _______________________________________________
End Module
Step 6: In the pseudocode below, write the missing lines, including:
a.The missing parameter list
b.The missing display statement
c.The missing display statement
//printInfo module
Module printInfo(a.______________________________________)
_______________________________________________
_______________________________________________
End Module
Step 7: Write the JavaScript code to implement your algorithm
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
