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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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) { 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); for(int i=0; i<nYears; i++) { outputStreamName << setprecision(precision) << setw(9) << data[i][j]; } outputStreamName << endl; } cout << "\n Data for " << nYears << " years have been stored to file: "...
View Full Document

This note was uploaded on 12/04/2011 for the course ESD 1.124 taught by Professor Kevinamaratunga during the Fall '00 term at MIT.

Page1 / 9

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

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online