Question

(Classes and Objects) Design a class named Box. The class should have the following private members:...

(Classes and Objects)

Design a class named Box. The class should have the following private members:

width - A double member variablethat holds the width of the box.

length – A double member variable for holding the length of the box.

height – A double member variable of type double that holds the height of the box.

In addition, provide the following member functions with full (inline) implementation.

a) A default constructor that sets all member variables to 0.

b) A constructor that accepts width, length and height and initializes the member variables appropriately.

c) A copy constructor

d) An appropriate set and get functions for width, length and height.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

class Box{
   private:
       double width, length, height;
   public:
       Box();
       Box(double w, double l, double h);
       Box(const Box& b);
      
       void setWidth(double w);
       void setLength(double l);
       void setHeight(double h);
      
       double getWidth() const;
       double getLength() const;
       double getHeight() const;
};

Box::Box(): width(0), length(0), height(0){
}
Box::Box(double w, double l, double h):
   width(w), length(l), height(h){
}
  
Box::Box(const Box& b){
   width = b.width;
   length = b.length;
   height = b.height;
}

void Box::setWidth(double w){width =w;}
void Box::setLength(double l){length =l;}
void Box::setHeight(double h){height=h;}

double Box::getWidth() const{return width;}
double Box::getLength() const{return length;}
double Box::getHeight() const{return height;}

=================================================================

Add a comment
Know the answer?
Add Answer to:
(Classes and Objects) Design a class named Box. The class should have the following private members:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Long Answer 2: (Classes and Objects) Design a class named Box. The class should have the...

    Long Answer 2: (Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables...

  • Design a class named Month. The class should have the following private members:

    Design a class named Month. The class should have the following private members:   • name - A string object that holds the name of a month, such as "January", "February", etc.   • monthNumber - An integer variable that holds the number of the month. For example, January would be 1, February would be 2, etc. Valid values for this variable are 1 through 12.  In addition, provide the following member functions:• A default constructor that sets monthNumber to 1 and name...

  • 1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - a int variable named itemNumber - an int variable named quantity - a double variable named cost - a double variable named totalCost. Total cost is defined as quantity X cost. - updateTotalCost() which takes no arguments and sets the values of the variable totalCost. 1c. Add the following public functions: - Accessor and Mutators for...

  • In JAVA 1. Create a class called Rectangle that has integer data members named - length...

    In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...

  • a. construct a class named room that declares two-double precision data members named length and width....

    a. construct a class named room that declares two-double precision data members named length and width. include a constructor that initializes each datavmember to 1.0 when a room object is created. add two accessor funtions for displaying the length and width values of a room object and two mutator functions that allow changing these data member values. b. include the class written for 6a in the context of a complete program

  • Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class...

    Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class should have a zero-argument constructor that initializes each data member to 0. It should have member functions named calcPerimeter() and calcArea() that calculate the perimeter and area of a rectangle respectively, a member function setLength() and setWidth() to set the length and width, member functions getLength() and getWidth() to return the length and width, and a member function showData() that displays the rectangle’s length,...

  • 1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - an int variable named year - a string variable named model - a string variable named purpose 1c Add the following public functions: - Default constructor which sets numeric members to -1 and string members to the empty string - Destructor to print "Removing instance from memory" - A non-default constructor to set the year and...

  • I need help with my homework please. I should write this program in C++ language and...

    I need help with my homework please. I should write this program in C++ language and use Inventory.h file (header file), Inventory.cpp file (implementation file), and main.cpp file (main program). This is the program: Demonstrate the class in a driver program. Input validation, don’t accept negative values for item number, quantity, or cost. 6. Inventory Class Design an Inventory class that can hold information and calculate data for items ma retail store's inventory. The class should have the following private...

  • Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default...

    Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default constructor -- that calls the default super class constructor and sets the default height to 0- Overloaded constructor with three parameters (length, width and height) – that calls the two parameterized super class constructor passing in length and width passed and sets the height to passed height.- setDimension method with three parameters (length, width, height) – call the super class setDimension and pass in...

  • C++ design a class named Technician that contains private data members to store the following: -technician's...

    C++ design a class named Technician that contains private data members to store the following: -technician's name (a string) - number of service calls - total time of all service calls - average service call time the technician class should also have the following public member functions: - a constructor function that initializes all data members by obtaining their values from the users. with the exception of the average service call time which will be calculated as: total_time/number_of_call - a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT