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 1/2 + 1/3 + 1/4 + 1/5 + ... + 1/10.
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.
d. Testing a function to see how it performs for different values of its arguments.
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (9th Edition)
Additional Engineering Textbook Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
C++ How to Program (10th Edition)
Starting Out with Python (3rd Edition)
Starting Out with Programming Logic and Design (4th Edition)
- Write a function as seen in the photo. Do NOT use any loopsarrow_forwardWrite a function using C that has two integers and uses a loop to count from a lower value to a higher value and vice versa. Use each value of the loop counter as a length in miles and printing it with the corresponding length in KM, with three digits after the decimal point.arrow_forwardQuestion 2: Write a program to read student ID and check whether it is odd/even number. Output a 4X4 badge if the student ID is even number and output a 3X3 badge if it is odd number. The badge is built up by the (height X width) of asterisks. (Use for-loop to draw the asterisks, do not hard-coded)arrow_forward
- Pleaser fix the code below: Since functions should do a single logical task, there is no need for the userInputCalc function to collect the info and also do the summary calculations, so move line 61 to line 72. Then, place line 67-72 inside a main() function, and place a call to this function at the end of the program file. Also, fix the names of the menu items (in menu_items) with spaces so they all have the same size. also, there is a simpler way: change {:<15} with {:<20} in lines 22 and 25. Also, use format for the “Subtotal” and “Grand total” (just like you did for “Sales tax” and “Suggested tip”) Also, the $ should go in front of the each amount. PLEASE MAKE THOSE CHANGES IN THE CODE BELOW: SummaryThis program will create a new version of the restaurant ordering programthat uses lists to look up menu items, record the items ordered by the user,and print a full receipt.''' def Menu(menu_items,menu_prices):print("Menu Card")count = 1for i,j in…arrow_forwardI have three C functions that work perfectly but I am not allowed to use continue, break to get out of loop. I need help in modfying the function so it will give the same output without the inclusion of continue(highlighted in bold) int setIntersection(String *A, String *B, String *C, int nElemA, int nElemB){ //Set the nElemc to zero int nElemC = 0; //Set the for loop over A for(int i = 0 ; i< nElemA ; i++){ //Set the for loop over the B for(int j = 0 ; j< nElemB ; j++){ //Check if element already present in both if(strcmp(A[i],B[j]) == 0){ //Then add the element in the c strcpy(C[nElemC], A[i]); //Increment the nEleC nElemC++; //Break after the match continue;; } } } //Print the intersection for(int i = 0; i < nElemC; i++) printf("%s ", C[i]); return nElemC;}//For the differenceint setDifference(String…arrow_forwardCode in Python Write a function, print_perfect_cubes(n), that takes an integer parameter n and prints the perfect cubes starting from 03 = 0 and ending with n3. When n is negative, the function prints nothing; but do not check for this condition with an "if" statement, it is unneccesary; use a for loop that will automatically print nothing when n < 0. Hint for choosing the right range for your for loop: In the general case, when n is not negative, your function will need to print n+1 different values. For example: Test Result print_perfect_cubes(2) 0 1 8 print_perfect_cubes(5) 0 1 8 27 64 125 print_perfect_cubes(-10)arrow_forward
- Consider the following Python function: def values_above_threshold(values, threshold):filtered = []for value in values:if value > threshold:filtered.append(value)return filtered Rewrite the function below to use a while loop instead of a for loop. Your version of the function should have the same name, the same number of parameters, and it should produce the same output as the function above.arrow_forwardWhat is wrong with the following C++ function? void Maximum(int a, int b, int& max) { if (a > b) max = a; else max = b; return max; }arrow_forwardhow to write a function that takes an integer n and prints all of the integers between 1 and n which are multiple of 5 using while looparrow_forward
- -Python- Write a function get_letter_grade, such that when given * a lab grade score and * a list of the grade cutoffsreturns the letter grade of that score.Note: Your function automatically returns A for the values that are >= to the first cutoff-value in the list, then A- for the second cutoff-value, B+ for the third and so on. The function returns None for anything that's below the score for B-. You test that get_letter_grade(97, [93, 90, 87, 83, 80]) correctly returns an A, and get_letter_grade(93, [97, 90, 87, 83, 80]) returns A-. DO NOT hard-code the cutoffs, since they can change! You can copy/paste the following template: def get_letter_grade(score, cutoffs): if score ... : return 'A' ...: return 'A-' ...: return 'B+' ...: return 'B' ...: return 'B-'arrow_forwardBartleby answered my homework and Write a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters. Otherwise, it should return False. Implement has_duplicates by creating a histogram using the histogram function above. Do not use any of the implementations of has_duplicates that are given in your textbook. Instead, your implementation should use the counts in the histogram to decide if there are any duplicates. Write a loop over the strings in the provided test_dups list. Print each string in the list and whether or not it has any duplicates based on the return value of has_duplicates for that string. For example, the output for "aaa" and "abc" would be the following. aaa has duplicatesabc has no duplicates Print a line like one of the above for each of the strings in test_dups. True needs to be defined. I tried to code it but didn't accept and got an error message.arrow_forwardCould you solve this Question please? Write a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters. Otherwise, it should return False. Implement has_duplicates by creating a histogram using the histogram function above. Do not use any of the implementations of has_duplicates that are given in your textbook. Instead, your implementation should use the counts in the histogram to decide if there are any duplicates. Write a loop over the strings in the provided test_dups list. Print each string in the list and whether or not it has any duplicates based on the return value of has_duplicates for that string. For example, the output for "aaa" and "abc" would be the following. aaa has duplicatesabc has no duplicates Print a line like one of the above for each of the strings in test_dups. Obs:Copy the code below into your program def histogram(s): d = dict() for c in s: if c not in d: d[c] =…arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr