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
For this c++ hw
1) Make a function that reads in 2 integers from the user. (call it Get2Ints)
2) Make a function that swaps 2 integers (call it swap)
3) Make a function swapAndMult that takes two ints as parameters, and one more int parameter which will be a multiplier
swapAndMult should take the two parameters and multiply them by the multiplier.
The parameters should return from the function with new values.
swapAndMult should NOT print out the values.
4) Make a function that prints 2 integers. Call it Print2Ints
Main function should:
a) declare two integers and a multiplier
b) read 2 integers from the user (use your function)
c) print the values of the integers (use the function)
d) swap the integers
e) print the values of the integers
f) read an additional integer (the multplier) from the user
g) print the multiplier from the user (sometimes called 'echoing the input')
h) call swapAndMult
i) print the values of the integers
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…
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
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
- Mark the following statements as true or false:arrow_forwarduse the function call process to write a main function that calls the Discard function below. You can use any food as its argument. C++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_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_forwardPlease answer in c++. with showing the code.arrow_forward
- I need this coded in c++, please.arrow_forward[C++ Programming] Please help 4-II. Do not copy other solutions. Please write your own progrmming to avoid doing same with others.arrow_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_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_forwardg) 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_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
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