Top-Rated Free Essay

Lab 7 Student

Satisfactory Essays
Topics: Statement
Lab 7: Repetition Structures I
This lab accompanies Chapter 5 (pp. 163-183 and pp. 196-201) of Starting Out with Programming Logic & Design.

Name: ___________________________

Lab 7.1 –Condition Controlled with While and Do-While Loops: Pseudocode

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

Help Video: Double click the file to view video

Step 1: Examine the following pseudocode main module from Lab 4.1. Loops are commonly used to call modules multiple times. The best design is to use a loop around the module calls in Main.

Module main () //Declare local variables
Declare String clientName = “ “
Declare Real feetUTP = 0
Declare Real subTotal = 0
Declare Real taxCost = 0
Declare Real totalCost = 0

//Module calls
Call inputData(feetUTP, clientName)
Call calcCosts(feetUTP, subTotal, taxCost, totalCost)
Call displayBill(clientName, totalCost)

End Module

Step 2: In the space provided, re-write the pseudocode for the main module with a condition controlled While or a Do-While loop so that the program runs multiple times. Create a loop control variable named keepGoing of the data type string and initialize this variable to “y”. Don’t forget to indent the contents of your loop. (Reference: Modularizing the Code in the Body of a Loop, page 172).

Module main () Declare String keepGoing = y While keepGoing == y
Declare String clientName =
Declare Real feetUTP = 0
Declare Real subTotal = 0
Declare Real taxCost = 0
Declare Real totalCost = 0

Call inputData (feetUTP, clientName)
Call calcCosts (feetUTP, subTotal, taxCost, totalCost)
Call displayBill (clientName, totalCost)
End While
End Module

Lab 7.2 –Condition Controlled with While and Do-While Loops: Flowcharts

Critical Review

In a while loop, the question is asked first. After the statements process, the control goes back above the condition.

In a do-while loop, the question is asked last. The statements always process at least one time.

Help Video: Double click the file to view video

Step 1: Examine the following main module from Lab 4.2. Loops are commonly used to call modules multiple times. The best design is to use a loop around the module calls in Main (Reference: Modularizing the Code in the Body of a Loop, p. 173).

Step 2: Redesign the main module with a condition controlled While or a Do-While loop so that the program runs multiple times, based on the pseudocode from Lab 7-1.

PASTE FLOWCHART HERE

Lab 7.3 –Count Controlled with While and Do-While Loops: Pseudocode

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.

The general structure of a While loop (although it is the same process with a Do-While loop) with a count-controlled statement is:

//Declare loop control variable
Declare Integer counter = 1
While condition Statement Statement Etc. //increment counter Set counter = counter + 1
End While

Help Video: Double click the file to view video

Step 1: Understanding how to raise a number to the power of 2 is very important to the field of networking as it relates to binary conversion. Convert the following algorithm to pseudocode using a count controlled do while or while loop:

1. Create three integer variables called toPower, number, and counter. Set counter to 0, and toPower and number to 2.
2. Write a do while loop or while loop that will run 7 iterations.
3. Inside the loop, set toPower equal to 2 to the power of the number variable.
4. Display “2 to the power of”, number, “ is”, toPower to the screen
5. Increment counter and number by 1

Module Main()
Declare integer toPower = 2
Declare integer number = 2
Declare integer counter = 0
While Counter < <7
Set toPower = 2^Number
Display 2 to the power of, number, is,toPower, Counter += 1
Number += 1
End While
End Module

Lab 7.4 –Count Controlled with While and Do-While Loops: Flowcharts

Critical Review

In a count controlled while or do-while loop, the flowchart is essentially the same as a condition controlled, except you must create a counter and manually increment the counter variable. The general flow using a while loop looks as follows:

Help Video: Double click the file to view video

Step 1: Using your pseudocode from lab 7-3, design either a while or a do while loop of raising 2 to the power of 2-8 to the screen.

PASTE FLOWCHART HERE
Lab 7.5 –While and Do While Loops: Visual Basic Challenge I

Critical Review

Visual Basic supports both While and Do While loops. The general syntax for a condition controlled loop is as follows:

While loop:

While keepGoing = "yes"

End While

Do While loop:

Do While keepGoing = "yes" Loop

Visual Basic will automatically end your While with an End While, and end your Do While with the Loop.

Count controlled loops are structured the same way, but you must declare a counter variable as an Integer as loops only count in whole increments. Additionally, do not forget to increment or decrement your counter variable.

Help Video: Double click the file to view video

Write either the Pseudocode OR Flowchart AND the Visual Basic Code

Design a program that will use your pingMe() module from Lab 4-4. There should be a condition controlled loop in Main to run the program multiple times if the user wants. Additionally, in the pingMe() module, there should be a count controlled loop that will ping your system after a count down of 5 (Reference p. 199, Decrementing). You may use while or do while loops. Your output may look as follows:

PASTE FLOWCHART OR PSEUDOCODE HERE

PASTE VISUAL BASIC CODE HERE
Lab 7.6 –While and Do While Loops: Visual Basic Challenge II

Based on Lab 7-3 and 7-4, code the flowchart/pseudocode by converting 2 to the power of a number from 2 to 8. You should have a main module that calls a module called displayPower() as many times as the user types yes (using a condition controlled loop). The displayPower() module should use a count controlled loop that raises the toPower variable to 2 to the power of the number, such as toPower = 2 ^ number. The output should look as:

Help Video: Double click the file to view video

PASTE VISUAL BASIC CODE HERE

