#include #include #include using namespace std; #define MAX 100 void getData(int &size, float len[], float wid[]); void calcAreaPerim(int size, float len[], float wid[], float area[], float perim[]); void print(int size, float len[], float wid[], float area[], float perim[]); int main() { float len[MAX], wid[MAX], area[MAX], perim[MAX]; int size; // array sizeex getData(size, len, wid); calcAreaPerim(size, len, wid, area, perim); print(size, len, wid, area, perim); return 0; } // end main void getData(int &size, float len[], float wid[]) { ifstream infile; infile.open("shapes.data"); if (infile.fail()) { cout << "ERROR opening input file shapes.data" << endl << endl; exit(0); } // end if fail size = 0; // initialize array size to 0 infile >> len[size] >> wid[size]; // Read to EOF and also make sure not out-of-bounds on array while ((size < MAX) && (!infile.eof())) { size++; infile >> len[size] >> wid[size]; } // end !eof infile.close(); return; } // end function getData void calcAreaPerim(int size, float len[], float wid[], float area[], float perim[]) { for (int i = 0; i < size; i++) { area[i] = len[i] * wid[i]; perim[i] = (2 * len[i]) + (2 * wid[i]); } return; } // end function calcAreaPerim void print(int size, float len[], float wid[], float area[], float perim[]) { // print heading cout << setprecision(3) << fixed << showpoint; cout << endl; cout << setw(15) << "Length" << setw(15) << "Width" << setw(15) << "Area" << setw(15) << "Perimeter" << endl; for (int i = 0; i < size; i++) { cout << setw(15) << len[i] << setw(15) << wid[i] << setw(15) << area[i] << setw(15) << perim[i] << endl; } return; } // end function print