// Sample Function Call with Argument Change
//
// File: SWAP.CPP
// Version: 3.1
// Created: 9/24/96
// Last updated: 10/20/99
// Written by: Dr. C. S. Tritt
//
#include <iostream>  // Header for stream I/O.
#include <fstream> // Header for file I/O.
#include <iomanip> // Header for I/O manipulators.

using namespace std;

// Function declaration use references and without default values.

void swap(float& first_indentifier, float& second_indentifier);

// Main program

int main(void)
{
// Declare and initialize variables.

	int p = 3; // Ouput numeric precision.
	float a = 2.5f; // Units and description of a (f indicates float value).
	float b = 7.5f; // Units and description of b.
	ofstream fout;  // Declare an output file object.

	fout.open("swap.out", ios::out);  // Open the output file.
	if (!fout) // See if the file was opened sucessfully.
	{ 
		cout << "Can't open output file!\n";
		return 1;
	}

	fout.setf(ios::showpoint); // Show decimal points.
	fout << setprecision(p);  // Set the precision.

	fout << "Before swapping...\n";
	fout << "a = " << a << " and b = " << b << endl;
	swap(a, b);
	fout << "After swapping...\n";
	fout << "a = " << a << " and b = " << b << endl;

	fout.close(); // Close the out file.

	return 0;
}

// Define the swap function.  Use references so argument changes are returned.

void swap(float& x, float& y)
{

//	This function swaps the values of its two arguments.	

	float hold;
	hold = x;
	x = y;
	y = hold;
	return;
}