Respuesta :
Answer:
Please copy the C++ code inluded. It's better to open it with an Integrated Development Environment of your choice.
Th C++ code includes explanatory comments (after "//"). You may run it on on step by step basis.
The void function code follows:
void swapFunction(int & a, int & b) { // receives 2 references (&) as a and b
int c = a; // saves a's value (actually first's) to local variable c
a = b; // assigns b's value (actually second's) to a (actually first's)
b = c; // assigns to b (actually second) from c
}
Main function:
using namespace std; // Assumes "std::" prefix for "cin" and "cout"
int main() { // Main program unit
int first,second; // We must declare 2 variables to store 2 int values (data input)
cout << "First value:"; cin >> first; // Reads first value after a little message
cout << "Second value:"; cin >> second; // Reads second value after a little message
swapFunction(first,second); // Swap function call sends first's and second's references
cout << "First value:" << first << endl; // Displays new first value
cout << "Second value:" << second << endl; // Displays new second value
return 0; // Success exit returns 0
}
Explanation: The testable code is included as main function
- It declares 2 int variables to store input data
- Reads the input data
- Calls swapFunction to swap values stored
- Displays exchanged values
