// G. Hagopian:  PPP 8 Drill #2
#include <iostream>

void swap_v(int a, int b) { 
	int temp; 
	temp = a;
	a = b; 
	b = temp; 
}
void swap_r(int& a, int& b) { 
	int temp; 
	temp = a; 
	a = b; 
	b = temp;
}
/*void swap_cr(const int& a, const int& b) { 
	int temp; 
	temp = a;
	a = b;
	b = temp;
}*/

void swap_dr(double& a, double& b) {
	double temp;
	temp = a;
	a = b;
	b = temp;
}

/* Which functions and calls compiled, and why? After each swap that compiled, print the value
of the arguments after the call to see if they were actually swapped. If you are surprised by a
result, consult §8.6.*/

int main() {
	int x = 7;
	int y = 9;
	swap_v(7, 9);
	swap_r(x, y); // When pass by value is used only the copies of x and y local to swap_v()
				 // are swapped.  After returning, x is still 7 and y is still 9
	std::cout << "\nx = " << x << ", and y = " << y;
	//swap_r(7, 9);  // I think this won't work because swap_r() takes non-constant reference variables
				  // The compiler reports "error C3892: 'a': you cannot assign to a variable that is const"
	
	const int cx = 7;
	const int cy = 9;
	swap_v(cx, cy);
	std::cout << "\nx = " << x << ", and y = " << y;
	swap_v(7.7, 9.9);
	std::cout << "\nx = " << x << ", and y = " << y;
	double dx = 7.7;
	double dy = 9.9;
	swap_dr(dx, dy);
	std::cout << "\ndx = " << dx << ", and dy = " << dy;
	swap_v(7.7, 9.9);
	std::cout << "\nx = " << x << ", and y = " << y;
	std::cin.get();
}