Absolute C++
6th Edition
ISBN: 9780133970784
Author: Walter Savitch, Kenrick Mock
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Question
error_outline
This textbook solution is under construction.
Students have asked these similar questions
use c++ by Using dynamic arrays, implement a polynomial class with polynomial addition,subtraction, and multiplication.
Discussion: A variable in a polynomial does nothing but act as a placeholder forthe coefficients. Hence, the only interesting thing about polynomials is the arrayof coefficients and the corresponding exponent. Think about the polynomialx*x*x + x + 1Where is the term in x*x ? One simple way to implement the polynomial class is touse an array of doubles to store the coefficients. The index of the array is theexponent of the corresponding term. If a term is missing, then it simply has a zerocoefficient.There are techniques for representing polynomials of high degree with many missingterms. These use so-called sparse matrix techniques. Unless you already knowthese techniques, or learn very quickly, do not use these techniques.Provide a default constructor, a copy constructor, and a parameterized constructorthat enables an arbitrary polynomial to be constructed.Supply an…
Write a program to overload the function call operator ( ) so as to allow the more common form of double-array subscripting. Therefore, instead of saying:
chessBoard[row][column]
for an array of objects, overload the function call operator to allow the alternate form: chessBoard(row, column)
A sample output of your program should look like follows:
The value of each array element is the product of the row and column values. Using the class definition given in the myClassOperator.h header file below, implement the class member functions and driver code in separate files.
FOR JAVA
Write a Java method that takes two 2 dimensional int arrays (a and b) and a 2 dimensional boolean array (c) where all three arrays have the same size. Your method should return an array (result) such that, if a partic- ular element in c is true, then the corresponding (same indexed) element in result must be the multiplication of the the corresponding elements of a and b. If the element in c is false, then the the corresponding element in result must be the negative of multiplication of the the corresponding element in a and b.
For example ifa = {{1,2,3},{4,5}},b = {{1,2,1},{0,2}} andc = {{true,false,true},{false,true}}, then the result should be result={{1, -4, 3}{0, 10}}.
Knowledge Booster
Similar questions
- Write method findZero, as started below. findZero should return the index of the first element of array A that contains the value zero, starting from position 0 up through position pos. If no element of A from position 0 to position pos contains the value zero, then findZero should return –1. For example:(in java) Array (A) Position (pos) Value returned by findZero(A, pos) 1 0 2 5 6 0 -1 1 0 2 5 6 1 1 1 0 2 5 6 2 1 1 0 2 0 6 2 1 1 0 2 0 6 4 1 1 2 3 4 5 4 -1 Complete method findZero below. Assume that it is called only with values that satisfy its assumptions as stated below. // Description: Returns smallest index k // such that (0 <= k <= pos) and (A[k] == 0) // Assumptions: 0 <= pos < A.length public int findZero(int[] A, int pos) {arrow_forwardComplete the implementation of scrabble.c, such that it determines the winner of a short scrabble-like game, where two players each enter their word, and the higher scoring player wins. Notice that we’ve stored the point values of each letter of the alphabet in an integer array named POINTS. For example, A or a is worth 1 point (represented by POINTS[0]), B or b is worth 3 points (represented by POINTS[1]), etc. Notice that we’ve created a prototype for a helper function called compute_score() that takes a string as input and returns an int. Whenever we would like to assign point values to a particular word, we can call this function. Note that this prototype is required for C to know that compute_score() exists later in the program. In main(), the program prompts the two players for their words using the get_string() function. These values are stored inside variables named word1 and word2. In compute_score(), your program should compute, using the POINTS array, and return the score…arrow_forwardanswer for this without arrays and please every time i get answers this ouput doesn't work as i needarrow_forward
- Implement a range function for a dynamic array which returns a new dynamic array that is a subset of the original. input parameters: array - (the array and any related parameters) start - index of the first elementend - index of the last elementInterval - An integer number specifying the incrementation of index This function returns a new dynamic array containing the elements from the start thru the end indices of the original array.All array indexing must be done using pointer arithmetic. For example, given the array: 49 96 99 47 76 29 22 16 30 22 If the start and end positions were 5 and 9 with step 2, return a new dynamic array: 29 16 22 Please use following main to test your function. int main(){int *p = new int[10]{49,96,99,47,76,29,22,16,30,22}; int *q = range(p,10,5,9,2);for(int i=0;i<3;i++) cout<<q[i]<<" "; // print 29 16 22 cout<<endl;delete [] q;q = range(p,10,1,8,3); for(int i=0;i<3;i++)cout<<q[i]<<" "; // print 96 76 16 cout<<endl;…arrow_forwardFirst, write a Java method merge that takes as parameter a non-empty double array representing employees’ salaries. The method merges the values of every 2 adjacent elements. put the merged values at the beginning of the array, and put 0 in the remaining positions. Suppose that the original array will contain an even number of elements. Second, write two java methods readArray(int[]a) and printArray(int[]a) that reads/writes the elements of an array passed in parameter from/to the standard input/output. Finally, Use the following main method to test your different methods: public class MergeSalary { private static Scanner input = new Scanner(System.in); public static void main(String[] args) { } } double[] salaries = new double[10]; System.out.print("Enter 10 salaries: "); readArray(salaries); merge(salaries); System.out.print("Salaries after merge: "); printArray(salaries); Hint: For the method merge, you can work on the same array or use a temporary array. Run example:…arrow_forwardFirst, write a Java method merge that takes as parameter a non-empty double array representing employees’ salaries. The method merges the values of every 2 adjacent elements. put the merged values at the beginning of the array, and put 0 in the remaining positions. Suppose that the original array will contain an even number of elements. Second, write two java methods readArray(int[]a) and printArray(int[]a) that reads/writes the elements of an array passed in parameter from/to the standard input/output. Finally, Use the following main method to test your different methods:arrow_forward
- Write method findZero, as started below. findZero should return the index of the first element of array A that contains the value zero, starting from position 0 up through position pos. If no element of A from position 0 to position pos contains the value zero, then findZero should return –1. For example: Array (A) Position (pos) Value returned by findZero(A, pos) 1 0 2 5 6 0 -1 1 0 2 5 6 1 1 1 0 2 5 6 2 1 1 0 2 0 6 2 1 1 0 2 0 6 4 1 1 2 3 4 5 4 -1 Complete method findZero below. Assume that it is called only with values that satisfy its assumptions as stated below. // Description: Returns smallest index k // such that (0 <= k <= pos) and (A[k] == 0) // Assumptions: 0 <= pos < A.length public int findZero(int[] A, int pos) {arrow_forwardWrite a program that first reads an integer for the array size, then reads numbers intothe array, and finally outputs how many numbers have values that are greater than theaverage. For practice reasons, try not to use the index notation of arrays (e.g. myarray[i])at all. Use pointers instead.arrow_forwardFOR JAVA // Question is the first one, try to solve it by using the second question. Repeat the second question, but if there are multiple occurrences of the number, your program must return the largest index instead of the small- est. Write a method that takes a one dimensional integer array and an integer, and returns the index of the integer in the array. If the integer is not in the array, your program must return -1. If there are multiple occurrences of that number, your program must return the smallest index.arrow_forward
- I just need the method they are asking for Write a recursive function that takes a start index, array of integers, and a target sum. Your goal is to find whether a subset of the array of integers adds up to the target sum. The start index is initially 0.A target sum of 0 is true for any array. Examples: subsetSum(0, {2, 4, 8}, 10) -> true public boolean subsetSum(int start, int[] nums, int target) { }arrow_forwardWrite a Java 7 program with proper whole code and Explatation too,,. & Dont use JAVA8... Shil got an array of N integers as a present on his birthday. But he didn't liked it. Shil wants to make this array beautiful. Shil considers an array A1,A2,A3 . . . AN beautiful if A1 > AN. Inorder to make it beautiful Shil can swap any two numbers in the array. Also Shil can perform this operation any number of times on any adjacent pairs of integers in the array A.Find the number of ways in which Shil can make this array beautiful.Two ways are considered same if resulting array after making all the swaps have same A1 and AN. Input First line of input contains an integer N denoting the number of elements in an array A. Next line of input contains N space separated integers denoting A1,A2,A3 . . . AN respectively. Output Number of ways in which you can make given array beautiful. Constraints 1 ≤ N ≤ 1061 ≤ Ai ≤ 106 SAMPLE INPUT 5 1 4 3 2 5 SAMPLE OUTPUT 10 Explanation…arrow_forwardImplement a function GetMinimumCutSegments(int[] arr, int k) that takes in an array arr of positive integers and an integer k, and returns the minimum number of contiguous segments of the array that must be concatenated to form an array of size k. The function should return -1 if it is not possible to create an array of size k by concatenating contiguous segments of the input array. Example: Input: [1, 2, 3, 4], 6 Output: 2 Explanation: The minimum number of contiguous segments that must be concatenated to form an array of size 6 is 2. The two segments that can be concatenated are [1, 2] and [3, 4]. Input: [1, 2, 3, 4], 7 Output: -1 Explanation: It is not possible to create an array of size 7 by concatenating contiguous segments of the input array. Constraints: The input array arr will have at most length 100. The integer k will be at least 1 and at most 10^6. Can you write a C# function that solves this problem? public int GetMinimumCutSegments(int[] arr, int k) { // Your code…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning