C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 6, Problem 6.49E
(pass-by-Value vs. Pass-by-Reference) Write a complete C++
a) function tripleByValue that passes a copy of count by value, triples the copy and returns the new value and
b) function tripleByReference that passes count by reference via a reference parameter and triples the original value of count through its alias (i.e. the reference parameter).
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(C PROGRAMMING ONLY!)
6. Teaching the Dog To Sitby CodeChum Admin
Ever since I was a kid, I've always wanted to see a dog sit because it's so cute ?
Let's create a function that lets a dog sit!
Instructions:
In the code editor, you are provided with the definition of a struct Dog. This struct needs an integer value for its age. Furthermore, in the main, a Dog is already created for you and is passed to a call to a function, sit().Your task is to declare and define the function sit() which has the following details:Return type - voidName - sitParameters - 1 DogDescription - prints the message, "Arf arf! My age is <AGE_OF_DOG> and I know how to sit!"Input
1. The age of the Dog
Output
Enter age of Dog: 3Arf arf! My age is 3 and I know how to sit!
You must answer the Problem in C++.
(Anagrams)
Write a function that checks whether two words are anagrams. Two words are anagrams if they contain the same letters in any order. For example, “silent” and “listen” are anagrams.
The header of the function is as follows:
bool isAnagram(const string& s1, const string& s2)
Write a test program that prompts the user to enter two strings and checks whether they are anagrams.
Sample Run 1
Enter a string s1: silent
Enter a string s2: listen
silent and listen are anagrams
Sample Run 2
Enter a string s1: split
Enter a string s2: lisp
split and lisp are not anagrams
Topic: A function with parameters passed by value and passed by reference
Do not use anything beyond Chapter 6 materials. Write a C++
Write a single function rectangleAreaPerim (width, height, area, perimeter) that calculates both the area and the perimeter of a rectangle given its width and height.
-Input parameters to the functions are the width and height of the rectangle. Function cannot modify the input parameters.
-Output parameters of the function are the area, perimeter, and a boolean return (success or failure).
-This function returns true if both width and height are not negative, and thus calculation is required. Otherwise the function returns false and skips all calculations.
-The function rectangleAreaPerim(width, height, area, perimeter) should Not use any "cin" or "cout". Only the main() function will contain "cin" and "cout".
-The main() function calls the function rectangleAreaPerim() in a loop until the user enters 0 0. These are "Sentinel" values that stop the…
Chapter 6 Solutions
C++ How to Program (10th Edition)
Ch. 6 - Show the value of x after each of the following...Ch. 6 - (Parking Charges) A parking garage charges a...Ch. 6 - Prob. 6.13ECh. 6 - (Rounding Numbers) Function floor can be used to...Ch. 6 - Prob. 6.15ECh. 6 - (Random Numbers) Write statement that assign...Ch. 6 - (Random Numbers) Write a single statement that...Ch. 6 - Prob. 6.18ECh. 6 - Prob. 6.19ECh. 6 - Prob. 6.20E
Ch. 6 - Prob. 6.21ECh. 6 - Prob. 6.22ECh. 6 - Prob. 6.23ECh. 6 - (Separating Digits) Write program segments that...Ch. 6 - (Calculating Number of Seconds) Write a function...Ch. 6 - (Celsius and Fahrenheit Temperature) Implement the...Ch. 6 - (Find the Minimum) Write a program that inputs...Ch. 6 - Prob. 6.28ECh. 6 - (Prime Numbers) An integer is said to be prime if...Ch. 6 - Prob. 6.30ECh. 6 - Prob. 6.31ECh. 6 - (Quality Points for Numeric Grades) Write a...Ch. 6 - Prob. 6.33ECh. 6 - (Guess-the-Number Game) Write a program that plays...Ch. 6 - (Guess-the-Number Game Modification) Modify the...Ch. 6 - Prob. 6.36ECh. 6 - Prob. 6.37ECh. 6 - Prob. 6.38ECh. 6 - Prob. 6.39ECh. 6 - Prob. 6.40ECh. 6 - Prob. 6.41ECh. 6 - Prob. 6.42ECh. 6 - Prob. 6.43ECh. 6 - Prob. 6.44ECh. 6 - (Math Library Functions) Write a program that...Ch. 6 - (Find the Error) Find the error in each of the...Ch. 6 - (Craps Game Modification) Modify the craps program...Ch. 6 - (Circle Area) Write a C++ program that prompts the...Ch. 6 - (pass-by-Value vs. Pass-by-Reference) Write a...Ch. 6 - (Unary Scope Resolution Operator) What’s the...Ch. 6 - (Function Templateminimum) Write a program that...Ch. 6 - Prob. 6.52ECh. 6 - (Find the Error) Determine whether the following...Ch. 6 - (C++ Random Numbers: Modified Craps Game) Modify...Ch. 6 - (C++ Scoped enum) Create a scoped enum named...Ch. 6 - (Function Prototype and Definitions) Explain the...Ch. 6 - Prob. 6.57MADCh. 6 - Prob. 6.58MADCh. 6 - (Computer-Assisted Instruction: Monitoring Student...Ch. 6 - (Computer-Assisted Instruction: Difficulty Levels)...Ch. 6 - (Computer-Assisted Instruction: Varying the Types...
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
- Hello, I am having a problem with this homework assignment for C++. 14.) Write a function definition for a function named getSmaller: a) Accept two whole numbers as input parameters. b) Return the smaller number. Example: Given the arguments 10 and 3 return 3. I am trying to include a cin but having troublesarrow_forwardIn C++ Language (please use hint) : Write a function which will swap its arguments if the first argument is greater than its second argument, but will not interchange them if the first argument is samller than or equal to the second argument. The function should return 1 if a swap was made, and 0 otherwise. (Hint: Make sure to use call by reference.) Write also a short test driver (i.e. a main() invoking your function).arrow_forwardC++ Coding Question, Fill the void function *n1, int *n2, int *n3) void passReference(int { // Write your code here } Rounding to nearest 10 and rotating once clockwise In this coding exercise, you are asked to write the body of a function called passReference, which takes three integers by reference, round off each number to the nearest 10, and then right rotate all the numbers clockwise only once. For example, if variables a, b, and c contains the following values: a = 214; b = 2147; c=214748; Then values of variables after calling the passReference(&a, &b, &c) will be: a = 214750 b = 210 c=2150 Sample inputs 214,2147,214748 10,20,30 0,2,3 5,9,13 2147483641,2147483635,2147483631 Sample outputs 214750,210,2150 0,10,20 0,0,0 10,0,10 2147483630,2147483640,2147483630arrow_forward
- SOLVE THE ERRORS IN THE CODE GIVEN BELOW: QUESTION: Write the code of C++ which is used to take factorial of any number. you may pass the value to function by using "pass by value" and "pass by reference" methods.function name: factorial_calculate(); CODE: #include<iostream> using namespace std; int factorial_calaculate(int n) // start definition of function to calculate factorial{if(n > 1) // condition for recursion{return n * factorial_calculate(n - 1);}else // terminating condition{return 1;}} int main() // start definition of main function{int n; // declare required variablecout << "Enter the positive integer: ";cin >> n; // take number from the usercout << "Factorial of " << n << " = " << factorial_calculate(n); // display the resultreturn 0;}arrow_forwardHi, I am having trouble with this hw question for C++. 1.Write a function declaration for a function named getMax: a) Accept two numbers as input parameters. b) Return the largest number. 2) Write the function call for the getMax function with input parameters 10 and 15.5. Example Given the arguments 10 and 15.5 return 15.5.arrow_forwardSorry about that. Here's my C++ parameters: Instructions The function printGrade in Example 6-13 is written as a void function to compute and output the course grade. The course score is passed as a parameter to the function printGrade. Rewrite the function printGrade as a value-returning function so that it computes and returns the course grade. (The course grade must be output in the function main.) Also, change the name of the function to calculateGrade. The function printGrade has been posted below for your convenience. void printGrade(int cScore){cout << "The course grade is: "; if (cScore >= 90) {cout << "A." << endl; } else if (cScore >= 80) {cout << "B." << endl;} else if(cScore >= 70) {cout << "C." << endl;} else if (cScore >= 60) {cout << "D." << endl; } else {cout << "F." << endl; } Here's what I got so far: //Define include-header files#include <iostream>#include <string.h> //Define…arrow_forward
- C++ Programming. Topic: Working with pointers and dynamic memory. Indicators. Working with dynamic memory. Dynamic arrays and their use as function parameters. Task : Describe a void function named Swap(x,y) that swaps the values stored in the variables x and (x is a real type parameter and is both input and output). Using this function , for the given variables of real type a, b, c, d, one should sequentially replace the values of the pairs (a, b), (c, d) and (b, c) and let a, b, c, d be new values .arrow_forwardNote: Using C++. (Please correct the code as indicated below. Thank you!) Correct the code below making absolutely no changes to main(). Instead, alter 1) prototype for calcDiscount(), 2) alter definition of function calcDiscount(), 3) change Pre comment in calcDiscount as appropriate, and 4) add your name into signature function. Test your code 100.0 entered; the amount of discount output should be 10.00 and amount owed output should be 90.00. /*****************************************************************Change only 1) function calcDiscount, 2) its prototype *******and 3) change Pre comment in calcDiscount as appropriate, ****** and 4) add your name into signature function!***************************************************************************/#include <iostream>#include <iomanip>using namespace std;#define DISC_RATE 0.1//Function prototypesvoid signature(void);double calcDiscount(double);int main(){// Declare variaablesdouble amtOwing, discount;//Input amouont…arrow_forward- Highlight Draw 1 #include \\ function 3 int main () { int a = 3; 6. float b = 4.5; %3D int c = 5.25; %3D 8. float sum; 9. 10 sum = a + b + c 11 12 printf("The sum of a, b, and c is 8f.", sum); 13 return 0; 14 A function written in C++ is shown in the box above.arrow_forward
- g) Write the code to define the abs() function in the C language. The function should take an integer value as the parameter and should return the absolute value of that integer. Do not use any inbuilt function to write your code.arrow_forwardMark the following statements as true or false and correct the second part if false: 1. The statement: int A [3113]={{0,3)(0.2).(0.1}; initialized the matrix A to: 0 3:0 2:0 1. 2. User-defined functions in C++ classified into two categories: standard and pre-defined functions. 3. When used the predefine function cos(x) we must include the header 4. The following loop: for (index = 0; index < 20; index=index+1) sale[index] = index%2; Initialize the even components of sale to 0 and odd components to 1 5. The syntax of void function with parameters is : datatype functionName () { Statements 6. The statement double List [15]; Declares a one-dimensional array List, the components of the The components are List[0], List[1]., List[14]. 7. To initializes the 1" column of the matrix[4][$] to 0, we can use the following segment of program: for (row = 0; row <= 4; row++) for (col = 0; col <= 5; col++) matrix[row][col] =0; 8. Struct is a collection of a fixed number of components in which the…arrow_forward7- In how many ways can we pass arguments to a C++ function? a) One. b) Two. I need a sure answer 100% with explanation only solve number 10 c) Three. d) Unlimited 8- To access the value that the pointer is pointing to, we use 9- Is it possible to alter the address that the reference points to? (Yes or No) 10- We can write as many constructors in a C++ class as we want. (True or False)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
What is Abstract Data Types(ADT) in Data Structures ? | with Example; Author: Simple Snippets;https://www.youtube.com/watch?v=n0e27Cpc88E;License: Standard YouTube License, CC-BY