In Visual Logic Please submit the following programs - both the .vls& .jpgfile (showing output) for each program. I attached pages from the book that have the questions to be answered. The .docx readme file contains all the questions to be answeredPlease submit the following programs - both the .vls & .jpg file (a screenshot of the program,showing output) for each program. Programming Exercises: On page 70 4-4 NumberStackDifferent - .vls & .jpg On page 71 4-5 NumberStackSame - .vls & .jpg On page 71 4-6 RightTriangle - .vls & .jpg On page 71 4-7 Tree - .vls & .jpg On page 72 4-8 Diamond - .vls & .jpg On page 94 5-6 TwoDiceSimulation .vls .jpg - Refer to Sample Program #2: Dice Roll Simulation in the chapter. Also refer to Chapter 5, Part 3 PowerPoint in Reading Highlights. On page 94 5-7 AccessGranted - .vls & .jpg (Use attached file usernames.txt for input file). Refer to Sample Program #3 Parallel Arrays (Username and Password). Also refer to Chapter 5, Part 4 PowerPoint in Reading Highlights. "peanut butter" "jelly" "sunrise" "sunset" "light" "dark" "forward" "reverse" "water" "oil" "burgundy" "gold" "sofa" "chair" "boy" "girl" "fire" "water" "build" "destroy" CHAPTERFOUR CHAPTER SUMMARY » For loops are used to automate the initialize, test, and update process. In Visual Logic, the For loop flowchart element appears as a six-sided figure with a loop vari- able, a start value, an end value, and two exit arrows. (The step value also appears if the step value is something other than 1.) The body of the loop is to the right and below the element. » When executed, the first action is to initialize the loop variable to the start value. » The body of the loop executes as long as the value of the loop variable does not exceed the final value. (Note: If the step value is negative, then the body of the loop executes as long as the value of the loop variable is not smaller than the final value.) After the body of the loop executes, the loop variable is updated by the step value, and the process is repeated. Any valid statements can occur inside the body of a loop, including input, assignment, output, conditions, and even other loops. » A nested loop refers to a loop that appears inside the body of another loop. KEY TERMS final value initial value step value For loop nested loop REVIEW QUESTIONS 1. What is the difference between a For loop and a While loop? 2, When using a For loop, what happens when the loop variable is equal to the final value? What happens when the loop variable exceeds the final value? » . Consider two For loops, one with a positive step value and one with a negative step value. How are these two loops similar? How are these two loops different? ~ ‘When writing a program that reads input terminated by a sentinel value, which loop is more appropriate to use, a For loop or a While loop? Explain your answer. = . Consider the following statement: “An infinite loop is more likely to occur when using a While loop than when using a For loop.” Do you agree or disagree with the statement? Explain your answer. PROGRAMMING EXERCISES 4-1. Blast Off! Write a program that uses a For loop to generate the output shown below. The text “Rocket launch” should appear only once in your program. 69 Copyright 2009 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, FOR LOOPS AND NESTED LOOPS 4-2. Pass It Around. Write a program that uses a For loop to generate the output shown below. Note that the program should only show the text for 99, 98, 97, and 96 bottles (Hint: Have a start value of 99 and a final value of 96, with a step value of -1). [99 boteTes of rootbeer on the wall 99 bottles of rootbeer pC PRE UE! Fst BR TCR Fadil aba 27 bottles of rootbeer on the wall 97 bottles of rootbeer Fae one down and pass it aroun Hott dbi JE i NS 36 bottles of rootbeer on the wall 96 bottles of roth Rr RE Tee fone Tess bottle of rootbeer on the wall 4-3. Very Merry Christmas. Write a program that uses a nested loop to display “Ho Ho Ho Merry Christmas” five times to console output. Note: Your program should use the word “Ho” only once. Cl] 4-4. Number Stack Different. Write a program that uses a nested loop to generate the output shown below. Be sure that the value on the line changes with each digit displayed. For example, line 5 has the values “17, “2”, “3”, “4”, and “5”. 70 Copyright 2009 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, CHAPTERTFOUR FOR LOOPS AND NESTED LOOPS 4-5. Number Stack Same. Write a program that uses a nested loop to generate the output 4-8. Diamond. Write a program that generates the following diamond shape to console shown below. Be sure that all the values on a single line are the same. For example, line 5 has output. Note that every line has an odd number of circles. the values “5”, “5”, “5”, “5”, and “5”. 4-6. Right Triangle. Write a program that generates the following triangle to console output. Note that the number of blank spaces decreases each line. (Hint: Modify the solution in Figure 4-14 by adding a “SpaceCount” loop above the “CircleCount” loop. Both the SpaceCount and CircleCount loops should be nested inside the LineCount loop.) 4-7. Tree. Write a program that generates the following tree shape to console output. Note that every line contains an odd number of circles. 7 72 Copyright 2009 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Copyright 2009 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. CHAPTERFIVE pairs; the first number will be between 1 and 9 and will represent the batter’s position, and the second number will be either 0 or 1 and will represent an out (0) or a hit (1). The program will continue to input data pairs until the sentinel value —1 is read. At that point, the program should output the batting average for each of the nine positions. (Note: Batting average is the number of hits divided by the number of at bats. Therefore, hits and at bats may be good values to store in parallel arrays.) The output shown below was generated using the input file ige.txt,” which may be available from your instructor. “battingavera 5-5. Batting Average and Slugging Percentage. Write a program that uses parallel arrays to determine the batting average and slugging percentage for a baseball team by position. There are nine positions on a baseball team and your program should have parallel arrays with an upper bound of 9. Your program will read data in pairs; the first number will be between 1 and 9 and will represent the batter’s position, and the second number will be either a 0 (for an out) or a 1 (for a single) or a 2 (for a double) or a 3 (for a triple) or a 4 (for a home run). The program will continue to input data pairs until the sentinel value —1 is read. At that point, the program should output the batting average and slugging percentage for each of the nine posi- tions. (Note: Batting average is the number of hits divided by the number of at bats and slug- ging percentage is the total number of bases divided by the number of at bats. You might want to have three parallel arrays in your solution.) The output shown below was generated using the input file “battingandslugging:txt,” which may be available from your instructor. (Hint: You will probably need parallel arrays for Hits, AtBats, and Bases.) 93 Copyright 2009 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. ARRAYS 5-6. Two Dice Simulation. Write a program that simulates the rolling of two dice many ach of the two dice should have a separate “Random(6) + 1” and the two random values should be added together to get the total of the two dice roll. After rolling the two dice, the total rolled should be updated in an array of counters, For example, if the random values were 3 and 4, then the dice total is 7 and the index 7 element should be incremented by 1. Because the maximum roll possible for two dice is 12, your array of counters should have an upper bound of 12. Your program should simulate rolling the two dice many times (400 rolls is the number used in the figure below) and then display how many times each total was rolled and the percentage for each total. Finally, the program should display the roll totals visually by creating a histogram. Note: Each time you run your program you will get different totals and therefore a different histogram. In general the middle totals (such as 6, 7 8) should be rolled more often than the extremes (2, 3, 4 on the low end and 10, 11, 12 on the high end) because there are more combinations of two dice that result in those middle values. 5-7 Access Granted. Write a program that reads 10 username and password pairs and stores those username and password values into parallel arrays. After the arrays have been loaded, the program should behave as a login screen, continuously prompting for a username and password until a valid combination is entered and access is granted. Each time the user enters username and password data, the program should respond appropriately with one of three output me sages. If the username does not match one of the values in the username array, then the message should be “Username not found.” 1f the username is found in the username array, but the pass- word does not match the parallel value in the password array, then the message should be “Username and password do not match.” If the username is found and the password matches the parallel value in the password array, the message should be “Access granted.” The pro- gram should use a loop and continue to prompt the user for a valid username and password pair until a valid pair is entered and access is granted. [EX] [PTaase type a value for TNPUTUSER: “yesterday” BB username fot found Please type a value for INPUTUSER Please type a value for INPUTPASS (Tr ET Rr ved AR RR I PT CTT Please type a value for INPUTPASS 9% Copyright 2009 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.