//Zachary Abdollahi 			 CS1A                      Chapter 9, P. 538, #5
//
/*******************************************************************************
 *
 * DEMONSTRATE POINTER PARAMETERS
 * _____________________________________________________________________________
 * This program demonstrates rewriting a function to accept pointer
 * parameters instead of reference variables, multiplying each dereferenced
 * value by 10, swapping them, and returning their sum.
 *
 * Computation is based on the formulas:
 * New X = Original Y * 10
 * New Y = Original X * 10
 * Result = New X + New Y
 * _____________________________________________________________________________
 * INPUT
 *   num1   : First integer value entered by user
 *   num2   : Second integer value entered by user
 *
 * OUTPUT
 *   num1   : Modified first integer value
 *   num2   : Modified second integer value
 *   result : Sum of the two modified integer values
 *
 ******************************************************************************/
#include <iostream>
using namespace std;

// Function Prototype
int doSomething(int *, int *);

int main()
{
    int num1;               //INPUT/OUTPUT - First integer value
    int num2;               //INPUT/OUTPUT - Second integer value
    int result;             //OUTPUT       - Sum returned by doSomething

    // Prompt User for Two Integers
    cout << "Enter the first integer: ";
    cin >> num1;
    cout << "Enter the second integer: ";
    cin >> num2;

    // Display Values Before Function Call
    cout << "\nBefore calling doSomething:" << endl;
    cout << "num1 = " << num1 << ", num2 = " << num2 << endl;

    // Call Function Passing Addresses of num1 and num2
    result = doSomething(&num1, &num2);

    // Output Modified Values and Returned Sum
    cout << "\nAfter calling doSomething:" << endl;
    cout << "num1 = " << num1 << ", num2 = " << num2 << endl;
    cout << "Returned sum = " << result << endl;

    return 0;
}

/*******************************************************************************
 * Function: doSomething
 * Accepts two int pointers, swaps and multiplies their underlying values
 * by 10 via dereferencing, and returns the sum of the new values.
 ******************************************************************************/
int doSomething(int *x, int *y)
{
    int temp = *x;
    *x = *y * 10;
    *y = temp * 10;
    return *x + *y;
}