7.8.1: Function pass by reference: Transforming coordinates. Define a function CoordTransform() that transforms the function's first two input parameters xVal and yVal into two output parameters xValNew and yValNew. The function returns void. The transformation is new = (old + 1) * 2. Ex: If xVal = 3 and yVal = 4, then xValNew is 8 and yValNew is 10. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include using namespace std; /* Your solution goes here */ int main() { int xValNew; int yValNew; int xValUser; int yValUser; cin >> xValUser; cin >> yValUser; CoordTransform(xValUser, yValUser, xValNew, yValNew); cout << "(" << xValUser << ", " << yValUser << ") becomes (" << xValNew << ", " << yValNew << ")" << endl; return 0; } 1 test passed All tests passed Run Feedback? How was this section?

Respuesta :

Answer:

Here is the CoordTransform() function:              

void CoordTransform(int xVal, int yVal, int &xValNew, int &yValNew){

xValNew = (xVal + 1) * 2;

yValNew = (yVal + 1) * 2; }

The above method has four parameters xVal  and yVal that are used as input parameters and xValNew yValNew as output parameters. This function returns void and transforms its first two input parameters xVal and yVal into two output parameters xValNew and yValNew according to the formula: new = (old + 1) *

Here new variables are xValNew  and yValNew and old is represented by xVal and yVal.

Here the variables xValNew and yValNew are passed by reference which means any change made to these variables will be reflected in main(). Whereas variables xVal and yVal are passed by value.

Explanation:

Here is the complete program:

#include <iostream>

using namespace std;

void CoordTransform(int xVal, int yVal, int &xValNew, int &yValNew){

xValNew = (xVal + 1) * 2;

yValNew = (yVal + 1) * 2;}

int main()

{ int xValNew;

int yValNew;

int xValUser;

int yValUser;

cin >> xValUser;

cin >> yValUser;

CoordTransform(xValUser, yValUser, xValNew, yValNew);

cout << "(" << xValUser << ", " << yValUser << ") becomes (" << xValNew << ", " << yValNew << ")" << endl;

return 0; }

The output is given in the attached screenshot   

Ver imagen mahamnasir
ACCESS MORE