Question
c++ Create a class called box that has the following attributes (variables): length, width, height (in inches), weight (in pounds), address (1 line), city, state,
c++
Create a class called box that has the following attributes (variables): length, width, height (in inches), weight (in pounds), address (1 line), city, state, zip code. These variables must be private. Create setter and getter functions for each of these variables. Also create two constructors for the box class, one default constructor that takes no parameters and sets everything to default values, and one which takes parameters for all of the above. Create a calcShippingPrice function that returns the cost of shipping a box, using the following formula:
Shipping price for a single box = (((length + width + height) * $0.50) + (weight * $1.00))
Finally, create a print function that prints length, width, height, address, city, state, zip code and shipping price to the screen.
You may not end up needing all of the above functions in main but you still need to create and test them all so that your box class is versatile and can be used by others.
Main should ask the user how many packages they wish to send, then create an array of boxes of that size. Have the user enter the information for each box, then display the information for all boxes as well as the total shipping price for all boxes combined.
Input validation:
Length, width, height, weight should all be positive. If negative or not supplied set to 0.
Address needs no input validation, but can have spaces in it (remember getline and ignore), if not supplied set to blank.
City needs no input validation but can have spaces in it, if not supplied set to blank.
State should be exactly two letters long. If invalid or not supplied set to XX.
Zip code should be 5 digits and positive (no leading zeros), if invalid or not supplied set to 00000.
Input validation should be done in your setter functions and/or constructors as needed to ensure no bad data can get in to the class variables. Invalid input should instead set the value to a default as specified above.
Your program should be split into three files, a .h file for the box class, a .cpp file for the box class, and a .cpp file for main.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started