IT1090cLab3

.docx

School

University of Cincinnati, Main Campus *

*We aren’t endorsed by this school

Course

1090

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

8

Uploaded by MegaRainMandrill31

Report
IT 1090C Computer Programming I Prof. Tom Wulf Lab 3 Looping 15 pts / 6 extra Mini-lecture: We will continue to refine our pseudo code. Now, we will look at looping We looked at looping in class. Java has a while loop and a for loop. These are both pre-test loops. The for loop is a definite loop and the while loop is an indefinite loop. (Java also has a post-test indefinite loop: do..while. Here is the flowchart and the pseudo code for an indefinite loop that uses a sentinel to terminate the repetition of the loop. In this variation the sentinel is the value “N” which the user enters when they are prompted if they want to continue or not. Here is the general format for the while loop in pseudo code: while BOOLEAN EXPRESSIO statements here that will be repeated endWhile As discussed, Boolean expressions are expressions that evaluate to true or false. These are formed by relational operators (<. >,< =,>=, !=) and the logical operators AND && and OR ||. Copyright © 2019-2020, University of Cincinnati, Ohio. All rights reserved.
For loops: For loops are definite pre-test loops. Use these when you want to repeat something some fixed number of times. Copyright © 2019-2020, University of Cincinnati, Ohio. All rights reserved.
Pseudo code for the for loop: for count = 1 to 5 step 1 these statements repeat endFor Pseudo code for the do .. while loop do these statements repeat while BOOLEAN EXPRESSION Which to use? Use a while loop when you don’t 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 don’t know ahead how many items there will be. This is the looping part! ;) ) The program computes shipping costs. Copyright © 2019-2020, University of Cincinnati, Ohio. All rights reserved.
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