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
Question
error_outline
This textbook solution is under construction.
Students have asked these similar questions
Write a program that fills an integer array of size 1000 with random positive integers between 1 and 10.Assume that each element represents a different city and the integers stored in the array represent thenumber of golds in those cities. The program traverses over the array and collects the golds at each city,starting from a random position. When the program visits a certain city, all of the golds are collected,and the visited element of the array becomes 0 (no gold is left at that city.) The journey continues withthe rule given below. If the position at the nth step is denoted by pn, and the number of golds at the citypn is denoted by gn,??+1 = {| ((??−1 + ?? + ??) ???1000|, ????? 2 = 0| ((??−1 + ?? − ??) ???1000|, ????? 2 = 1.The program continues visiting cities until the last three visited city has no gold.The program, at each visit, should print out the following information:• The current city index (pn).• The previous city index (pn-1).• The number of golds at the current city…
PROGRAM in JAVA
Write a program that defines two arrays - one of strings and one of integers, both of size 10. Your program should then ask the user to enter the a string representing a persons name (just one name - their family name - not their given name as well), and an integer representing their age. It should continue to do this until either the user enters ‘done’ instead of a name, or until the array is full (that is, 10 pairs of names and ages have been entered). It should then print out the names and ages as well as the names of the youngest and oldest.
Hints: One tricky (deliberately) part is making sure that once you’ve typed ‘done’ to finish entering names, your program does not then ask you for the age of the person with name ‘done’ - be careful about this. This is one of the few cases where, if you are careful, you can sensibly use a ‘break’ statement outside of a switch statement
Stage 6: Assessed Task
Redo Stage 5 above but replace the arrays with ArrayLists.
A scientist has developed a mathematical model for a physical process, and he wants to check how
good is model is. To evaluate the correctness of his model, he wants to test the results of his model
under certain parameters and compare them with experimental results.
Write a program that first reads the number of tests (testCount) as an int followed by the results of
each test according to the model as a double array (test Model) and finally the results of each test
according to experiments as a double array (testExperiment). Then, the program should calculate
the error of the model by evaluating the average of the squares of the differences between the model
result and experimental result (see formula below) using a function.
Error
Input
1
testCount
NOTE: Individual square of the difference between the model value and the experiment value
calculations MUST be done in the function. Every other functionality MUST be done in the main
function.
NOTE: To calculate square of a number you…
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
- Write a program that simulates a magic square using 3 one dimensional parallel arrays of integer type. Each one the arrays corresponds to a row of the magic square. The program asks the user to enter the values of the magic square row by row and informs the user if the grid is a magic square or not.arrow_forwardJava Program - Functions with 2D Arrays Write a function named displayElements that takes a two-dimensional array, the size of its rows and columns, then prints every element of a two-dimensional array. Separate every row by a new line and every column by a space. In the main function, write a program that asks for integer input to be assigned on a 3 x 3 array and call the function displayElements to print the contents on the next line. Input 1. Multiple lines containing integer each line Output R1C1: 1 R1C2: 2 R1C3: 3 R2C1: 4 R2C2: 5 R2C3: 6 R3C1: 7 R3C2: 8 R3C3: 9 1 2 3 4 5 6 7 8 9arrow_forwardWrite a program in which the user will create an array of numbers. Take note the user will be the one to decide the number of rows and columns, and will be the onė to input the elemets of the array. Let the program display the matrix. Then, the program must ask the user which one is to display-the minimum or the maximum element of the array.arrow_forward
- Write a program in java that randomly fills in 0s and 1s into an n-by-n matrix, prints the matrix, and finds the rows and columns with the most 1s. (Hint: Use two ArrayLists to store the row and column indices with the most 1s.)arrow_forwardWrite a program that reads an integer array a[] from the console and writes out the subsequence of the array that sums to the largest value. If there are more than one such subsequence, then the program should write out the subsequence that starts at the smallest position in the array and, if there are more than one subsequence of largest sum starting at the same smallest position, it should write out the shortest such subsequence.arrow_forwardJeff loves to develop code for random scenarios. Today Jeff started playing with a couple of Arrays A and B, each of size N. Initially A is filled with zeros. Jeff filled B with random numbers. Jeff visits each index i (1 <= i <= N) in random order. When at i, he selects another random indexj such that j is greater or equal to i. He then increments A[i], A[i+1], A[i+2] ... Alj] by 1. Finally, if for any index i, A[i] is greater than B[1], he then throws away that array A. For a given B, calculate the number of different arrays A, that Jeff can end up with. Two arrays are called different if there exists an index where the arrays have different values. Help Jeff in creating a C++ code that prints a single line containing the required answer modulo 109 + 7. Sample Test Case: 1 111 Result: 2arrow_forward
- Write a program that reads a 2D array of chars, checks, and corrects each char within this array, and print out the corrected 2D array. First the program will read the row count (rowCount) and column count (columnCount) of the 2D array, both as int values. Then, the chars constituting the 2D array will be read on a row-by-row basis. After reading the 2D array, the program will check and correct each char within the 2D array according to the rules below. This process MUST be done by using a void function by sending the appropriate cell of the 2D array with a call-by-reference fashion. If the row index is an even number, a char can only be a digit value. If the row index is an odd number, a char can only be an uppercase English letter. • Any incorrect value MUST be changed into Finally, the checked and corrected 2D array will be printed out to the screen. NOTE: Checking the correctness of a char and correcting it (if necessary) MUST be done in the function with a call-by-reference…arrow_forwardJeff loves to develop code for random scenarios. Today Jeff started playing with a couple of Arrays A and B, each of size N. Initially A is filled with zeros. Jeff filled B with random numbers. Jeff visits each index i (1 <= i <= N) in random order. When at i, he selects another random indexj such that j is greater or equal to i. He then increments A[i], A[i+1], A[i+2] ... A[j] by 1. Finally, if for any index i, A[i] is greater than B[i], he then throws away that array A. For a given B, calculate the number of different arrays A, that Jeff can end up with. Two arrays are called different if there exists an index where the arrays have different values. Help Jeff in creating a C++ code that prints a single line containing the required answer modulo 109 + 7. Sample Test Case: 1 3 111 Result: 2arrow_forwardWrite a basketball program such that it implements a two-dimensional array for 5 players whose score is entered into the array.arrow_forward
- Using Java, Dr. Choi has 5 students who took a midterm and final. 1.First, she wants to store their midterm and final results in two different 1-dimensional arrays and print each of them to a console. 2.She also wants to find average scores of the midterm and final using loops. 3.Second, she wants to store them in one 2-dimensional array and print it to the console. Each row has test scores of the midterm and final. 4.Modify the program above using a 2-dimensional array: Search the highest test score at midterm and lowest test score at final and print them: Pass an array to a method for finding highest score at midterm and lowest test score at final. There are two methods invoked in main () method. One is for finding the highest score and the other one is for finding the lowest score.arrow_forwardWrite a program that creates a matrix 3 by 3 .create a array having 3 elements .the program should multiple the matrix with the given vector and print the resultant matrix in proper format.arrow_forwardSuppose that you are playing a card game whose goal is to collect exactly k cards with a total value of t. Write a solution that can determine if it is possible for a given collection of cards whose values are given in the array values. For example, if the array contained the values <10,5,7,2>, k = 3, and t = 12, you would return false because no three values add to 12. However, if t = 14, you would return true, since 5 + 7 + 2 = 14. So I considered this to be a form of groupSum recursion, so I try to implement it in recursion form. However, since the passing parameters are not the incrementing level index but 'k' that is the limit number of the numbers we can choose from the array, I cannot use passing index through recursion to search from the start of the array toward the end of the values.length(the length of the array). would there be any method I can use to increment and search along the array using k, the number of numbers we can add into the total(t) instead of the…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 Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License