/* Lab 4 assignment
---------------------------------------------
Patrick Schmid pds2
January 30, 2006
Lab 4 solution
Lab instructor: Patrick Schmid
Lab section: 10 & 11
Purpose: Calculate the volume of a pyramid. Read base and height from
		 a text file. Output to screen and a text file. Use metric units.
Algorithm: Volume = Base * Height / 3
*/

#include <iostream.h>
#include <fstream.h>

void main() {
	//declare variables
	double base; //base in square meters
	double height; //height in meters
	double volume; //volume in cubic meters

	//open files
	ifstream indata1 ("pyramids.txt", ios::in); //input file
	ofstream outdata1 ("results.txt", ios::out); //output file
	
	//read from file
	indata1>>base>>height;

	//echo print input
	cout<<"Base (square meters): "<<base<<endl;
	cout<<"Height (meters): "<<height<<endl;
	outdata1<<"Base (square meters): "<<base<<endl;
	outdata1<<"Height (meters): "<<height<<endl;

	//check base & height
	if (height>0 && base>0) {

		//calculate volume
		volume = 1/3. * base * height;

		//output results to screen & file
		cout<<"Volume (cubic meters) of pyramid: "<<volume<<endl;
		outdata1<<"Volume (cubic meters) of pyramid: "<<volume<<endl;
	}

	//close files
	indata1.close();
	outdata1.close();
}

