Question: C++ Help. Please add comments to the following program. #ifndef BOX_H #define BOX_H class Box { public: Box(int length, int width, int height); Box(); Box

C++ Help. Please add comments to the following program.

#ifndef BOX_H #define BOX_H

class Box { public: Box(int length, int width, int height); Box(); Box operator+(const Box& b1) const; Box operator-(const Box& b1) const; Box operator*(const Box& b1) const; bool operator>(const Box& b1) const; Box operator++(); Box operator++(int); bool operator<(const Box& b1) const; bool operator<=(const Box& b1) const; bool operator>=(const Box& b1) const; bool operator==(const Box& b1) const; bool operator!=(const Box& b1) const;

void setLength(double); void setWidth(double); void setHeight(double);

friend std::ostream& operator<<(std::ostream& dout, const Box& b); private: // Declaring variables int length; int width; int height;

}; #endif

................................................................................................................

#include #include using namespace std; #include "box.h"

Box::Box(int length, int width, int height) {

setLength(length); setWidth(width); setHeight(height);

} void Box::setLength(double length) { if (length < 0) this->length = 0; else this->length = length; } void Box::setWidth(double width) { if (width < 0) this->width = 0; else this->width = width; } void Box::setHeight(double height) { if (height < 0) this->height = 0; else this->height = height; }

Box::Box() {

} Box Box::operator+(const Box& b1) const { double l = b1.length + length; double w = b1.width + width; double h = b1.height + height; Box b(l, w, h); return b; } Box Box::operator-(const Box& b1) const { Box b; b.setLength(length - b1.length); b.setWidth(width - b1.width); b.setHeight(height - b1.height);

return b; } Box Box::operator*(const Box& b1) const { double l = length * b1.length; double w = width * b1.width; double h = height * b1.height; Box b(l, w, h); return b; } bool Box::operator>(const Box& b1) const { if (length*width*height > b1.length*b1.width*b1.height) return true; else return false; } Box Box::operator++() { double l = ++length; double w = ++width; double h = ++height; Box b(l, w, h); return b; }

bool Box::operator<(const Box& b1) const { if (length*width*height < b1.length*b1.width*b1.height) return true; else return false; } bool Box::operator<=(const Box& b1) const { if (length*width*height <= b1.length*b1.width*b1.height) return true; else return false; } bool Box::operator>=(const Box& b1) const { if (length*width*height >= b1.length*b1.width*b1.height) return true; else return false; } bool Box::operator==(const Box& b1) const { if (length == b1.length && width == b1.width && height == b1.height) return true; else return false; } bool Box::operator!=(const Box& b1) const { if (length == b1.length && width == b1.width && height == b1.height) return false; else return true; }

ostream& operator<<(ostream& dout, const Box& b) { dout << "Length is " << b.length << ". Width is " << b.width << ". Height is " << b.height << "." << endl; return dout; }

Box Box::operator++(int) { const Box old(*this); ++(*this); return old;

// b.length++; // b.width++; // b.height++; //return b; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!