Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Having trouble writing a revision of function nthItem that returns zero if the file contains fewer than n items. // Estimate necessary solar collecting area

Having trouble writing a revision of function nthItem that returns zero if the file contains fewer than n items.

// Estimate necessary solar collecting area for a particular type of // construction in a given location. // #include #include #include #include using namespace std;

int daysInMonth( int); int fileMax( ifstream&, int& ); int nthItem( ifstream&, int );

int main() { int heatingDegreeDays, // average for coldest month solarInsolation, // average daily solar radiation per // ft^2 for coldest month coldestMonth, // number in range 1..12 heatingRequirement, // Btu / degree day ft^2 for given type // of construction efficiency; // % of solar insolation converted to // usable heat double floorSpace, // ft^2 heatLoss, // Btu's lost in coldest month energyResource, // Btu's heat obtained from 1 ft^2 // collecting area in coldest month collectingArea; // ft^2 needed to provide heat for // coldest month ifstream hddFile( "hdd.txt", // average heating degree days for each ios::in ), // of 12 months solarFile( "solar.txt",// average solar insolation for each of ios::in ); // 12 months

// Get from files average heating degree days for coldest month and // corresponding average daily solar insolation heatingDegreeDays = fileMax( hddFile, coldestMonth ); solarInsolation = nthItem( solarFile, coldestMonth ); hddFile.close(); solarFile.close(); // Get from user specifics of this house cout << "What is the approximate heating requirement (Btu / " << "degree day ft^2)" << endl << "of this type of construction?" << endl << "=> ";

cin >> heatingRequirement; cout << "What % of solar insolation will be converted to usable heat?" << endl << "=> "; cin >> efficiency; cout << "What is the floor space (ft^2)?" << endl << "=> "; cin >> floorSpace;

// Project collecting area needed heatLoss = heatingRequirement * floorSpace * heatingDegreeDays; energyResource = efficiency * 0.01 * solarInsolation * daysInMonth( coldestMonth ); collectingArea = int( heatLoss / energyResource + 0.5 );

// Display results cout << setiosflags( ios::fixed ) << setprecision( 0 ); cout << "To replace heat loss of " << heatLoss << " Btu's in the " << "coldest month (month " << coldestMonth << ")" << endl << "with available solar insolation of " << solarInsolation << " Btu / ft^2 / day, and an" << endl << "efficiency of " << efficiency << "%, use a solar collecting area of " << collectingArea << " ft^2." << endl;

return 0; }

// // Given a month number (1 = January, 2 = February, ..., // 12 = December ), return the number of days in the month // (non-leap year). // Pre: 1 <= monthNumber <= 12 // int daysInMonth( int monthNumber ) { int ans;

switch (monthNumber) { case 2: ans = 28; // February break;

case 4: // April case 6: // June case 9: // September case 11: ans = 30; // November break;

default: ans = 31; }

return ans; }

// // Finds and returns the largest value in a file of integers, and assigns // to maxPos the index of this largest value (index of first value = 1). // Pre: dataStream accesses a file of at least one integer // int fileMax( ifstream& dataStream, int& maxPos ) { int large, next;

dataStream >> large; maxPos = 1; int ct = 2; for (dataStream >> next; !dataStream.fail(); dataStream >> next) { if (next > large) { large = next; maxPos = ct; } ++ct; } return large; }

// // Finds and returns the nth integer in a file. // Pre: dataStream accesses a file of at least n integers (n >= 1). // int nthItem( ifstream& dataStream, int n) { int item;

for (int i = 1; i <= n; ++i) dataStream >> item;

return item; }

/* Input file hdd.txt 995 900 750 400 180 20 10 10 60 290 610 1051

Input file solar.txt 500 750 1100 1490 1900 2100 2050 1550 1200 900 500 500

What is the approximate heating requirement (Btu / degree day ft^2) of this type of construction? => 9 What % of solar insolation 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 insolation of 500 Btu / ft^2 / day, and an efficiency of 60%, use a solar collecting area of 1221 ft^2.

*/

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

International Baccalaureate Computer Science HL And SL Option A Databases Part I Basic Concepts

Authors: H Sarah Shakibi PhD

1st Edition

1542457084, 978-1542457088

More Books

Students also viewed these Databases questions