Question

5. The following function uses reference variables as parameters. Rewrite the function so it uses pointers instead of reference variables, and then demonstrate the function in a complete program. int pointe rFun (int int temp-xi y - temp * 10; &x, int &y) return x + y; Copy and paste your program into the word document. Capture the output window demonstrating your function works directly below the program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

int pointerFun(int *x, int *y) {
   int temp = *x;
   *x = *y * 10;
   *y = temp * 10;
   return *x + *y;
}

int main() {
   int x, y;
   cout << "Enter x and y: ";
   cin >> x >> y;
   cout << "pointerFun(&x, &y) returns " << pointerFun(&x, &y) << endl;
   cout << "x is changed to " << x << endl;
   cout << "y is changed to " << y << endl;
   return 0;
}

nterx and y: 2 5 po in terFunC&x, &y) returns 70 x is changed to 50 y is changed to 28 Process exited after 0.8422 seconds wi

Please\;let\;me\;know\;if\;you\;need\;me\;to\;change\;anything\\ Please\;upvote\;this\;answer!

Add a comment
Know the answer?
Add Answer to:
5. The following function uses reference variables as parameters. Rewrite the function so it uses pointers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Project Execute Tools AStyle Window Help 456 TDM-GCC 4.9.2 32-bit Profiling I"l practicel swapNums-KEY.cpp This progran uses a function to swop the values in two variables. 1 3 TO DO: 4 change th...

    Project Execute Tools AStyle Window Help 456 TDM-GCC 4.9.2 32-bit Profiling I"l practicel swapNums-KEY.cpp This progran uses a function to swop the values in two variables. 1 3 TO DO: 4 change the function swap Nuns to use two pointer parameters instead of two reference parameters, and 5 then modify the complete program accodingly <iostream > #include 8 9 using namespace std; 10 void swapNums (int&, int&) 12 int main() 13 14 15 int numl5, num2 = 7; 16 cout...

  • Lab 6.6 – Using Value and Reference Parameters Below is a copy of the source code....

    Lab 6.6 – Using Value and Reference Parameters Below is a copy of the source code. 1 // Lab 6 swapNums.cpp -- Using Value and Reference Parameters 2 // This program uses a function to swap the values in two variables . 3 // PUT YOUR NAME HERE. 4 #include <iostream> 5 using namespace std; 6 7 // Function prototype 8 void swapNums(int, int); 9 10 /***** main *****/ 11 int main() 12 { 13 int num1 = 5, 14...

  • C program that uses pointers as function arguments to do the following: To exemplify pointers, we...

    C program that uses pointers as function arguments to do the following: To exemplify pointers, we will be doing quadratics. Remember that a quadratic expression is of the form: ax2 + bx + c where a. b, c are constant and a is not 0. You will scan in the values a. b. and c. With these values, you will write three functions: quadraticFormula quadraticVertex quadratic Info The first function will perform the quadratic equation to find the roots of...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

  • 1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf...

    1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf ("Hello!") return 0 2 Assume a program has the following declarations: short s- 4 int i--5; long m-3 float f-19.3f; double d-3.6; What are the following values? (a) s+m (b) (float) d (c) d s (e) (int) f 3 What will be the output of the following program: int x = 3 float a 2.76; y-2* x; print f("X-2d, y*ta, z»%d", x, y, z);...

  • 81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5...

    81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5 );                    int BoxVolume(int length = {1}, int width = {1}, int height = {1});                                                     T__   F__                                                                     82. The following function is implemented to swap in memory the          argument-values passed to it:         void swap(int a, int b)                   {           int temp;             temp = a;             a = b;             b = temp;        ...

  • Consider the following code C++ like program: int i, j, arr[5]; //arr is an array starting...

    Consider the following code C++ like program: int i, j, arr[5]; //arr is an array starting at index 0 void exchange(int x, int y) { int temp:= x; x:= y; y:= temp; } main(){ for (j = 0; j < 5; j++) arr[j]:= j; i:= 1; exchange(i, arr[i+1]); output(i, arr[2]); //print i and arr[2] } What is the output of the code if both parameters in function swapping are passed by: a- value? b- reference? c- value-result?

  • C++ 4. (5 points) Identify the following items in the programming code shown below: a. Function...

    C++ 4. (5 points) Identify the following items in the programming code shown below: a. Function prototype, function heading, function body, and function definitions. b. Function call statements, formal parameters, and actual parameters. C. Value parameters and reference parameters. d. Local variables and global variables. 6. Named constants. #include <iostream> //Line 1 using namespace std; //Line 2 const double NUM = 3.5; //Line 3 int temp; //Line 4 void func(int, doubles, char); //Line 5 int main() int num; double one;...

  • code in C++ Create a program that uses the pass by reference operator instead of the...

    code in C++ Create a program that uses the pass by reference operator instead of the return command. Your main program will need to: create empty variables call void function 1 with no input to display your name to the screen call function 2 to collect the square feet that a gallon of paint covers from user call function 2 to collect the square feet of wall that needs to be painted call function 3 to calculate the number of...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT