/*
	**************************
	Patrick Schmid
	pds2
	15 February 2006
	Lab 9 Solution
	Patrick Schmid
	Section 10 & 11
	**************************
	Purpose: Estimate heating and cooling load requirements for a given building
	Algorithm: Obtain user input. Use two functions to estimate requirements
*/

#include <iostream.h>
#include <math.h>

//prototypes
double heatload (double, double, double, double, double, double);   
double coolload(double, double, double, double, double, 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; //stores result of heatload function
	double resultCoolload; //stores result of coolload function

	//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 functions
	//explicit conversion of int nw to double (could be omitted, C++
	//does this conversion implicitly
	resultHeatload = heatload (sa, ht, (double) nw, wa, tinhs, mintohs);
	resultCoolload = coolload(sa, ht, (double) nw, wa, tincs, maxtocs);

	//output results
	cout<<"Estimated heating load requirement (Btu/hr): "<<resultHeatload<<endl;
	cout<<"Estimated cooling load requirement (Btu/hr): "<<resultCoolload<<endl;
}

//heatload function
//result is heating load (Btu/hr)
double heatload (double sa, double ht, double nw, double wa, double tinhs, double mintohs) {
	return sqrt(sa)*ht*4.0*(tinhs-mintohs)*1.25+wa*nw*(tinhs-mintohs)*2.0;
}

//coolload function
//result is cooling load (Btu/hr)
double coolload(double sa, double ht, double nw, double wa, double tincs, double maxtocs) {
	return sqrt(sa)*ht*4.0*(maxtocs-tincs)*1.25+wa*nw*(maxtocs-tincs)*2.0;
}
