C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
How do you do 7 and 8?
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 3 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- There is a large pile of socks that must be paired by color. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are. Example There is one pair of color and one of color . There are three odd socks left, one of each color. The number of pairs is . Function Description Complete the sockMerchant function in the editor below. sockMerchant has the following parameter(s): int n: the number of socks in the pile int ar[n]: the colors of each sock Returns int: the number of pairs Input Format The first line contains an integer , the number of socks represented in .The second line contains space-separated integers, , the colors of the socks in the pile. Constraints where Sample Input STDIN Function ----- -------- 9 n = 9 10 20 20 10 10 30 50 10 20 ar = [10, 20, 20, 10, 10, 30, 50, 10, 20] Sample Output 3 Explanation There are three pairs of socks.arrow_forward2.1arrow_forwardHow do you do 7 and 8?arrow_forward
- Write a function using Java Function Name: winInRowParameters: board: 2D integer array, row: integer, piece: integerReturn: booleanAssume board is valid 2D int array, row is valid index in the board, piece is X==1/O==2Look at indicated row at given index in board. If that row has at least 3 consecutive entries withgiven type of piece (X/O) (3 in a row XXX, OOO), then return true, otherwise false.arrow_forwardImplement a function rollsToRepeat in Python that simulates a dice game in which a pair of dice are rolled repeatedly until some total on the dice occurs the specified number of times. Details: accepts one integer argument, n , the number of repeats required before the game ends rolls a pair of dice repeatedly until some dice total has repeated n times returns the total number of times the pair of dice was rolled For example, using a random seed of 85 , the sequence of rolled pairs will be : (2, 6), (5, 1),(3, 2), (2, 4), (3, 5), (2, 6), (4, 5), (5, 2), (6, 5), (5, 5), ... If you runrollsToRepeat with n=1 , only 1 repeat is required. On the first roll, the total 8=2+6 is repeated once (as wouldany first roll). So the simulation stops and the function returns 1. This always happens whenn=1 . n=2 , some total must repeat twice. This first occurs on the 4throll, when the total of 6occurs for the 2ndtime. n=3 , some total must repeat three times. This first occurs on the 6throll, when…arrow_forwardCode in Python Write a function, print_integers_less_than(n), which takes an integer parameter n and prints each integer k which is at least 0 and is less than n, in ascending order. Hint: use a simple for loop. For example: Test Result print_integers_less_than(2) 0 1 print_integers_less_than(5) 0 1 2 3 4 print_integers_less_than(-3)arrow_forward
- int getMax(int arr[], int n) { intmx=arr[0]; for (inti=1; i<n; i++) if (arr[i] >mx) mx=arr[i]; returnmx; } Can u give me the code for this one as well....this is the first function and countsort is the secondarrow_forwardPython Your class announced a new grade policy: any of your quiz score that are less than 80 will have 2 points added to them.You decide to check whether the proposed grade replacement policy changes your overall quiz grade. Write a function grade_change that takes as input* a list of quiz grades* a list of letter grade cutoffsand returns the two average scores (before and after the policy) and their corresponding letter grades packaged as a list of tuples using the following order: [(avg1, letter1), (avg2, letter2)]First, you need to * compute the average score of the quiz grades* call the get_letter_grade to get the letter grade for the current average* find the quiz scores that are less than 80 in the list and increment each by 2* recompute the average score* call the get_letter_grade to get the letter grade for the new averageFinally, you return the requested result. Just to help you test your code, here's the main program and its output:if __name__ == "__main__":…arrow_forward[Unbalanced Rod] Given a set of n weights {w₁,..., wn} and a rod of length n - 1 inches, we can attach the weights to the rod at hooks placed at one inch distances apart as shown in the figure below. -1". /10 2 3 12 2 4 We can attach a weight to any hook but no two weights can be attached to the same hook and we have to attach all the weights. For any given assignment of weights to hooks, we can compute the location of the center of mass of the rod and the weights according to the following equation (neglecting the weights of the rod and the hooks). where 0 ≤ Pi≤n-1 is the position of weight along the rod. For example, in the figure shown above, the center of mass is computed as C= C = i Wi Pi Σi Wi 10 0+2 1+3·2+4·3+12.4 +2.5 10+2+3+4+12+2 78 33 The problem is to find an assignment of weights to hooks that makes the center of mass as far as possible to the left, i.e., minimize the value of c. Answer the following questions. 1. Describe a greedy algorithm that finds the assignments that…arrow_forward
- Levenshtein distance is the minimum number of editing operations (insertions, deletions, or replacements) needed to turn one sequence into another. For example, given the two words loyola and cravola, how many edits are needed to transform one into the other? loyola → covola [change I to c] → crvola [change o to r] → crayola [add a] www A. Implement a function that computes the Levenshtein distance between two sequences using memorization. Note, you must implement the algorithm that determines the distance; you cannot use imported Python functions to calculate it for you. The function should take in two parameters, the two sequences, and return the distance (an integer). B. Implement a function that computes the Levenshtein distance between two sequences using dynamic programming. Again, you must implement the algorithm that determines the distance; you cannot use imported Python functions to calculate it for you. The function should take in two parameters, the two sequences, and…arrow_forwardin javascript please create a function that does the following and is named as such please don't copy and paste the incorrect answer sequence( start, step ) This function takes two numeric inputs, start and step, and returns a function of no inputs. The ith invocation of the resulting function will generate the value: start + step * i. The first invocation is said to be the 0th. Examples var x = sequence( 3, 15 ) [ x(), x(), x() ] => [ 3, 18, 33 ] var y = sequence( 28, -5 ) [ y(), y(), y() ] => [ 28, 23, 18 ]arrow_forward(Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr