Write a program that lets the user input two integers. You want to triple both integers together in a separate function (but you can't directly return two values from the function). So pass the integers two ways by reference to the same function. Use one argument by pointer (and triple what the pointer is pointing at - the variable in main) and one argument by a reference variable (a new local name to the variable in main) so we can try both ways without any return. Print the results in main. Include the proper function prototype. Attach your .cpp file and an output .txt file and submit.

Answer :

Answer:

Explanation:

#include <iostream>

using namespace std;

//function declaration

void triple(int *a,int *b);

//function implementation which will triple the numbers

void triple(int *a,int *b)

{

  //Tripling the numbers

  *a=(*a)*(*a)*(*a);

  *b=(*b)*(*b)*(*b);

}

int main()

{

//Declaring varibles  

int a,*b,c;

//Getting the First Number entered by the user

cout<<"Enter First number :";

cin>>a;

//getting the second number entered by the user

cout<<"Enter Second number :";

cin>>c;

//Assigning the address of variable 'c' to the pointer variable 'b'

b=&c;

//calling the function by passing the arguments

triple(&a,b);

//Displaying the output after tripling the numbers.

cout<<"After Tripling the numbers are "<<a<<" and "<<*b<<endl;

     

return 0;

}

_____________________________________________

Output:

(image attached)

${teks-lihat-gambar} shallomisaiah19

Other Questions