{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# sol4 - 1.124J Foundations of Software Engineering Problem...

This preview shows pages 1–3. Sign up to view the full content.

1.124J Foundations of Software Engineering Problem Set 4 - Solution Due Date: Tuesday 10/17/00 Problem 1:[40%] sol4_1.h // Problem Set#4 - Problem#1 solution [sol4_1.h] #define YEARS 50 #define MONTHS 12 template<typename DataType> int readData( DataType (&data)[YEARS][MONTHS], int &firstYear) { int nYears=0; char fileName[80]; cout << "\n\n First year: " ; cin >> firstYear ; cout << " File with data: " ; cin >> fileName ; ifstream inputStreamName (fileName); inputStreamName.clear(); while(1) {

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
for(int j=0 ; !inputStreamName.eof() && j<MONTHS ; j++) inputStreamName >> data[nYears][j]; if(inputStreamName.eof()) break; nYears++; } cout << "\n Data for " << nYears << " years have been read\n\n"; return nYears; } template<typename DataType> void writeInvertedData( DataType (&data)[YEARS][MONTHS], int firstYear, int lastYear, int precision) { int nYears=lastYear-firstYear+1; char fileName[80]; cout << " File to store data: " ; cin >> fileName ; ofstream outputStreamName(fileName); outputStreamName << setw(6) << "\nMonth" ; for(int i=0; i<nYears; i++) outputStreamName << setw(9) << firstYear+i ; outputStreamName << endl; for(int j=0 ; j<MONTHS ; j++) { outputStreamName.setf(ios::left); outputStreamName << setw(2) << " " << setw(4) << j+1 ; outputStreamName.unsetf(ios::left); outputStreamName.setf(ios::fixed);
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}