For each of the following situations, tell which type of loop (while, do-while, or for) would work best:
a. Summing a series, such as
b. Reading in the list of exam scores for one student.
c. Reading in the number of days of sick leave taken by employees in a department.
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Absolute Java (6th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects
C How to Program (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Computer Science: An Overview (12th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Software Engineering (10th Edition)
- A criticism of the break and continue statements is that each is unstructured. These statements can always be replaced by structured statements. Describe in general how you’d remove any break statement from a loop in a program and replace it with some structured equivalent. [Hint: The break statement leaves a loop from within the body ofthe loop. Another way to leave is by failing the loop-continuation test. Consider using in theloop-continuation test a second test that indicates “early exit because of a ‘break’ condition.”] Use the technique you developed here to remove the break statement from the program of Fig. 5.13.arrow_forwardA criticism of the break and continue statements is that each is unstructured. These statements can always be replaced by structured statements. Describe in general how you’d remove any break statement from a loop in a program and replace it with some structured equivalent. [Hint: The break statement leaves a loop from within the body ofthe loop. Another way to leave is by failing the loop-continuation test. Consider using in theloop-continuation test a second test that indicates “early exit because of a ‘break’ condition.”]arrow_forwardUse following series to do the given task; 135 79 11 13 15 1719 21 23 25 27 29 31 ... Given the number N of odd numbers in a certain line, your task is to determine the sum of the last three numbers of that line. For example N = 5 means, the third line, the last three numbers are 13, 15 and 17. The summation of these three numbers is 45. InputThe first line tells the number of test cases. From the next line, the input is a sequence of lines, one odd number N (1 < N <1000000000) per line. OutputFor each input line write the sum of the last three odd numbers written in that line of series with N numbers.arrow_forward
- Implement programs involving the use of while, do..while and for loop statement. Objectives: Topics Covered: Implementing programs using loops. Description FRIDAY THE 13TH When will Friday the 13th occur in 1990? Write a program that will find all months in 1990 in which the 13th falls on a Friday. You need to know the following. 1. January 1, 1990 was on a Monday. 2. September, April, June, and November have thirty days, all the rest have 31 except for February which has 28 except in leap years when it has 29. 3. 1990 is not a leap year. Note: To make it fair for everyone, you may not use any built-in date functions from your computer language. Sample Output if Applicable Sample Run In 1990, Friday the 13th occurs in the months: APRILarrow_forward1. Which is the most easiest way in looping? Explain.arrow_forwardActual timings. Instrument FrequencyCounter to use Stopwatch and StdDrawto make a plot where the x-axis is the number of calls on get() or put() and the y-axisis the total running time, with a point plotted of the cumulative time after each call.Run your program for Tale of Two Cities using SequentialSearchST and again usingBinarySearchST and discuss the results. Note : Sharp jumps in the curve may be explained by caching, which is beyond the scope of this question.arrow_forward
- Modify the guessing-game program of Section 3.5 so that the user thinks of a number that the computer must guess. The computer must make no more than the minimum number of guesses, and it must prevent the user from cheating by entering misleading hints. (Hint: Use the math.log function to compute the minimum number of guesses needed after the lower and upper bounds are entered.)arrow_forwardThe following function is designed to determine (the hard way) if a number is prime. What definition for stopNum will complete the function? There are multiple answers that will work in the sense that they will produce the right output. For full marks, your answer must be the one which will both work AND cause the loop to run the FEWEST number of times (thus making the function as fast as possible). def checkPrime(num): factors - [] stopNum = ??? for nn in range (2, stopNum): if num % nn == 0: factors.append (nn) if len(factors): print("The number is composite") else: print("The number is prime")arrow_forwardBoth while loops and do-while loops are executed as long as a stated boolean condition is true and both while loops and do while loops terminate if the boolean condition is false. What is the only (major, key) difference between the two types of loops. 1. while loops are faster 2. A do-while loop can be rewritten as a for loop, but we cannot rewrite a while loop as a for loop. 3. A do while loop will always execute the loop statements once, but it is possible that a while loop skip all of its loop statements.arrow_forward
- a. Implement the problem above using C/C++ programming language. Do apply the techniques for good programming practices. Ensure that appropriate validations are done on your input data. b. Sample Input: The user should be allowed to input the following information:i. Maximum weight a truck is allowed to carryii. Number of oversized items to ship for the dayiii. Weight of each oversized itemiv. Priority status for oversized item (if applicable) Sample Output:i. Oversized items that were loaded into each truckii. Amount of unused space (weight) for each truckiii. Number of trucks that were not utilized/loaded (if any)iv. List of oversized items that could not be shipped (including priority status, if applicable)arrow_forwardAnswer the ff looping problems- WHILE LOOP 1. Allow the user to input integer values and sum up all the inputted values. The loop will be terminated if the user input ZERO (0). 2. Interest is compounded annually at 10% by a certain bank. Create a program that will allow input an amount and a number of years and output how much the original amount will be worth after the period. Each transaction is tagged as customer #(Maximum of 10 customers only).arrow_forwardInstructions for Questions 1 through 6. For each piece of pseudocode, give the runtime in terms of N. Your answer should give an exact value for the number of times the inner loop runs (i.e. the final value of count), and it should also give the order of growth of the runtimes using big-Oh notation. You can assume that N "comes out nicely" with respect to loops. For example, if the loop counts by 2, you can assume it is an even number, and if it multiplies or divides by 2 each time, you can assume it is a power of 2. Note: log(N!) is 0(NlogN).arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr