For questions 1-3 Review the following project document: Design a class named Bo
ID: 3815970 • Letter: F
Question
For questions 1-3 Review the following project document:
Design a class named Box whose dimensions are integers and private to the class. The dimensions are labeled: length l, breadth b, and height h.
The default constructor of the class should initialize l, b, and h to 0.
The parameterized constructor Box(int length, int breadth, int height) should initialize Box's l,b and h to length, breadth and height.
The copy constructor Box(Box B) should set l,b and h to B's l,b and h, respectively.
Every constructor should increment the global variable BoxesCreated.
The destructor should increment the global variable BoxesDestroyed.
Apart from the constructor and destructor, the class should have 4 functions:
int getLength() - Return box's length
int getBreadth() - Return box's breadth
int getHeight() - Return box's height
long long CalculateVolume() - Return the volume of the box
Overload the operator < for the class Box. Box A < Box B if:
A.l < B.l
A.b < B.b and A.l==B.l
A.h < B.h and A.b==B.b and A.l==B.l
Overload operator << for the class Box().
If B is an object of class Box:
cout<<Bcout<<B should print B.l, B.b and B.h on a single line separated by spaces.
Constraints
0 {l,b,h } 10^5
Two boxes being compared using the < operator will not have all three dimensions equal
1. What phase of the Software design cycle does this document represent? Are there any preconditions and postconditions presented here? If so what are they?
2. What are the methods and Attributes here? Which members should be private and which should be public?
3. From the documentation please create a header for the class and include all necessary functions as required. (Note: just create the function prototypes)
Explanation / Answer
Answers :
1) This document represent the System Design phase of software development life cycle.
--> Here, class definition along with all the methods and structure of class is given. This class definition will be given to the coders and they code it accordingly.
--> Pre condition is something that is expected by coder. if X is pre condition then coder will assume that X is true.
--> Post condition is something that is expected by user. If X is post condition then user is expecting X to be true and Coder will make sure in code that X becomes true.
--> In given design there are two pre conditions :
a) value od l, b and h will be > 0 and <105 .
b) Two boxes that are being compared with '<' operator will not have all three dimensions same.
--> Post conditions are given here :
a) when cout << B is entered, where B is box object, then code should print l, b and h in same line separated by space.
b) CalculateVolume() should return volume of the box.
similarly, getLength(), getHeight() and getBreadth() functions should return length l, height h and breadth b respectively.
c) Constructor with parameters should create object with given l,b and h.
similarly, copy constructor should use l,b h of given object and create another object with those values and constructor with no parameters should create object with l, b and h initialized to 0.
2) Methods :
- getLength() - returns length and it has to be public so that user can use it.
- getBreadth() - returns breadth and it has to be public.
- getHeight() - returns height and it has to be public too.
- CalculateVolume() - calculates volume of box and it has to be public.
Operators that are overloaded :
Operator '<' and "<<" : both has to be public so that user can use it.
Attributes :
length --> int l --> has to be private as it can be accessed with get function.
breadth --> int b --> has to be private as it can be accessed with a get function.
height --> int h--> has to be private as it can be accessed with get function.
int BoxesCreated --> it has to be private as it is used inside constructor and user should not know about number of boxes. it has to be static too as it is not property of object.
int BoxesDestroyed --> it has to be private as it is used inside destructor and user should not know about number of boxes. it has to be static too as it is not property of object.
3) Class prototype would look like this :
class Box {
public:
Box() { }
Box(int l ,int b, int h) { }
Box( const Box &obj) { }
~Box() { }
int getLength() { }
int getHeight() { }
int getBreadth() { }
long CalculateVolume() { }
bool operator<(Const Box&){ }
void operator<<(Const Box&) { }
private:
int l,b,h;
static int BoxesCreated, BoxesDestroyed;
}
if you have any doubts , you can ask in comment section.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.