Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C PROGRAMMING: Define a function CoordTransform() that transforms its first two

ID: 3767717 • Letter: C

Question

C PROGRAMMING: 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.

#include

/* Your solution goes here */

int main(void) {
   int xValNew = 0;
   int yValNew = 0;

   CoordTransform(3, 4, &xValNew, &yValNew);
   printf("(3, 4) becomes (%d, %d) ", xValNew, yValNew);

   return 0;
}

Explanation / Answer

Solution:

#include <stdio.h>
//If you send a pointer to a int, you are allowing the contents of that int to change.
void CoordTransform(int xVal,int yVal,int* xNew,int* yNew){
*xNew = (xVal+1)*2;
*yNew = (yVal+1)*2;
}
int main(void) {
int xValNew = 0;
int yValNew = 0;
CoordTransform(3, 4, &xValNew, &yValNew);
printf("(3, 4) becomes (%d, %d) ", xValNew, yValNew);
return 0;
}

Output:

(3, 4) becomes (8, 10)