#include #include #include using std::cout; using std::endl; using std::fixed; using std::setprecision; #define STANDARD_PAINT 0 #define DELUXE_PAINT 1 #define CEILING_HEIGHT 9 #define MAXBEDROOMS 5 #define MAXSTRINGLENGTH 20 #define SQFT_PER_GALLON 1000 #define SQFT_PER_HOUR 500 #define PAINTER_WAGE 20 class House { private: double lrWidth, lrLength; double bedroomWidth[MAXBEDROOMS]; double bedroomLength[MAXBEDROOMS]; int numBedrooms; public: House(int numBed) { numBedrooms = numBed; } House() { numBedrooms = 3; } void setLR(int width, int length) { lrWidth = width; lrLength = length; } void setBR(int id, int width, int length) { id --; if (id < 0 || id > numBedrooms-1) return; bedroomWidth[id] = width; bedroomLength[id] = length; } double getWallSurface() { double total = 0; total += lrWidth + lrLength; for(int b = 0; b < numBedrooms; b++) { total += bedroomWidth[b] + bedroomLength[b]; } total *= CEILING_HEIGHT; return total; } void display() { cout << "Living Room: " << lrWidth << " x " << lrLength << endl; for(int b = 0; b < numBedrooms; b++) { cout << "Bedroom " << b+1 << ": " << bedroomWidth[b] << " x " << bedroomLength[b] << endl; } } }; class Paint { private: char color[MAXSTRINGLENGTH]; int quality; public: Paint(char col[], int qual) { strcpy(color,col); quality = qual; } Paint() { strcpy(color,"white"); quality = STANDARD_PAINT; } double pricePerGallon() { if (quality == STANDARD_PAINT) return 5; else return 10; } void display() { cout << color; if (quality == DELUXE_PAINT) cout << " (DELUXE) "; } }; class Estimate { private: House house; Paint paint; double materials; double labor; double total; public: Estimate() { } void setHouse(House h) { house = h; } void setPaint(Paint p) { paint = p; } void computeCost() { int gallonsToBuy = ceil(house.getWallSurface()/SQFT_PER_GALLON); materials = gallonsToBuy * paint.pricePerGallon(); labor = house.getWallSurface() / SQFT_PER_HOUR * PAINTER_WAGE; total = labor+materials; } void display() { computeCost(); cout << "We will paint your " << house.getWallSurface() << " square foot home" << endl << "using "; paint.display(); cout << fixed << setprecision(2); cout << " for $" << total << "." << endl; cout << " Materials = " << materials << endl; cout << " Labor = " << labor << endl; } }; int main() { House whiteHouse(3); whiteHouse.setLR(20,15); whiteHouse.setBR(1,40,20); whiteHouse.setBR(2,35,20); whiteHouse.setBR(3,30,20); whiteHouse.display(); Paint favoritePaint("white",DELUXE_PAINT); Estimate est; est.setHouse(whiteHouse); est.setPaint(favoritePaint); est.display(); return 0; }