Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Collecting Area for Solar Heated House Write a program that estimates the approp

ID: 3689071 • Letter: C

Question

Collecting Area for Solar Heated House

Write a program that estimates the appropriate size for the collecting area of a solar heated house. Determining collecting area size requires consideration of several factors, including the average number of heating degree days for the coldest month of a year (this is the product of the average difference between inside and outside temperatures and the number of days in the month), the heating requirement per square foot of floor space, the floor space, and the efficiency of the collection method. Your program will have to access (2) two data files.

File "hdd.txt" contains numbers representing the average heating degree days in the construction location for each of 12 months. File "solar.txt" contains the average solar insulation (rate at which solar radiation falls on one square foot of a given location) for each month. The first entry in each file represents data for January, the second is a data value for February, and so on.

The formula for approximating the desired collecting area (A) is

A = heat loss/energy resource

In turn, heat loss is computed as the product of the heating requirement, the floor space, and the heating degree days. The necessary energy resource is computed by multiplying the efficiency of the collection method by the average solar insulation per day and the number of days.

INPUT FILES:

hdd.txt

995         900        750         400         180         20           10           10           60           290         610         1051

solar.txt

500 750 1100 1490 1900 2100 2050 1550 1200 900 500 500

The following functions are mandatory and must be used in your program:

int daysinmonth(int);

int filemax(ifstream&, int&);

int nthItem(ifstream&, int);

SAMPLE RUN:

Enter 2 input files (heating_degree and then solar) : hdd.txt
solar.txt


What is the approximate heating requirement (Btu / degree day ft^2
of this type of construction?
=> 9


What % of solar insulation will be converted to usable heat?
=> 60


What is the floor space (ft^2)?
=> 1200


To replace heat loss of 11350800 Btu's in the coldest month (month 12)
with available solar insulation of 500 Btu / ft^2/day, and an efficiency of 60%, use solar collecting area of 1221 ft^2.

Explanation / Answer

#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
char filenamein[21];
cout << "Please enter 2 input files : hdd.txt solar.txt ";
cin >> filenamein >> filenamein;
ifstream fin (filenamein);
ifstream datastream (filenamein);
if (fin.fail())
{
cout << "Requested file not found." << endl;
exit (1);
}
if (datastream.fail())
{
cout << "Unable tp open input file." << endl;
exit (1);
}
int heatingdd, solarin, heatingre, efficiency, coldestmonth, days;
double floorspace, heatloss, collectingarea, energyresource;
int fileMax(ifstream&, int& );
int daysinmonth(int );
int insolation(ifstream&, int );
cout << "What is the approximate heating requirement (BTU/degree day ft^2) of this type of construction? ";
cin >> heatingre;
cout << "What percent of solar insulation will be converted to usable heat? " ;
cin >> efficiency;
cout << "What is the floor space (ft^2)? ";
cin >> floorspace;
heatingdd = fileMax(fin, coldestmonth);
days = daysinmonth(coldestmonth);
solarin = insolation(fin, coldestmonth);
heatloss = heatingre*floorspace*heatingdd;
energyresource = efficiency*0.01*solarin*days;
collectingarea = heatloss/energyresource;
cout << "To replace heat loss of " << heatloss << " BTU's in the coldest month with available solar insolation of " << solarin << " BTU/ft^2/day, and an efficiency of " << efficiency << "%, use " << endl;
cout << "a solar collecting area of " << collectingarea << "ft^2 ." << endl;
return 0;
}
int fileMax(ifstream& datastream, int& maxPos)
{
int large, next;
datastream >> large;
maxPos = 1;
int count = 2;
for (datastream >> next; !datastream.fail(); datastream >> next)
{
if (next > large)
{
large = next;
maxPos = count;
}
++count;
}
return large;
}
int daysinmonth(int monthnumber)
{
int ans;
switch (monthnumber)
{
case 2: ans=28;
break;
case 4: case 6: case 9: ans=30;
break;
default: ans=31;
}
return ans;
}
int insolation(ifstream& fin, int monthnumber)
{
int item;
for (int i=1; i< monthnumber; i++)
fin >> item;
return item;
}