1. Class specification Box.h models a box. Include private data for length, widt
ID: 3693050 • Letter: 1
Question
1. Class specification Box.h models a box. Include private data for length, width, and height. Include a default constructor setting box dimensions to 1 x 1 x 1, a parameterized constructor where the user passes in dimensions, a destructor, accessor and modifier functions for all data members, and area and volume functions. Be sure to include all PRE/POST comments.
2. Write Box.cpp. Be sure to include all PRE/POST comments.
3. Write an application which uses Box objects. The company sells snow globes which come in a 4 inch by 4 inch by 4 inch box. There are two shipping boxes, one is 16 x 12 x 4 inches and the other is 20 x 8 x 8 inches. For a number of orders, the company would like to know how many shipping boxes are required and the shipping costs where packing bubble material is $0.0023 per cubic inch and external plastic wrap is $0.0016 per square inch. Packing bubble material is only needed on a partially filled shipping box. Code should use three Box objects, one for the snow globe and one for each ship box. Class functions must be called when needed, for example, the volume function is needed to compute the cost of packing bubbles and the area function is needed to compute the cost of plastic wrap around the outside of the box. Code should be reusable; changes to size of the ship box or the cost of packing material should require only minor code change.
Input: The user will enter the number of snow globes to be shipped. The user can enter as many orders as desired using 0 as a sentinel.
Sample: After testing use the runs shown on the next page.
Submission:
Turn in Box.h, Box.cpp and Source.cpp code for class specification, class implementation, and application with proper documentation as previously discussed.
Check you have submitted the correct files! Incomplete file submission receives no credit.
CAUsersAdministratorDesktopCOS220 Assignments-F15COS220-A10-BoxDebugAssg3-Box.exe Student Name Enter number of snow globes to ship (0 to quit): 12 20 100 0 Number of snow globes: 12 Number of shipping box 1 needed: 1 Cost of packing material: $0.00 Cost of plastic wrap: $0.97 Total Cost: $0.97 Number of shipping box 2 needed: 1 Cost of packing material: $1.18 Cost of plastic wrap: $1.23 Total Cost: $2.41 Ship Box 1 is recommended Number of snow globes: 20 Number of shipping box 1 needed: 2 Cost of packing material: $0.59 Cost of plastic wrap: $1.95 Total Cost: $2.53 Number of shipping box 2 needed: 1 Cost of packing material: $0.00 Cost of plastic wrap: $1.23 Total Cost: $1.23 Ship Box 2 is recommended Number of snow globes: 100 Number of shipping box 1 needed: 9 Cost of packing material: $1.18 Cost of plastic wrap: $8.76 Total Cost: $9.93 Number of shipping box 2 needed: 5 Cost of packing material: $0.00 Cost of plastic wrap: $6.14 Total Cost: $6·14 Ship Box 2 is recommended Press any key to continue .. . _Explanation / Answer
Main.cpp
//This File: Main.cpp
#include "Box.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int l,w,h,boxes,temp;
Box b1(16,12,4); //initialize Box 1
Box b2(24,16,8); //initialize Box 2
int shipboxes,fit1, fit2, empty;
double cost;
bool full;
Box sgb; //Snow Globe Box
do{ //initial read
cout<<"Enter number of snow globes to ship (0 to quit): ";
cin>>boxes;
if(boxes<0){ //ensure user is entering valid data
cout<<"Error: Please enter a non negative integer value"<<endl;
}
}while(boxes<0); //keep getting user from data until valid data is entered
while(boxes != 0){ //keep the program running until user enters 0
do{
cout<<"Enter length, width and height of snow globe container: ";
cin>>l>>w>>h;
cout<<endl;
if(l<1 || w<1 || h<1){
cout<<"Error: Please enter a value greater than 0!";
}
}while(l<1 || w<1 || h<1);
sgb.setDim(l,h,w); //store the valid values in the snow globe object
cout<<"Number of snow globes: "<<boxes<<endl;
cout<<"Dimensions of snow globe box (L x W x H): "<<l<<" x "<<w<<" x "<<h<<endl;
//code to determine how many snow globe boxes that fit in either shipping boxes
fit1 = (b1.getL() / sgb.getL()) * (b1.getW() / sgb.getW()) * (b1.getH() / sgb.getH());
fit2 = (b2.getL() / sgb.getL()) * (b2.getW() / sgb.getW()) * (b2.getH() / sgb.getH());
cout<<"Number that fit in Ship Box 1: "<<fit1<<endl;
cout<<"Number that fit in Ship Box 2: "<<fit2<<endl;
cout<<endl;
if(fit1 > 0){ //print box 1's info
cout<<"Ship Box 1:"<<endl;
shipboxes = (boxes+fit1-1)/fit1;
cout<<"Number of Ship Boxes Needed: "<<shipboxes<<endl;
full = boxes%fit1;
cout<<"Partial Box Used: "<<boolalpha<<full<<endl;
empty = (shipboxes * b1.getVolume()) - (boxes * sgb.getVolume());
if(empty != 0){ //calculate the remaining volume that needs packing material
cost = empty * 0.0023;
cout<<"Packing cost for Partial box: $"<<setprecision(2)<<fixed<<cost<<endl;
}
cout<<endl;
}
if(fit2 > 0){ //print box 2's info
cout<<"Ship Box 2:"<<endl;
shipboxes = (boxes+fit2-1)/fit2;
cout<<"Number of Ship Boxes Needed: "<<shipboxes<<endl;
full = boxes%fit2;
cout<<"Partial Box Used: "<<boolalpha<<full<<endl;
empty = (shipboxes * b2.getVolume()) - (boxes * sgb.getVolume());
if(empty != 0){ //calculate the remaining volume that needs packing material
cost = empty * 0.0023;
cout<<"Packing cost for Partial box: $"<<setprecision(2)<<fixed<<cost<<endl;
}
}
if(fit1 == 0 && fit2 == 0){ //both Box 1 and Box 2 won't work
cout<<"No shipping box is available!"<<endl;
}
cout<<string(75,'-')<<endl<<endl; //print '-' to show the end of the order
do{ //get the next order
cout<<"Enter number of snow globes to ship (0 to quit): ";
cin>>boxes;
if(boxes<0){
cout<<"Error: Please enter a non negative integer value"<<endl;
}
}while(boxes<0);
}
return 0;
}
Box.h
//This File: Box.h
#pragma once
class Box
{
public:
Box(); //POST: a 1x1x1 box is created
Box(int l, int w, int h); //POST: a user defined box is created
~Box(); //POST: Destructor
int getArea() const; //PRE: length and width must be non negative
//POST: return area of the box
int getVolume() const; //PRE: length, width and heigth must be non negative
//POST: return volume of the box
int getL() const; //POST: return Length of Box
int getW() const; //POST: return Width of Box
int getH() const; //POST: return Height of Box
void setDim(int l, int w, int h); //POST: return dimensions of the box
private:
int width;
int length;
int height;
};
Box.cpp
//This File: Box.cpp
#include "Box.h"
Box::Box()
//POST: a 1x1x1 box is created
{
width = 1;
length = 1;
height = 1;
}
Box::Box(int l, int w, int h)
//POST: a user defined box is created
{
length = l;
width = w;
height = h;
}
Box::~Box()
//POST: Destructor
{
}
int Box::getArea() const
//PRE: length and width must be non negative
//POST: return area of the box
{
return (width * length);
}
int Box::getVolume() const
//PRE: length, width and heigth must be non negative
//POST: return volume of the box
{
return (width * length * height);
}
int Box::getL() const
//POST: return Length of Box
{
return length;
}
int Box::getW() const
//POST: return Width of Box
{
return width;
}
int Box::getH() const
//POST: return Height of Box
{
return height;
}
void Box::setDim(int l, int w, int h)
//POST: return dimensions of the box
{
length = l;
width = w;
height = h;
}
sample output
Enter number of snow globes to ship (0 to quit): 20
Enter length, width and height of snow globe container: 12 20 100
Number of snow globes: 20
Dimensions of snow globe box (L x W x H): 12 x 20 x 100
Number that fit in Ship Box 1: 0
Number that fit in Ship Box 2: 0
No shipping box is available!
---------------------------------------------------------------------------
Enter number of snow globes to ship (0 to quit): 0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.