/*
	**************************
	Patrick Schmid
	pds2
	22 February 2006
	Lab 10 Solution
	Patrick Schmid
	Section 10 & 11
	**************************
	Purpose: Estimate heating and cooling load requirements as well 
	as appropriate heating/cooling unit sizes for a given building
	Algorithm: Obtain user input. Use two void functions to estimate requirements
*/

#include <iostream.h>
#include <math.h>

//prototypes
//prototypes can include variable names, but do not have to
//only variable types are required
void heatload (double sa, double ht, double nw, 
				 double wa, double tinhs, double mintohs,  
				 int & htsize, double & htload);   
void coolload(double, double, double, 
				double, double, double, int &, double &);

void main() {

	double sa; //square feet of enclosed space
	double ht; //building height in feet
	int nw; //number of windows 
	double wa; //average area of a window in square feet
	double tinhs; //average indoor temperature during heating season in Fahrenheit
	double mintohs; //minimum outdoor temperature during heating season in Fahrenheit
	double tincs; //average indoor temperature during cooling season in Fahrenheit
	double maxtocs; //maximum outdoor temperature during cooling season in Fahrenheit
	double resultHeatload; //estimated heating load
	double resultCoolload; //estimated cooling load
	int htsize; //estimated heating unit size
	int clsize; //estimated cooling unit size

	//get input from user
	cout<<"Please enter the following building information\n";
	cout<<"Enclosed space (square feet): ";
	cin>>sa;
	cout<<"Building height (feet): ";
	cin>>ht;
	cout<<"Number of windows (integer): ";
	cin>>nw;
	cout<<"Average area of a window (square feet): ";
	cin>>wa;
	cout<<"Average indoor temperature during heating season (F): ";
	cin>>tinhs;
	cout<<"Minimum outdoor temperature during heating season (F): ";
	cin>>mintohs;
	cout<<"Average indoor temperature during cooling season (F): ";
	cin>>tincs;
	cout<<"Maximum outdoor temperature during cooling season (F): ";
	cin>>maxtocs;

	//call void functions
	//explicit conversion of int nw to double (could be omitted, C++
	//does this conversion implicitly
	heatload (sa, ht, (double) nw, wa, tinhs, mintohs, htsize, resultHeatload);
	coolload (sa, ht, (double) nw, wa, tincs, maxtocs, clsize, resultCoolload);

	//output results
	cout<<"Estimated heating load requirement (Btu/hr): "<<resultHeatload<<endl;
	cout<<"Estimated heating unit size: "<<htsize<<endl;
	cout<<"Estimated cooling load requirement (Btu/hr): "<<resultCoolload<<endl;
	cout<<"Estimated cooling unit size: "<<clsize<<endl;
}

//heatload void function
//uses pass-by-reference to return estimated heat load (Btu/hr)
//and estimated heating unit size
void heatload (double sa, double ht, double nw, 
			   double wa, double tinhs, double mintohs,
			   int & htsize, double & htload) {
	
	//calculate estimated heating load
	htload = sqrt(sa)*ht*4.0*(tinhs-mintohs)*1.25+wa*nw*(tinhs-mintohs)*2.0;

	//determine needed unit size
	if (htload<=100000)
		htsize=100;
	else if (htload<=200000)
		htsize=200;
	else if (htload<=300000)
		htsize=300;
	else {
		cout<<"Error: Estimated heating load is too high\n";
		htsize=0; //we don't want to have any variables in our program
				  //that has not been assigned a value, but will be printed
				  //to the screen
	}
}

//coolload function
//uses pass-by-reference to return estimated cooling load (Btu/hr)
//and estimated cooling unit size
void coolload(double sa, double ht, double nw,
				double wa, double tincs, double maxtocs,
				int & clsize, double & clload) {

	//calculate estimated cooling load
	clload = sqrt(sa)*ht*4.0*(maxtocs-tincs)*1.25+wa*nw*(maxtocs-tincs)*2.0;

	//determine needed unit size
	if (clload<=50000)
		clsize=5;
	else if (clload<=100000)
		clsize=10;
	else if (clload<=150000)
		clsize=15;
	else {
		cout<<"Error: Estimated cooling load is too high\n";
		clsize=0; //we don't want to have any variable in our program
		          //that has not been assigned a value, but will be printed
				  //to the screen
	}
}
