Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

implement UML and classes Room, Apartment and Condominium. The first three classes have been discussed in class on Thu, the last one, Condominium is a

implement UML and classes Room, Apartment and Condominium. The first three classes have been discussed in class on Thu, the last one, Condominium is a new class which includes 3 Apartments, a few functions (you will define the functions only you need it)

1b. implement the main function to calculate the area of the condominium and find the apartment has largest area.

note:

a. define const functions whenever you can

b. read the code in the book and you can find class Rectangle and Carpet, which may help you understand.

2. re-organize the above classes into different files, you should have the following files

Room .h Room .cpp

Apartment .h Apartment .cpp

Condominium .h Condominium .cpp

The attached please download Rectangle.h Rectangle.cpp, ############## rectangle.cpp #################

// Rectangle.cpp is the Rectangle class function implementation file. #include "Rectangle.h" /******************************************************************* * Rectangle::setLength * * If the argument passed to the setLength function is zero or * * greater, it is copied into the member variable length, and true * * is returned. If the argument is negative, the value of length * * remains unchanged and false is returned. * *******************************************************************/ bool Rectangle::setLength(double len) { bool validData = true; if (len >= 0) // If the len is valid length = len; // copy it to length else validData = false; // else leave length unchanged return validData; } /****************************************************************** * Rectangle::setWidth * * If the argument passed to the setWidth function is zero or * * greater, it is copied into the member variable width, and true * * is returned. If the argument is negative, the value of width * * remains unchanged and false is returned. * ******************************************************************/ bool Rectangle::setWidth(double w) { bool validData = true; if (w >= 0) // If w is valid width = w; // copy it to width else validData = false; // else leave width unchanged return validData; } /************************************************************** * Rectangle::getLength * * This function returns the value in member variable length. * **************************************************************/ double Rectangle::getLength() { return length; } /************************************************************** * Rectangle::getWidth * * This function returns the value in member variable width. * **************************************************************/ double Rectangle::getWidth() { return width; } /******************************************************************* * Rectangle::getArea * * This function calculates and returns the area of the rectangle. * *******************************************************************/ double Rectangle::getArea() { return length * width; } ################# rectangle.h ############################################ 
// Rectangle.h is the Rectangle class specification file. #ifndef RECTANGLE_H #define RECTANGLE_H // Rectangle class declaration class Rectangle { private: double length; double width; public: bool setLength(double); bool setWidth(double); double getLength(); double getWidth(); double getArea(); }; #end ########################## rectangle:: room############################################### 
#include  #include  using namespace std; class Rectangle { private: double length; double width; public: void setLength(double l) { length = l; } void setWidth(double w) { width = w; } double getArea() { return length* width; } }; class Room { private: Rectangle dim; string type; public: void setDimension(double l,double w) { dim.setLength(l); dim.setWidth(w); } double getArea() { return dim.getArea(); } string getType() { return type; } void setType(string t) { type = t; } }; class Apartment { private: Room kitchen; Room livingRoom; public: void setKitchenDim(double l, double w) { kitchen.setDimension(l,w); } void setLivingDim(double l, double w) { livingRoom.setDimension(l, w); } double getArea() { return kitchen.getArea() + livingRoom.getArea(); } }; int main() { Apartment ap; return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Develop a program for effectively managing diversity. page 303

Answered: 1 week ago

Question

List the common methods used in selecting human resources. page 239

Answered: 1 week ago