cosc1315_l4_lab5_2
.docx
keyboard_arrow_up
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
Related Questions
computer programming
Loop is used to repeat a sequence of actions or statements many times. Simplydescribe the differences between for-loop and while-loop.
arrow_forward
assembly language please with comment and screen shot of the out put
arrow_forward
Looping Construct with Floating Point Numbers
Write a program that utilizes a while-loop to read a set of five floating-point values from user
input. Include code to prevent an endless loop. Ask the user to enter the values, then print the
following data:
Total
Average
Maximum
Minimum
Interest on total at 20%
Answer:
arrow_forward
Bug Collector - MUST BE WRITTEN IN PSEUDOCODE
A bug collector collects bugs every day for seven days. Design a program that keeps a running total of the number of bugs collected during the seven days. The loop should ask for the number of bugs collected for each day, and when the loop is finished, the program should display the total number of bugs collected.
arrow_forward
True or False: You should be incrementing the control variable of a for loop
True or False: you can use the control variable of a while loop after the loop has finished executing
True or False: you can nest repetition structures in repetition structures
True or False: you can nest selection structure in selection structures
arrow_forward
Sum of Numbers Problem
Design a program in Python with a loop that asks the user to enter a series of positive numbers. The user should enter a negative number to signal the end of the series. After all the positive numbers have been entered, the program should display their sum.
arrow_forward
MPI Lab Directions
Write an MPI program, countprimes which will count the number of prime numbers in the numbers from 1 to n inclusive where n is a long integer. The value for n which should be set in the program using a constant should be 50,000.
Each process will test its share of the cases.
Each process should not print out any primes that it finds, but it should keep a running total. Before the process finishes, it should print out its ID number and its count of primes that it found.
The master process should end with printing a total for the count of the number of primes and the total amount of time taken to find all the primes.
Take a screenshot of the output for running this with 5 processes.
Before submission, make sure you clean up the directories so that no miscellaneous files are kept around in the submission. (Grade would be deducted if useless files are found in the homework directories.) Include the source code, screenshot, and the Makefile in the submission. Your…
arrow_forward
JAVA
If the for loop counter variable is declared and initialized in the for loop header the variable only has scope inside the for loop body.
True
False
arrow_forward
Identif the data type of x after the statment executes: x = 7 // 2 + 3
int
float
str
arrow_forward
Lap Timer Tool
Write a program ON PYTHON that asks the user to enter the number of times that they have run around a racetrack, and then uses a loop to prompt them to enter the lap time for each of their laps. When the loop finishes, the program should display the time of their fastest lap, the time of their slowest lap, and their average lap time.
arrow_forward
Activity 7
Guessing Game
There is list of word, the interpreter will choose a word randomly. The user has to input his names and then, he
will be asked to guess the word by accepting any alphabet. If the random word contains accepted character, it
will be shown as the output (with correct placement) else the program will ask you to guess another alphabet.
User will be 50% of the total number of characters to guess the complete word.
Requirements
1. There must be 10 words of different length.
2.
The words must be in random.
3. It should accept lower case and upper case letter
4. The number of turns left must be display
5. All wrong characters are also display
arrow_forward
Exercise # 8 – Student Number Password
Description of the Problem
Write a program that inputs your student number and printout your Biography when the student number
is correct. Use a Do While / While loop to repeat the process when an incorrect student number is placed.
Sample Output
Enter your student no. : 29766512
Name : Lastname, Firstname MI
Course : [your course here]
Favorite [write something here]: [your favorite 1]
Favorite [write something here] : [your favorite 2]
Favorite quotation : "quotation here"
Enter your student no. : 88888888
"Incorrect Student No.!!"
Note : Template will not be available for this one. As the code is very short to finish the exercise.
arrow_forward
PROGRAMMING LANGUAGE: C++ALSO PASTE SCREENSHOTS OF OUTPUTS
You are required to create a simulation of an elevator system. There are 7 floors in a building. A user may enter the elevator and press the button of the destined floor. The simulation should display appropriate messages while moving towards the destined floor.
arrow_forward
All of the following are looping control structures except
Select one:
while loop
do-while loop
for loop
do loop
none; all of these are looping control structures
arrow_forward
True or False
___(4) In a while loop, the body of the loop has to be executed at least once whether the test is true or not.
___(5) In Java a while loop can be changed to a for loop and vice versa.
___(6) Java statement !( x / 3 = = 6 ) || y*3 = = -6 ; evaluates to false if x=19 and y= -2
arrow_forward
True or False: The do-while loop is a pretest loop, as opposed to a main loop.
arrow_forward
ASSIGNMENT BRIEF
Introduction
Roulette is a popular casino game named after the French word for 'little wheel'. In the game, players
may choose to place bets on single numbers or various groupings which will determine their payout.
To determine the winning number a ball is spun in the opposite direction of a spinning wheel. As the
ball loses momentum it comes to rest in one of the slots of the wheel.
Winnings are then paid to anyone who places a successful bet.
n 00
2.
1ST12
2ND12
3RD12
1T018 EVEN
ODD |19то36
Figure 1: Layout of a European roulette table
Numbers can be classified in several ways:
1. Red or Black
2. Odd or Even
3. High or Low - if a number is in the first half of the table it is considered low (1-18).
If a number is in the second half of the table, it is considered high (19-36).
4. Dozens - a number can be in the first dozen(1-12), second dozen (13-24) or third dozen (25-36)
5. Columns - A number may be in any of the three columns of the table
6. Zero - the number '0'…
arrow_forward
Card guessing Design a strategy that minimizes the expected number of questions asked in the following game
You have a deck of cards that consists of one ace of spades, two deuces of spades, three threes, and on up to nine nines, making 45 cards in all.
Someone draws a card from the shuffled deck, which you have to identify by asking questions answerable with yes or no.
arrow_forward
HELP NEEDED ASAP!
Language: JAVA
Write a program that prompts the user for a value greater than 10 as an input (you should loop until the user enters a valid value) and finds the square root of that number and the square root of the result, and continues to find the square root of the result until you reach a number that is smaller than 1.01. The program should output how many times the square root operation was performed.
arrow_forward
A count-controlled loop must possess three elements:
arrow_forward
11 Worksheet 5
Note:Solution using Matlab Code
Write a program that prompts the user to enter a number within the range of 1 through 7, those
numbers represent the weekdays as shown in the table. If the entered number is more than 7,
display 'invalid day'.
Number
1
2
3
4
5
6
7
Day
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Type of the day
Workday
Workday
Workday
Workday
Workday
Weekend
Weekend
The program should continue to repeat itself 10 times, after which, the program should stop.
Furthermore, the program should be able to show a message saying if this is a 'workday' or a
'weekend day'.
Note: you are required to add a comment beside your command. Hint: to add a comment you
may use the % sign. thank guys you dodo great.
arrow_forward
C++ Memory Game
Children often play a memory game in which a deck of cards containing matching pairs is used. The cards are shuffled and placed face down on a table. The players take turns and select two cards at a time. If both cards match, they are left face up; otherwise, the cards are placed face down at the same positions. Once the players choose their pair, they can see the board for some time period and attempt to memorize the configuration of cards. They can then use their memory to select the next pair of cards when it is their turn. The game continues until all the cards are face up. Assume that there are two players and to make the game interesting, keep track of how many correct matches each player makes. When all the cards are turned face up, the player with the most matches is the winner. Write a program to play the memory game. Use a two-dimensional array of 4 rows and 4 columns for a deck of 16 cards with 8 matching pairs. You can use numbers 1 to 8 to mark the cards.…
arrow_forward
JAVA CODE PLEASE
FINAL EXAM Part 3
Instructions:
Create a java program that asks & accepts input from the user (must be int value). Then depending on the number of inputs, the program will ask the user to enter string value/s. After, the program will print the strings entered by the user line-by-line.
Constraints:
Create a function and call it in the main function.
Use Functions With No Parameters and Return Values
Use for Loop
Use String Array
Use Scanner
Input
1. One line containing an integer
Sample
2
2. One line containing string
Sample
Funny
3. One line containing string
Sample
Sadly
Output
Enter·the·number·of·string·array:·2
Enter·string·#1:·Funny
Enter·string·#2:·Sadly
You've·entered:
Funny
Sadly
arrow_forward
Java - Painting a Wall
arrow_forward
Warm-up: Integer Operations
Write a program that asks the user to enter two integers and prints the Difference, Product, Area of an Ellipse, and Average of these numbers.
Here is an example of the execution of the program:
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Related Questions
- computer programming Loop is used to repeat a sequence of actions or statements many times. Simplydescribe the differences between for-loop and while-loop.arrow_forwardassembly language please with comment and screen shot of the out putarrow_forwardLooping Construct with Floating Point Numbers Write a program that utilizes a while-loop to read a set of five floating-point values from user input. Include code to prevent an endless loop. Ask the user to enter the values, then print the following data: Total Average Maximum Minimum Interest on total at 20% Answer:arrow_forward
- Bug Collector - MUST BE WRITTEN IN PSEUDOCODE A bug collector collects bugs every day for seven days. Design a program that keeps a running total of the number of bugs collected during the seven days. The loop should ask for the number of bugs collected for each day, and when the loop is finished, the program should display the total number of bugs collected.arrow_forwardTrue or False: You should be incrementing the control variable of a for loop True or False: you can use the control variable of a while loop after the loop has finished executing True or False: you can nest repetition structures in repetition structures True or False: you can nest selection structure in selection structuresarrow_forwardSum of Numbers Problem Design a program in Python with a loop that asks the user to enter a series of positive numbers. The user should enter a negative number to signal the end of the series. After all the positive numbers have been entered, the program should display their sum.arrow_forward
- MPI Lab Directions Write an MPI program, countprimes which will count the number of prime numbers in the numbers from 1 to n inclusive where n is a long integer. The value for n which should be set in the program using a constant should be 50,000. Each process will test its share of the cases. Each process should not print out any primes that it finds, but it should keep a running total. Before the process finishes, it should print out its ID number and its count of primes that it found. The master process should end with printing a total for the count of the number of primes and the total amount of time taken to find all the primes. Take a screenshot of the output for running this with 5 processes. Before submission, make sure you clean up the directories so that no miscellaneous files are kept around in the submission. (Grade would be deducted if useless files are found in the homework directories.) Include the source code, screenshot, and the Makefile in the submission. Your…arrow_forwardJAVA If the for loop counter variable is declared and initialized in the for loop header the variable only has scope inside the for loop body. True Falsearrow_forwardIdentif the data type of x after the statment executes: x = 7 // 2 + 3 int float strarrow_forward
- Lap Timer Tool Write a program ON PYTHON that asks the user to enter the number of times that they have run around a racetrack, and then uses a loop to prompt them to enter the lap time for each of their laps. When the loop finishes, the program should display the time of their fastest lap, the time of their slowest lap, and their average lap time.arrow_forwardActivity 7 Guessing Game There is list of word, the interpreter will choose a word randomly. The user has to input his names and then, he will be asked to guess the word by accepting any alphabet. If the random word contains accepted character, it will be shown as the output (with correct placement) else the program will ask you to guess another alphabet. User will be 50% of the total number of characters to guess the complete word. Requirements 1. There must be 10 words of different length. 2. The words must be in random. 3. It should accept lower case and upper case letter 4. The number of turns left must be display 5. All wrong characters are also displayarrow_forwardExercise # 8 – Student Number Password Description of the Problem Write a program that inputs your student number and printout your Biography when the student number is correct. Use a Do While / While loop to repeat the process when an incorrect student number is placed. Sample Output Enter your student no. : 29766512 Name : Lastname, Firstname MI Course : [your course here] Favorite [write something here]: [your favorite 1] Favorite [write something here] : [your favorite 2] Favorite quotation : "quotation here" Enter your student no. : 88888888 "Incorrect Student No.!!" Note : Template will not be available for this one. As the code is very short to finish the exercise.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT