(Pass-by-Value vs. Pass-by-Reference) Write a complete C++ program with the two alternate functions specified below, each of which simply triples the variable count defined in main. Then compare and contrast the two approaches. These two functions are
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).
```
// Comparing call by value and call by reference.
#include
using namespace std;
int tripleByValue( int ); // function prototype
void tripleByReference( int & ); // function prototype
int main()
{
int count; // local variable for testing
// prompt for count value
cout << "Enter a value for count: ";
cin >> count;
// using call by value
cout << "\nValue of count before call to tripleByValue() is: "
<< count << "\nValue returned from tripleByValue() is: "
<< tripleByValue( count )
<< "\nValue of count (in main) after tripleCallByValue() is: "
<< count;
// using call by reference
cout << "\n\nValue of count before call to tripleByReference() is: "
<< count << endl;
tripleByReference( count );
cout << "Value of count (in main) after call to "
<< "tripleByReference() is: " << count << endl;
} // end main
// tripleByValue uses call-by-value parameter passing to triple the value
int tripleByValue( int value )
{
return value *= 3;
} // end function tripleByValue
// tripleByReference uses call-by-reference parameter passing
// to triple the variable referenced by valueRef
void tripleByReference( int &valueRef )
{
valueRef *= 3;
} // end function tripleByReference
```
You might also like to view...
Use the selectionSort method presented in this section to answer this question. What is list1 after executing the following statements?
``` double[] list1 = {3.1, 3.1, 2.5, 6.4}; selectionSort(list1); ``` a. list1 is 3.1, 3.1, 2.5, 6.4 b. list1 is 2.5 3.1, 3.1, 6.4 c. list1 is 6.4, 3.1, 3.1, 2.5 d. list1 is 3.1, 2.5, 3.1, 6.4
A method of securing data transmitted over a public untrusted network.
What will be an ideal response?
Which of the following best describes a federated relationship?
A. HIPAA patient privacy requirements for healthcare providers B. The airline industry C. Numerous franchises in a geographical area D. Third-party companies and their networks share customer data based upon a single sign-on to a primary organization
The official protocol used for Internet communication is:
a. TCP b. SMTP c. TCP/IP d. ftp