Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (9th Edition)
9th Edition
ISBN: 9780133862225
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 7.2, Problem 12STE
Program Plan Intro
Purpose of given code:
The given code is initializes the array “b[]” and passes each value by calling the function “tripler()” using “for” loop.
Given code:
/*Function definition with argument*/
void tripler(int& n)
{
/*Calculation of "n" value*/
n=3*n;
}
/*Declaration and initialization of variable*/
int b[5]={1,2,3,4,5};
//Error
for(int i=1;i<=5;i++)
/*Call the function with argument value*/
tripler(b[i]);
Explanation of given code:
- The code defines the function “tripler()” which takes the address of an argument.
- The value of passed by argument is multiplied by “3” and stored into the variable “n”.
- The array variable “b[]” was initialized in type of integer.
- Using “for” loop, call the function with each value of array.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
IN JAVA
intends to auto generate test cases for a function foo that has k integers as input arguments, i.e., foo(int n1, int n2, …, int nk). Each argument belongs to a different equivalence class, which are stored in a downloadable Eq.txt file. The content is shown below and may be modified to handle more inputs and equivalence classes.
1, 15; 16, 30
1, 10; 11, 20; 21, 30
1, 5; 6, 10; 11, 15
1, 3; 4, 6; 7, 9; 10, 12
1, 12; 13, 24
For this file, the nth row describes the nth input. Take the second row for example. There are five input arguments. The data 1, 10; 11, 20; 21, 30 indicates that argument n2 has three equivalence classes separated by the semi-colons. Develop an internal method “private int check(int val)” that returns the equivalence class the val is in. The result of check(val = 3) for n2 will be 1 and check(val = 25) for n2 will be 3. Regarding the function foo, it computes the sum of the returned values by the check function for all input arguments.
Follow the contents…
pls give mommens by expression and statements , thanks
Recall that in C++, there is no check on an array index out of bounds. However, during program execution, and array index out of bounds can cause serious problems. Also, in C++, the array index starts at zero.
Design and implement the class myArray that solves the array index out of bounds problem, and also allows the user to begin the array index starting at any integer, positive or negative. Every object of type myArray is an array of type int. During execution, when accessing an array component, if the index is out of bounds, the program must terminate with an appropriate error message. Consider the following statements:
myArray<int> list(5); //Line 1
myArray<int> myList(2, 13); //Line 2
myArray<int> yourList(-5, 9); //Line 3
This statement in line one declares list to be an array of five components, the component type is int, and components are: list[0], list[1],…, list[4];…
WITE JAVA CODE JUST TO THE GIVEN CODE BELOW!
TESTS GIVE ERROR FOR SHRINK AND add remove 100 values
ALSO, DO IT BY CHECKING THE MAIN CLASS WITHOUT CHANGING IT
class Queue<T> { private T[] a = (T[]) new Object[1]; private int N = 0; public boolean isEmpty() { return N == 0; } public int size() { return N; } private void resize(int capacity) { T[] temp = (T[]) new Object[capacity]; for (int i = 0; i < N; i++) { temp[i] = a[i]; } a = temp; } public void enqueue(T item) { if (N == a.length) resize(2*a.length); a[N++] = item; } public T dequeue() { T item = a[--N]; a[N] = null; if (N > 0 && N == a.length/4) resize(a.length/2); return item; } // this method is for unit testing; don't touch public int getArraySize(){ return a.length; }}
public class Main {
public static void main(String[] args) {
Queue<Integer> myQueue = new Queue<Integer>();
int i;
i = 1;
myQueue.enqueue(i);…
Chapter 7 Solutions
Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (9th Edition)
Ch. 7.1 - Prob. 1STECh. 7.1 - In the array declaration double score(5); state...Ch. 7.1 - Identity any errors in the following array...Ch. 7.1 - What is the output of the following code? char...Ch. 7.1 - What is the output of the following code? double a...Ch. 7.1 - What is the output of the following code? int i,...Ch. 7.1 - Prob. 7STECh. 7.1 - Suppose we expect the elements of the array a to...Ch. 7.1 - Prob. 9STECh. 7.1 - Suppose you have the following array declaration...
Ch. 7.2 - Consider the following function definition: void...Ch. 7.2 - Prob. 12STECh. 7.2 - Write a function definition for a function called...Ch. 7.2 - Consider the following function definition: void...Ch. 7.2 - Insert const before any of the following array...Ch. 7.2 - Write a function named outOfOrder that takes as...Ch. 7.3 - Write a program that will read up to ten...Ch. 7.3 - Write a program that will read up to ten letters...Ch. 7.3 - Following is the declaration for an alternative...Ch. 7.4 - Prob. 20STECh. 7.4 - Write code that will fill the array a (declared...Ch. 7.4 - Prob. 22STECh. 7 - Write a function named firstLast2 that takes as...Ch. 7 - Write a function named countNum2s that takes as...Ch. 7 - Write a function named swapFrontBack that takes as...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - There are three versions of this project. Version...Ch. 7 - Hexadecimal numerals are integers written in base...Ch. 7 - Solution to Programming Project 7.3 Write a...Ch. 7 - Prob. 4PPCh. 7 - Write a program that reads in a list of integers...Ch. 7 - Prob. 6PPCh. 7 - An array can be used to store large integers one...Ch. 7 - Write a program that will read a line of text and...Ch. 7 - Write a program to score five-card poker hands...Ch. 7 - Write a program that will allow two users to play...Ch. 7 - Write a program to assign passengers seats in an...Ch. 7 - Prob. 12PPCh. 7 - The mathematician John Horton Conway invented the...Ch. 7 - Redo (or do for the first time) Programming...Ch. 7 - Redo (or do for the first time) Programming...Ch. 7 - A common memory matching game played by young...Ch. 7 - Your swim school has two swimming instructors,...Ch. 7 - Your swim school has two swimming instructors,...Ch. 7 - Prob. 19PPCh. 7 - The Social Security Administration maintains an...
Knowledge Booster
Similar questions
- Can I get a test driver for this code? #include<iostream> using namespace std; template <typename T> T* subarray(const T* a, int i, int m){ T* subArr = new T[m]; int index = 0; for(int j=i; j < m+i-1; j++){ subArr[index] = a[j]; index++; } return subArr; }arrow_forwardWrite 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.arrow_forwardWhat is wrong with the following code? int *p;. //Line 1int *q;. //Line 2 p = new int [5];. //Line 3 *p = 2; //Line 4 for (int i = 1; i < 5; i++). //Line 5p[i] = p[i-1] + i;. //Line 6 q = p;. //Line 7 delete [] p; //Line 8 for (int j = 0; j < 5; j++) //Line 9 cout << q[j] << " "; //Line 10 cout << endl; //Line 11arrow_forward
- Write code for following--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_forwardYou are required to demonstrate competency in any or all of 2D arrays, doubly linked lists, merging of sorted data structures and constructive and destructive programming techniques. Code your solution according to the requirements below. And add comments: Class Tester, method process: Modify the following(in particular method process in class Tester).arrow_forward
- write java codes to do the following: Write a recursive function to check if an integer array is negative symmetric, for example, an array of 10, 20, 30, 90, -30, -20, -10 is considered as negative symmetric, while an array of 10, 20, 30, 90, 30, 20, 10 is not considered as negative symmetric. public static boolean checkArraySym(int [ ] A, int first, int last) that receives an array A, first index, last index and checks if the array is negative symmetricarrow_forwardProvide an implementation of insertion sort that sorts arrays of integer values, then evaluate how well it performs in comparison to the code provided in the text (which sorts integer values and implicitly utilises autoboxing and auto-unboxing to convert).arrow_forwardWrite Java code and a C++ Code for the problem given below as: Given an array of distinct integers. The task is to count all the triplets such that sum of two elements equals the third element.arrow_forward
- Write a java code for the following. Write two methods that return the union and intersection of two arrays of integers using the following header: public int [ ] union(int arr1[ ], int arr2[ ] ) public int [ ] intersection(int arr1[ ], int arr2[ ]) For example, the union of two array lists {2, 3, 1, 5} and {3, 4, 6} is {2, 3, 1, 5, 3, 4, 6} and intersection is {3}. Write a test program that prompts the user to enter two lists of size 4 each, and displays their union and intersection. The numbers are separated by exactly one space in the output.arrow_forwardAnswer the given question with a proper explanation and step-by-step solution. In Java, please. Consider the following problem. Input: an array of integers A[] Output: rearranges the array to have the following property: Suppose the first element in the original array A[], A[0] = x. In the rearranged array, suppose that x is at index i, that is A[i] = x. Then, we want the rearranged array to be such that A[j] <= x for all j < i and A[j] > x for all j > i. The rearranging should place all the values less than (or equal to) x to the "left" of x and all values larger than x to the right of x. Here's an example. Suppose the array has the elements in this initial order: 4 3 9 2 7 6 5 A[0] = 4. After rearranging elements, we get: 3 2 4 5 9 7 6 That is, A[0] = 4, is positioned in the resulting array so that all elements less than 4 (that is, 2, 3) are to its left (in no particular order), and all elements larger than 4 are to its right (again, in no particular order).arrow_forwardWrite code for. Computes the smallest x that satisfies the chinese remainder theorem for a system of equations. The system of equations has the form: x % nums[0] = rems[0] x % nums[1] = rems[1] ... x % nums[k - 1] = rems[k - 1] Where k is the number of elements in nums and rems, k > 0. All numbers in nums needs to be pariwise coprime otherwise an exception is raised returns x: the smallest value for x that satisfies the system of equations.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