Question

In: Computer Science

Write the 2 possible ways the compiler could make function calls for the following operation. If...

Write the 2 possible ways the compiler could make function calls for the following operation. If there is a reason why there should only be one way to call this function, then explain why. The num variables are instances of the Number class.

fout << num;

____________________________________________________________________________________________________________________________________________________

Write the following function prototypes that would be declared for the Cplx class (you don't need to write the function definitions or write the rest of the class). Cplx class is a complex class with lots of data. Remember to show the return type, and const where needed. For all your parameters, call them lval or rval to show that you understand where they would be in the operation

// << function

// + as a non-member function

// + as a member function

// = as a member function

Solutions

Expert Solution

/*
Write the 2 possible ways the compiler could make function calls for the following operation.
Answer:
1) Member function
2) Non - member function (friend function )
*/

/*
If there is a reason why there should only be one way to call this function, then explain why.
Answer:
There is only one way to call the function because of operator overloading.
The function signature are different to distinguish between functions,
based on the number of parameter and type of parameter compiler determines
which function to call.
The key word friend before the function indicates it is a non - member function.
*/

/*
The num variables are instances of the Number class.
fout << num;
The above statement is used to display the value stored in the data member
of the class Number.
*/

/*
#include <iostream>
using namespace std;

class Cplx
{
public:
// << function
friend ostream& operator<<(ostream& , Cplx&);

+ as a non-member function
friend Cplx operator +(const Cplx &lval, const Cplx &rval);

// + as a member function
Cplx operator +(const Cplx &rval);

// = as a member function
void operator = (const Cplx &rval);
};
*/


Related Solutions

C++: Write the 2 possible ways the compiler could make function calls for the following operation....
C++: Write the 2 possible ways the compiler could make function calls for the following operation. If there is a reason why there should only be one way to call this function, then explain why. The num variables are instances of the Number class. fout << num;
Write a C function to implement operation of a stack using the following format: /** *...
Write a C function to implement operation of a stack using the following format: /** * function: *       push * * expects: *       pointer to the stack *       pointer to the size *       the value to push * * returns: *     true when value has been pushed *       false otherwise * * The push function push a value to the passed in stack */ bool push(int *stack, int *size, int max_size, int to_push) {...
1- write Commissioning, Startup, Operation, and Shutdown procedure of a pump 2- What is the function...
1- write Commissioning, Startup, Operation, and Shutdown procedure of a pump 2- What is the function of shaft sleeve for a centrifugal pump? 3: Discuss the types of pipe reducers for a centrifugal pumping system 4: Write a gate valve mounting procedure 5: Write assembly and dismantling procedure of a rising stem gate valve
Write a Python program that calls a function to sum all the numbers in a list...
Write a Python program that calls a function to sum all the numbers in a list and returns the result to the caller. The main program creates a list (with hard-coded or user input) and passes the list as an argument to the function. You may not use the built-in function, sum. The program calls a second function to multiply all the numbers in a list passed to it by main and returns the product back to the caller. List...
Write a program that asks the user for a Fahrenheit temperature and calls a function name...
Write a program that asks the user for a Fahrenheit temperature and calls a function name Celsius that returns the temperature in Celsius of the Fahrenheit temperature sent to it. Your function will look similar to this: double celsius(double f) { double c; : : return c; }
2. Following are three possible reactions that could occur when a sample of KClO3 (s) is...
2. Following are three possible reactions that could occur when a sample of KClO3 (s) is heated. One goal of this lab is to determine the correct one. Balance all three reactions. a. ___ KClO3 (s) ___ KClO2 (s) + _____ O2 (g) __________b. ___ KClO3 (s) ___ KClO (s) + _____ O2 (g) __________ c. ___ KClO3 (s) ___ KCl (s) + _____ O2 (g) __________  
Integrate the following function by using symbolic operation in MATLAB. y = x^3 − 2x^2 +...
Integrate the following function by using symbolic operation in MATLAB. y = x^3 − 2x^2 + 7
Given the following table of possible values for rv Z and the number of possible ways...
Given the following table of possible values for rv Z and the number of possible ways that this value can occur, Construct the pmf and cdf for this rv Graph the cdf Calculate Pr(Z=6) Calculate Pr(Z=2) Calculate Pr(Z > 4 or Z ≤ 2) Calculate Pr( 1 < Z ≤ 6) Calculate Pr( Z ≤ 3 | Z < 9 ) Z Count 0 4 1 10 2 16 4 11 6 5 8 3 9 1
list 3 possible ways that auditor independence could be further enhanced and improved beyond what is...
list 3 possible ways that auditor independence could be further enhanced and improved beyond what is currently in place in practice or through auditing standards.
Write a program that calls a/few function(s) to determine the smaller of two arguments. Test the...
Write a program that calls a/few function(s) to determine the smaller of two arguments. Test the program using integer, character and floating-point number arguments. Produce 3 separate programs solving the problem above. The three approaches you should be using are: a) 3 different functions (findMinimum1(), findMinimum2(), findMinimum3()), each to solve different data types parameters. b) Function overloading with only one function named findMinimum( ) c) Function template with only one function named findMinimum( )
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT