Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 7.2, Problem 14STE
Consider the following function definition:
void too2(int a[ ], int howMany) { for (int index = 0; index < howMany; index++) a[index] = 2; } |
Which of the following are acceptable function calls?
int myArray[29]; too2(myArray, 29); too2(myArray, 10); too2(myArray, 55); "Hey too2. Please, come over here." int yourArray[100]; too2(yourArray, 100); too2(myArray[3], 29); |
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Consider the following function main:Int main(){int inStock[10][4];int alpha [20];int beta[20];int gamma[4]= {11,13,15,17};int delta [10] = {3,5,2,6,10,9,7,11,1,8};}
a) Write the definition of the function setZero that initializes any one-dimentional array of type int to 0.b) Write the definition of the function inputArray that prompts the user to input 20 numbers and stores the numbers into alpha.c) Write the definition of the function doubleArray that initializes the elements of beta to two times the corresponding elements of alpha. Make sure that you prevent the function from modifying the elements of alpha.d) Write the definition of the function copyGamma that sets the elements of the first row of inStock to gamma and the remaining rows of inStock to three times the previous row of inStock. Make sure that you prevent the function from modifying the elements of gamma.e) Write the definitions of the function copyAlphaBeta that stores alpha into the first five rows of inStock and beta…
C code Blocks
Write the complete function that receives a pointer to the array's first element as an argument and multiplies the third element of the array by 10.
Define your function in the same way as the given function prototype.
Take a look at the "For example" below to see how the function is used in the main function and the expected result.
#include <stdio.h>#include <stdlib.h>void multiplyElement(int *ptr);int main(){ int array[5] = {1,2,3,4,5}; int *arrPtr = NULL; arrPtr = &array[0]; multiplyElement(arrPtr); for(int i = 0; i < 5; i++){ printf("%d ", array[i]); }return 0;}//Your answer starts here
For example:
Test
Result
int array[5] = {1,2,3,4,5}; int *arrPtr = NULL; arrPtr = &array[0]; multiplyElement(arrPtr); for(int i = 0; i < 5; i++){ printf("%d ", array[i]); }
1 2 30 4
C PROGRAM
Reverse + Random Formula
In the code editor, there's already an initial code that contains the function declaration of the function, computeReverseNumber(int n) and an empty main() function.
For this problem, you are task to implement the computeReverseNumber function. This function will take in an integer n as its parameter. This will get the reverse of the passed integer and will then compute and return the value:
result = (original_number + reverse_of_the_number) / 3
In the main() function, ask the user to input the value of n, call the function computeReverseNumber and pass the inputted value of n, and print the result in the main() with two (2) decimal places.
SAMPLE:
Input n: 20
Output: 7.33
Input n: 123
Output: 148.00
Chapter 7 Solutions
Problem Solving with C++ (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...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Your country is at war and your enemies are using a secret code to communicate with one another. You have manag...
Java: An Introduction to Problem Solving and Programming (7th Edition)
(Reverse an array) The reverse method in Section 7.7 reverses an array by copying it to a new array. Rewrite th...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
#inc1ude iostream #inc1ude string using namespace std; int main() { cout string("fantastic").size(); return 0;...
Starting Out with C++: Early Objects
Employee Class Modification In Programming Challenge 1 of Chapter 3, you wrote an Employee class. Add the follo...
Starting Out with Java: Early Objects (6th Edition)
What are the advantages and disadvantages of implicit declarations?
Concepts Of Programming Languages
Code an SQL statement that creates a table with all columns from the parent and child tables in your answer to ...
Database Concepts (7th Edition)
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
- -5- A PHP function is defined as follows: function planets ($arr) { if ($arr [1]) { print "Mercury"; } else { for ($i=0; $i <= $arr [2]; $i++) (print $arr [3] [$i]; } } print count ($arr); Recall that array $arr can be defined using a statement of the form: $arr array (...); Give an array $arr such that planets ($arr) prints Mercury O For this case, what is the output of the instruction print count ($arr); Give an array $arr such that planets ($arr) prints Venus o For this case, what is the output of the instruction print count ($arr); O Give an array $arr such that planets ($arr) prints Earth Jupiter Saturn. Note: the for loop must do three iterations in case (iii). -6- o For this case, what is the output of the instruction print count ($arr); 3. (a)arrow_forwardPYTHON You Define a Function Part 1: Write a function that takes in one or two input parameters and returns an output. The function should return the output of a one-line expression. Write at least three test cases for your function in the docstring. Make sure your function has just one line of code Part 2: Write the same function as a lambda function.arrow_forwardC code blocks Write the complete function that receives a pointer to a single floating point number as an argument and returns that number after subtracting 100 from it. Define your function in the same way as the given function prototype. Take a look at the "For example" below to see how the function is used in the main function and the expected result. (For interest sake, note that this is a pass-by-reference function call.) #include <stdio.h>#include <stdlib.h>void subtractFunc(float *a);int main(){ float num = 357.900; subtractFunc(&num); printf("%.3f", num); return 0;} //Your answer starts here For example: Test Result float num = 357.900; subtractFunc(&num); printf("%.3f", num); 257.900arrow_forward
- In c++, write a function void zero(int a[], int size, int target) that sets all elements of a larger than target to zero. Include a sensible main function which calls the function and prints out the results.arrow_forwardUsing C++ Programming language: Assume you want a function which expects as parameters an array of doubles and the size of the array. Write the function header that accepts these parameters but is defined in such a way that the array cannot be modified in the function. You can use your own variable names for the parameters.arrow_forwardc++ hw In this hw, you're going to be working with partially filled arrays that are parallel with each other. That means that the row index in multiple arrays identifies different pieces of data for the same person. This is a simple payroll system that just calculates gross pay given a set of employees, hours worked for the week and hourly rate. code format: // TODO: Add function prototypes for all the declared functions // TODO: Declare two functions to compute the highestPay and lowestPay// HINT: Each should return the index of the correct value in the grossPay array. /* TODO: Create a function calledgetEmployeeNames Arguments : Name array(first and last name) Maximum size Return the number of names filled.*/ /* TODO: Create a function calledgetHourlyPay Arguments : NameArray(filled in Step 1) HourlyPayArray(starts empty) NumberOfNamesFilled(from Step1)*/ int main(){ // TODO: Declare an array of strings for the employeeNames able to hold a…arrow_forward
- Question 2 Create a generic function sum that takes two integer/double numbers as parameters Not yet and prints the sum. answered Example: Marked out of sum(1.5, 3.5); sum(100, 200); // prints: 5 // prints: 300 2.00 P Flag question Submission instruction: Submit your code in the text editor below. Code must be indented. All the codes will be cross-checked for plagiarism and if found, both submissions will receive 0.arrow_forwardC++ Write a definition of a function called MAX which receives an integer array and its size parameters. It will return the max value of the parameter array.arrow_forwardConsider the following function. int my_func(int a) { return(a+3); } If the function is called using my_func(5), what will the function return?arrow_forward
- In C programming: Write a main() function using the following requirements:• Define a SIZE constant (the value is irrelevant, but for testing, you may want to keep it small enough – no bigger than 5)• Create an array of course pointers using SIZE• Dynamically allocate each element of the array• Call inputAllCourses()• Call printAllCourses().arrow_forwardCan the [] operator be defined as a nonmember function?arrow_forwardin c++ In statistics, the mode of a set of values is the value that occurs most often or with the greatest frequency. Write a function that accepts as arguments the following: A) An array of integers B) An integer that indicates the number of elements in the array The function should determine the mode of the array. That is, it should determine which value in the array occurs most often. The mode is the value the function should return. If the array has no mode (none of the values occur more than once), the function should return −1. (Assume the array will always contain nonnegative values.) Demonstrate your pointer prowess by using pointer notation instead of array notation in this function.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
What Are Data Types?; Author: Jabrils;https://www.youtube.com/watch?v=A37-3lflh8I;License: Standard YouTube License, CC-BY
Data Types; Author: CS50;https://www.youtube.com/watch?v=Fc9htmvVZ9U;License: Standard Youtube License