Define a function CoordTransform() that transforms its 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.

Respuesta :

Answer:

#include <iostream>

using namespace std;

void CoordTransform(int *ptr1, int *ptr2);

int main()

{

   int xVal;

int yVal;

cout<<"please enter two valid integers";

cin>>xVal;

cin>>yVal;

CoordTransform(&xVal , &yVal);

int xValNew=xVal;

int yValNew=yVal;

cout<<xValNew<<yValNew;

   

   return 0;

}

void CoordTransform(int *ptr1, int *ptr2)

{

int a = *ptr1;

*ptr1=(*ptr1+1)*2;

*ptr2=(*ptr2+1)*2;

}

Explanation:

It will return new values in previously defined variables

coding language: c++

Answer:

#include <iostream>

using namespace std;

void CoordTransform(int *xVal, int *yVal) {

// since we have passed x and y by adress:

// any change in xVal or yVal will also change the value of x and y

*xVal = (*xVal + 1) * 2;

*yVal = (*yVal + 1) * 2;

}

int main() {

int x, y;

// geting x from user

cout << "Enter x: ";

cin >> x;

// getting y from user

cout << "Enter y: ";

cin >> y;

// passing x and y to function CoordTransform() by adress.

CoordTransform(&x, &y);

cout << "new x: " << x << endl;

cout << "new y: " << y << endl;

return 0;

}

Explanation:

a pointer points to a memory location of the veraible so, when we pass a veriable by adress to a function, any change at that memory location also effect the value of the veriable that is local to the calling function.