Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

lab 8.1 for loop an accumulation with pseudocode this lab requires you to implem

ID: 3536485 • Letter: L

Question

lab 8.1 for loop an accumulation with pseudocode



this lab requires you to implement a count-controlled loop using a for loop.



step:1 examine the following code.


Constant Integer MAX_HOURS = 24

Declare Integer hours


For hours = 1 to MAX_HOURS

Display "THe hour is ", hours

End For


step 2: Explain what you think will be displayed in the screen in step 1.

_________________________________________________________

_______________________________________________________



step 3: Write a for loop that will print 60 minutes to the screen complete the missing lines of code.


Constant Integer MAX_MINUTES = ____________________

Declare Integer minutes


For _______________ = 1 to _____________

Display _____________________________

End For


Step 4: Write a for loop that will print 60 seconds to the screen. Complete the missing lines of code.


Constant Integer MAX_SECONDS = ________________________________

Declare Integer Seconds


For _______________ = 1 to __________________

Display _____________________________

End For


Step 5: For Loops can also be used to increment by more than one. Examine the following code.


Constant Integer MAX_VALUE = 10

Declare Integer counter


For counter = 0 to MAX_VALUE step 2

Display "The number is ", counter

End For


Step 6: Explain what you think will br displayed to the screen in step 5.

________________________________________________________

___________________________________________________________

________________________________________________________


step 7: Write a for loop that wil display the numbers starting at 20, then 40, then 60, and continuing the sequence all the way to 200.


Constant Integer MAX_VALUE = ________________________

Declare Integer counter

For counter = ____________ to MAX_VALUE Step _______________

Display "The number is ",_______________

End For


Step 8: For loops can also be used when the user controls the number of iterations. Examine the following code.


Declare Integer numStudents

Declare Integer counter


Display "Enter the number of students in class"

Input numStudents


For counter = 1 to numStundents

Display "Student #", counter

End For


Step 9: Explain what you think will be displayed to the screen in step 8

_________________________________________________________

__________________________________________________________

_____________________________________________________


Step 10: For loops are also commonly used to calculate a running total (acccumulation)

examine the following code.


Declare Integer counter

Declare Integer total = 0

Declare Integer number


For counter = 1 to 5

Display "Enter a number: "

Input number

Set total = total + number

End For

Display "The total is:", total


Step 11: Explain what you think will be displayed to the screen in step 10.

_______________________________________________________

_________________________________________________________

_______________________________________________________


Step 12: Write the missing lines for a program that will allow the user to enter how many ages they want to enter and then find the average.


Declare Integer counter

Declare Integer totalAge = 0

Declare Real averageAge = 0

Declare Integer age

Declare Integer number


Display "How many ages do you want to enter:"

Input ________________________________________


For counter = 1 to number

Display "Enter age: "

Input __________________

Set totalAge = _________________________ + _________________

End For


averageAge = _________________________ / ____________________________


Display "The average age is ", _________________________________




  

Explanation / Answer

lab 8.1 for loop an accumulation with pseudocode
this lab requires you to implement a count-controlled loop using a for loop.
step:1 examine the following code.
Constant Integer MAX_HOURS = 24
Declare Integer hours
For hours = 1 to MAX_HOURS
    Display "THe hour is ", hours
End For

step 2: Explain what you think will be displayed in the screen in step 1.
__for loop start from 1 and ends at 24_display will be_______
__THe hour is 1, THe hour is 2,THe hour is 3..........THe hour is 24

step 3: Write a for loop that will print 60 minutes to the screen complete the missing lines of code.
Constant Integer MAX_MINUTES = _____60_______________
Declare Integer minutes
For _____minutes__________ = 1 to ___MAX_MINUTES__________
       Display _____"THe minutes is ", minutes
End For

Step 4: Write a for loop that will print 60 seconds to the screen. Complete the missing lines of code.
Constant Integer MAX_SECONDS = _______60_________________________
Declare Integer Seconds
For ______Seconds_________ = 1 to _______MAX_SECONDS___________
     Display ______"THe Seconds is ", Seconds
End For

Step 5: For Loops can also be used to increment by more than one. Examine the following code.
Constant Integer MAX_VALUE = 10
Declare Integer counter
For counter = 0 to MAX_VALUE step 2
      Display "The number is ", counter
End For

Step 6: Explain what you think will br displayed to the screen in step 5.
________number is increasing at rate of 2 so_______display will be
The number is 0, The number is 2,The number is 4,The number is 6,The number is 8,The number is 0

step 7: Write a for loop that wil display the numbers starting at 20, then 40, then 60, and continuing the sequence all the way to 200.
Constant Integer MAX_VALUE = _________200_______________
Declare Integer counter
For counter = ______20______ to MAX_VALUE Step ___20____________
        Display "The number is ", counter
End For

Step 8: For loops can also be used when the user controls the number of iterations. Examine the following code.
Declare Integer numStudents
Declare Integer counter
Display "Enter the number of students in class"
Input numStudents
For counter = 1 to numStundents
     Display "Student #", counter
End For
Step 9: Explain what you think will be displayed to the screen in step 8
___it depends on the input ____numStudents__________________________________________________
if numStudents is 5 then display will be
Student 1
Student 2
Student 3
Student 4
Student 5

Step 10: For loops are also commonly used to calculate a running total (acccumulation)
examine the following code.
Declare Integer counter
Declare Integer total = 0
Declare Integer number
For counter = 1 to 5
     Display "Enter a number: "
     Input number
     Set total = total + number
End For
Display "The total is:", total
Step 11: Explain what you think will be displayed to the screen in step 10.
for loop running 5 times, so Enter a number will be displayed 5 times.
at the end display will be The total is: ( sum of those five inputted numbers)

Step 12: Write the missing lines for a program that will allow the user to enter how many ages they want to enter and then find the average.
Declare Integer counter
Declare Integer totalAge = 0
Declare Real averageAge = 0
Declare Integer age
Declare Integer number
Display "How many ages do you want to enter:"
Input _________number_______________________________
For counter = 1 to number
    Display "Enter age: "
    Input __age________________
    Set totalAge = ________Set totalAge_________________ + ____age;_____________
End For
averageAge = _______Set totalAge__________________ / ______number______________________
Display "The average age is ", ______averageAge___________________________