#include #include #include using namespace std; void getData(ifstream &infile, float &len, float &wid); void calcAreaPerim(float len, float wid, float &area, float &perim); void print(float len, float wid, float area, float perim); int main() { float len, wid, area, perim; ifstream infile; infile.open("shapes.data"); if (infile.fail()) { cout << "ERROR opening input file shapes.data" << endl << endl; return 0; } // end if fail // print heading cout << setprecision(3) << fixed << showpoint; cout << endl; cout << setw(15) << "Length" << setw(15) << "Width" << setw(15) << "Area" << setw(15) << "Perimeter" << endl; getData(infile, len, wid); while (!infile.eof()) { calcAreaPerim(len, wid, area, perim); print(len, wid, area, perim); getData(infile, len, wid); } // end !eof infile.close(); // close file return 0; } // end main void getData(ifstream &infile, float &len, float &wid) { infile >> len >> wid; return; } // end function getData void calcAreaPerim(float len, float wid, float &area, float &perim) { area = len * wid; perim = (2 * len) + (2 * wid); return; } // end function calcAreaPerim void print(float len, float wid, float area, float perim) { cout << setw(15) << len << setw(15) << wid << setw(15) << area << setw(15) << perim << endl; return; } // end function print