You May Also Find These Documents Helpful

  • Good Essays

    Lab 7

    • 995 Words
    • 4 Pages

    Lab 7: Geologic Time 9 Answer Sheet Name(s) 1. As an example of how radioactive decay works, the TA may lead a small demonstration. Each student will receive one penny and stand up. At this point all of the students are parent isotopes. Every student should then flip their penny. Students whose penny lands heads-up should sit down. These students who are now seated are now daughter isotopes. The remaining standing students should again flip their penny, and students whose penny lands heads-up…

    • 995 Words
    • 4 Pages
    Good Essays
  • Powerful Essays

    Lab 7

    • 1276 Words
    • 9 Pages

    Introduction to Networking GRADED ASSIGNMENTS Unit 9 Research 1: Network Design, Part 1 Course Objectives and Learning Outcomes Show competency in all outcomes for this course. Assignment Requirements Now it is time for you to put your networking knowledge to work. Read through the Network Design: Kamazon.kom Network Upgrade information and make sure you understand the customer’s requirements. Your instructor will act as Kamazon’s representative, so if you have questions or need clarification…

    • 1276 Words
    • 9 Pages
    Powerful Essays
  • Satisfactory Essays

    LAB 7

    • 354 Words
    • 2 Pages

    How much available shrink space is contained in the volume? 449MB 6. How is the last volume you created different from the previous ones? Explain why. The size of the volume is different. By shrinking the file it made the volumes less than 2000MB 7. What do you suppose would happen if you created another simple volume out of the free space left on the disk? I think that the it will run out of recourse. 8. Were you successful? No, The extend option is grayed out. 9. What is the result? It was…

    • 354 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Lab 7

    • 928 Words
    • 3 Pages

    1. What are some common risks, threats, and vulnerabilities commonly found in the LAN-to-WAN Domain that must be mitigated through a layered security strategy? A layered security strategy will encompass Rouge protocols such as Bit mining and P2P, Unauthorized network scanning and probing, and unauthorized access to the network. 2. What is an Access Control List (ACL) and how is it useful in a layered security strategy? An ACL is a Control list which will allow or deny traffic or devices based on…

    • 928 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    NT1210 Lab 7

    • 346 Words
    • 2 Pages

    Chapter 7 Lab 7.1.1 Why is it impractical for an organization to own the entirety of a WAN? There are no limitations on WANs so they can be custom built for the size of the organization. Why is it favorable for an organization to maintain ownership of the entirety of the LAN? Because the purpose of organizational expansion. Table 7-1 WAN Physical Media Media Infrastructure Summary UTP Phone lines The quality of UTP may vary from telephone-grade wire to extremely high-speed cable. The cable…

    • 346 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    IT220 Lab 7

    • 303 Words
    • 2 Pages

    Frantzy Senat IT220 Lab 7 Lab 7.1 Exercise 7.1.1 Its impractical for whole organization to own a whole WAN because it could be great distances or overseas or across the country. It would be better to own the LAN to be able to control the cost of the set up Exercise 7.1.2 Increasing the distance would help due to making easier to…

    • 303 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    IS3445 Lab 7

    • 371 Words
    • 2 Pages

    Lab 7 IS3445 Security Strategies for Web Applications and Social Networking Lab 7 Assessment 1. How does Skipfish categorize findings in the scan report? As high risk flaws, medium risk flaws, and low issue scans 2. Which tool used in the lab is considered a static analysis tool? Explain what is referred to by static code analysis. RATS, because the running of static code analysis tools that attempt to highlight possible vulnerabilities within ‘static’ (non-running) source code. 3. What possible…

    • 371 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Unit 7 Subnetting Lab 7

    • 1327 Words
    • 6 Pages

    Unit 7 Subnetting Lab 7 Read the lab details listed below, and then answer the questions listed in the lab exercise. CIDR (Classless InterDomain Routing) and VLSM CIDR (Classless Inter-Domain Routing) was introduced in 1993 (RCF 1517) replacing the previous generation of IP address syntax - classful networks. CIDR allowed for more efficient use of IPv4 address space and prefix aggregation, known as route summarization or supernetting. CIDR introduction allowed for: • More efficient use…

    • 1327 Words
    • 6 Pages
    Satisfactory Essays
  • Powerful Essays

    Lab 7 & 8

    • 1094 Words
    • 5 Pages

    Week 4 Lab Part 1: Design a Multi-factor Authentication Process Assessment Worksheet Design a Multi-factor Authentication Process Lab Assessment Questions & Answers 1. In an Internet Banking Financial Institution is Single Factor Authentication acceptable? Why or why not? Yes it can be acceptable because you can buff up security elsewhere. 2. Explain the difference between Positive Verification and Negative Verification? Negative verification is the opposite of positive verification…

    • 1094 Words
    • 5 Pages
    Powerful Essays
  • Better Essays

    Organic Lab 7

    • 1806 Words
    • 8 Pages

    Amanda Jornd Experiment 7- Synthesis and Reactivity of tert-Butyl Chloride Via an SN1 Reaction Introduction/Background: Alkyl halides are compounds in which a halogen atom replaces a hydrogen atom of an alkane. Alkyl halides are classified as primary, secondary or tertiary depending on the number of alkyl substituents directly attached to the carbon attached to the halogen atom. The purpose of this lab was to properly prepare t-butyl chloride from t-butyl-alcohol in a concentrated hydrochloric…

    • 1806 Words
    • 8 Pages
    Better Essays