Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
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
Consider the following function:
void fun_with_recursion(int x) { printf("%i\n", x); fun_with_recursion(x + 1); } What will happen when this function is called by passing it the value 0?
In java there must be at least two calls to the function with different arguments and the output must clearly show the task being performed. (ONLY ARRAYS or ARRAYLIST)
Develop a function that accepts an array and returns true if the array contains any duplicate values or false if none of the values are repeated.
Develop a function that returns true if the elements are in decreasing order and false otherwise.
A “peak” is a value in an array that is preceded and followed by a strictly lower value. For example, in the array {2, 12, 9, 8, 5, 7, 3, 9} the values 12 and 7 are peaks. Develop a function that returns the number of peaks in an array of integers. Note that the first element does not have a preceding element and the last element is not followed by anything, so neither the first nor last elements can be peaks.
Develop a function that finds the starting index of the longest subsequence of values that is strictly increasing. For example, given the array {12, 3, 7, 5, 9, 8,…
Q1/ find code optimization of this code then
find type to this code.
for (i=1;i
Chapter 7 Solutions
Problem Solving with C++ (10th 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
- [CLO-5] What is the value of the variable ss after the following code is executed? int x[ 7 ] = (5,10,3,0,-10,4); int ss=0; for (int i=1;i<=6; i++) { ss+=x[i]; cout<arrow_forwardWhat's wrong with this scrap of code? 1 #include 2 int main() { 3456 int a[5]; for(int i = 1; i <= 5; i++) ☐ a[i] a[i] = 0; 6 }arrow_forwardIn C++,arrow_forwardfunction myCompose(f,g){// TODO: return (f o g);// that is, a function that returns f(g(x)) when invoked on x.}arrow_forwardPlease use easy logic with proper indentations and comments for understanding!. Coding should be in C++. 3. Define a class which stores up to 10 integer values in an array. The class should also define the following 4 public methods: setNumber – accepts an integer value to store in the array. The value is stored in the next available element of the array (first call to the method stores the value in element 0 with the second call storing the value in element 1.) The method returns true if there is room in the array and the integer was successfully stored. Returns false otherwise. clear – removes all values from the array so that the array can be reused. displayNumbers – displays the values currently stored in the array. getStats – determines the largest, smallest, and average of the values currently stored in the array. These values are returned to the caller via reference parameters. All methods should produce correct results regardless of the order in which…arrow_forwardWrite in C++ Alice is trying to monitor how much time she spends studying per week. She going through her logs, and wants to figure out which week she studied the least, her total time spent studying, and her average time spent studying per week. To help Alice work towards this goal, write three functions: min(), total(), and average(). All three functions take two parameters: an array of doubles and the number of elements in the array. Then, they make the following computations: min() - returns the minimum value in the array sum() - returns the sum of all the values in the array average() - returns the average of all the values in the array You may assume that the array will be non-empty. Function specifications: Function 1: Finding the minimum hours studied Name: min() Parameters (Your function should accept these parameters IN THIS ORDER): arr double: The input array containing Alice's study hours per week arr_size int: The number of elements stored in the array Return Value:…arrow_forwardadd explanationarrow_forwardc++ coding language I need help with part B and C please. If you are unable to do both, then PLEASE prioritize part C. I am really stuck and really can use the help. This is the code for c that was provided in order to guide me: const int N =31; // N parking spaces bool parking[N]; // the garage void EmptyTheLot(bool parking[], int N) { for(int i=0; i<N; i++) p[i]=false; // empty space } // returns -1 if no space found, //otherwise it returns 0<=i<N for a valid space. int FindSpace(int PlateNumber, bool parking[], int N) { // ????? } main() { EmptyTheLot(parking, N); // start with an empty parking garage. // get plate numbers and fill lot. }arrow_forwardTopical Information Use C++. This lab will help you practice with dynamic memory (NOT mixed with classes). Program Information Heat flow through a rod can be simulated fairly easily in a computer program. We can simulate the rod using an array of temperatures. The rod begins all at the same temperature (user determined), but holding some position(s) of the rod at constant temperature (holding a match or ice cube to the rod) provides a [set of] heat source(s) (or sink(s)). To update the temperature at each time step (second?), you take the average of the positions on each side from the previous time step (and at the current position). For instance, if the following was the initial state of the rod: +------+------+------+------+------+------+------+------+ | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | +------+------+------+------+------+------+------+------+ And then the user specifies that there is a heat source at the left end of 100 degrees:…arrow_forwardPlease answer in C++ Zenny recently learned about Array and now answers Array's questions. She told her friend Zen about this. Zen wants to check how much Zenny knows about Array. So, give her the perfect number N. The task of Zenny is to find the sum of all the different positive number and different integers in the given list. As Zenny begins to solve problems she needs your help. Input 1 5 -1 1-10-2 Output 1-3arrow_forwardPrigraming in Python Problem 6.3 Purpose: Write array functions to solve a mathematical problem. I'm sure you have all heard of Euclidean distance. In two dimensions, the Euclidean distance between (x1, x2) and (y1, y2) is the square root of (x1-y1)2 + (x2-y2)2, or ((x1-y1)2 + (x2-y2)2)1/2. For example, the distance between (3,1) and (1,1) is ((3-1)2+(1-1)2)1/2 = 2 and the Euclidean distance between (1,1) and (0,0) is ((1-0)2+(1-0)2)1/2 ~= 1.4142. The Euclidean norm of a vector is just its Euclidean distance to the origin, (0,0). Therefore, the Euclidean norm of (1,1) is ~= 1.4142. This notion of Euclidean norm can easily be extended to vectors of arbitrary dimension. Indeed, if x is a vector of dimension n (versus dimension 2), then its Euclidean norm, which we will denote by |x|2, is given by |x|2 = ( Σ i = 1 to n |xi|2 )1/2 = (|x1|2+|x2|2+ ... + |xn|2 )1/2 There, Σ is a shorthand for "sum," as we saw in lecture and |xi| is just the absolute value of the real number xi. By the way,…arrow_forwarda) FindMinIterative public int FindMin(int[] arr) { int x = arr[0]; for(int i = 1; i < arr.Length; i++) { if(arr[i]< x) x = arr[i]; } return x; } b) FindMinRecursive public int FindMin(int[] arr, int length) { if(length == 1) return arr[0]; return Math.Min(arr[length - 1], Find(arr, length - 1)); } What is the Big-O for this functions. Could you explain the recurisive more in details ?arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_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