This Program should run in C++
In an effort to develop in-depth knowledge of base class,
derived class, and operator overloading, we will expand on our
in-class exercise of developing the rectangleType class and
overload the following operators: +, -, *, ++, --, ==, !=,
>>, and <<. Your program should contain the following
features:
a. Create a base class named rectangleType with following private
data members:
• length with double type
• width with double type
b. rectangleType class should contain the following
functions:
• 2 constructors (one for default and another to initialize the two
private data members mentioned above)
• get methods (getLength() and getWidth()) for each private data
members
• setDimension() method with two arguments: length and width) to
set the private data members
• functions to overload the operators +, -, *, ++, -- for
manipulation of the private data members.
• functions to overload the operators ==, !=, <=, <, >=,
> for comparison of different rectangleType objects
• overload stream insertion and extraction operators in order to
print information out onto the screen
c. Create a derived class named boxType which inherits the
functionality from based class, rectangleType, but has its own data
member and functions to represent a box.
• height with double type
• 2 constructors (one for default and another to initialize the
three private data members of the base class and the derived
class)
• get method (getHeight) for the derived class’s data member
• overload the setDimension() method to set the data members of the
base class, rectangleType, as well as its own data member (hint:
setDimension(double l, double w, double h) where l=length, w=width,
and h=height)
• override the area() method as necessary to work with the derived
class
• add a new method called volume() to return the volume of the box
(using base class’s private data members, length & width, with
derived class’s private data member, height)
• functions to overload the operators +, -, *, ++, --, ==, !=,
<=, <, >=, > for the derived class
d. Create a caller (where main() is located) file. In this file,
create 2 boxType objects and execute all the overloaded operators
mentioned above. Use the code below:
int main()
{
boxType box1(12, 9, 6);
boxType box2(8, 7, 5);
boxType box3, box4, box5;
cout << "box1: " << box1 << endl;
cout << "box2: " << box2 << endl;
box3 = box1 + box2;
cout << "box3: " << box3 << endl;
box4 = box1 - box2;
cout << "box4: " << box4 << endl;
box5 = box1 * box2;
cout << "box5: " << box5 << endl;
if (box1 > box2)
cout << "Volume of box1 is greater than the volume of box2."
<< endl;
else
cout << "Volume of box1 is less than or equal to the volume
of box2." << endl;
box1++;
cout << "After increment the length, width, and height of
"
<< "box1 by one unit, \nbox1: "
<< box1 << endl;
box3 = ++box2;
cout << "New dimension of box2: " << box2 <<
endl;
cout << "New dimension of box3: " << box3 <<
endl;
return 0;
}
//Please like and comment
//rectangleType.cpp
#include "rectangleType.h"
rectangleType::rectangleType():length(0),width(0)
{
}
rectangleType::rectangleType(double l, double
w):length(l),width(w)
{
}
rectangleType::~rectangleType()
{
}
double rectangleType::getLength() const
{
return length;
}
double rectangleType::getWidth() const
{
return width;
}
void rectangleType::setDimension(double l, double w)
{
length = l;
width = w;
}
rectangleType rectangleType::operator+(const rectangleType &
obj)
{
rectangleType temp(length + obj.length, width +
obj.width);
return temp;
}
rectangleType rectangleType::operator-(const rectangleType &
obj)
{
rectangleType temp(length - obj.length, width -
obj.width);
return temp;
}
rectangleType rectangleType::operator*(const rectangleType &
obj)
{
rectangleType temp(length * obj.length, width *
obj.width);
return temp;
}
rectangleType rectangleType::operator++()
{
++length;
++width;
return rectangleType(length,width);
}
rectangleType rectangleType::operator++(int)
{
rectangleType temp(length++, width++);
return temp;
}
rectangleType rectangleType::operator--()
{
--length;
--width;
return rectangleType(length, width);
}
rectangleType rectangleType::operator--(int)
{
rectangleType temp(length--, width--);
return temp;
}
bool rectangleType::operator==(const rectangleType &
a)
{
return area() == a.area();
}
bool rectangleType::operator!=(const rectangleType &
a)
{
return area() != a.area();
}
bool rectangleType::operator<=(const rectangleType &
a)
{
return area() <= a.area();
}
bool rectangleType::operator<(const rectangleType &
a)
{
return area() < a.area();
}
bool rectangleType::operator>=(const rectangleType &
a)
{
return area() >= a.area();
}
bool rectangleType::operator>(const rectangleType &
a)
{
return area() > a.area();
}
double rectangleType::area() const
{
return length*width;
}
ostream & operator << (ostream &out, const
rectangleType &obj)
{
return out;
}
istream & operator >> (istream &in, rectangleType
&obj)
{
return in;
}
//rectangleType.h
#pragma once
#include<iostream>
using namespace std;
class rectangleType
{
public:
rectangleType();
rectangleType(double l, double w);
~rectangleType();
double getLength() const;
double getWidth() const;
void setDimension(double l, double w);
rectangleType operator+(const rectangleType&
obj);
rectangleType operator-(const rectangleType&
obj);
rectangleType operator*(const rectangleType&
obj);
rectangleType operator ++();
rectangleType operator ++(int);
rectangleType operator --();
rectangleType operator --(int);
bool operator==(const rectangleType& a);
bool operator!=(const rectangleType& a);
bool operator<=(const rectangleType& a);
bool operator<(const rectangleType& a);
bool operator>=(const rectangleType& a);
bool operator>(const rectangleType& a);
double area() const;
friend ostream & operator << (ostream
&out, const rectangleType &obj);
friend istream & operator >> (istream
&in, rectangleType &obj);
private:
double length;
double width;
};
//boxType.cpp
#include "boxType.h"
boxType::boxType():height(0)
{
}
boxType::boxType(double l, double w, double
h):height(h),rectangleType(l,w)
{
}
boxType::~boxType()
{
}
double boxType::getHeight() const
{
return height;
}
void boxType::setDimension(double l, double w, double h)
{
height = h;
rectangleType::setDimension(l, w);
}
double boxType::volume() const
{
return area()*height;
}
boxType boxType::operator+(const boxType & obj)
{
boxType temp(getLength() + obj.getLength(),
getWidth() + obj.getWidth(), obj.height + getHeight());
return temp;
}
boxType boxType::operator-(const boxType & obj)
{
boxType temp(getLength() - obj.getLength(), getWidth()
- obj.getWidth(), getHeight() - obj.height);
return temp;
}
boxType boxType::operator*(const boxType & obj)
{
boxType temp(getLength() * obj.getLength(), getWidth()
* obj.getWidth(), obj.height * getHeight());
return temp;
}
boxType boxType::operator++()
{
rectangleType::operator++();
++height;
return boxType(getLength(), getWidth(),height);
}
boxType boxType::operator++(int)
{
boxType temp;
rectangleType::operator++(0);
temp.height = height++;
return temp;
}
boxType boxType::operator--()
{
rectangleType::operator--();
--height;
return boxType(getLength(), getWidth(), height);
}
boxType boxType::operator--(int)
{
boxType temp;
rectangleType::operator--(0);
temp.height = height--;
return temp;
}
bool boxType::operator==(const boxType & a)
{
return volume() == a.volume();
}
bool boxType::operator!=(const boxType & a)
{
return volume() != a.volume();
}
bool boxType::operator<=(const boxType & a)
{
return volume() <= a.volume();
}
bool boxType::operator<(const boxType & a)
{
return volume() < a.volume();
}
bool boxType::operator>=(const boxType & a)
{
return volume() >= a.volume();
}
bool boxType::operator>(const boxType & a)
{
return volume() > a.volume();
}
ostream & operator << (ostream &out, const boxType
&obj)
{
cout << "Length: " << obj.getLength()
<< " Width: " << obj.getWidth() << " Height: "
<< obj.getHeight();
return out;
}
istream & operator >> (istream &in, boxType
&obj)
{
return in;
}
//boxType.h
#pragma once
#include "rectangleType.h"
#include<iostream>
using namespace std;
class boxType :
public rectangleType
{
public:
boxType();
boxType(double l, double w, double h);
~boxType();
double getHeight() const;
void setDimension(double l, double w, double h);
double volume() const;
boxType operator+(const boxType& obj);
boxType operator-(const boxType& obj);
boxType operator*(const boxType& obj);
boxType operator++();
boxType operator++(int);
boxType operator--();
boxType operator--(int);
bool operator==(const boxType& a);
bool operator!=(const boxType& a);
bool operator<=(const boxType& a);
bool operator<(const boxType& a);
bool operator>=(const boxType& a);
bool operator>(const boxType& a);
friend ostream & operator << (ostream
&out, const boxType &obj);
friend istream & operator >> (istream
&in, boxType &obj);
private:
double height;
};
//Main.cpp
#include<iostream>
using namespace std;
#include "boxType.h"
int main()
{
boxType box1(12, 9, 6);
boxType box2(8, 7, 5);
boxType box3, box4, box5;
cout << "box1: " << box1 <<
endl;
cout << "box2: " << box2 <<
endl;
box3 = box1 + box2;
cout << "box3: " << box3 <<
endl;
box4 = box1 - box2;
cout << "box4: " << box4 <<
endl;
box5 = box1 * box2;
cout << "box5: " << box5 <<
endl;
if (box1 > box2)
cout << "Volume of box1 is
greater than the volume of box2." << endl;
else
cout << "Volume of box1 is
less than or equal to the volume of box2." << endl;
box1++;
cout << "After increment the length, width, and
height of "
<< "box1 by one unit, \nbox1:
"
<< box1 <<
endl;
box3 = ++box2;
cout << "New dimension of box2: " << box2
<< endl;
cout << "New dimension of box3: " << box3
<< endl;
return 0;
}
//sample output
This Program should run in C++ In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we will expand on our in-class exercise of developing the rectangleTyp...
In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we will expand on our in-class exercise of developing the rectangleType class and overload the following operators: +, -, *, ++, --, ==, !=, >>, and <<. Your program should contain the following features: a. Create a base class named rectangleType with following private data members: • length with double type • width with double type b. rectangleType class should contain the following functions: •...
Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...
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++ program. int main() { Rectangle box; // Define an instance of the Rectangle class double rectWidth; // Local variable for width double rectLength; // Local variable for length string rectColor; // Get the rectangle's width and length from the user. cout << "This program will calculate the area of a\n"; cout << "rectangle. What is the width? "; cin >> rectWidth; cout << "What is the length? "; cin >>...
please use c++ Write a program that contains a class Rectangle with two private double precision members iLength and iWidth, public set and get member functions for these two members, a two argument constructor that sets the length and width to any two user specified values and a void function area() that computes the area and then prints this value by inserting it into the cout output stream. Write a main function that ereates a Rectangle with a length of...
c++ Part 1 Consider using the following Card class as a base class to implement a hierarchy of related classes: class Card { public: Card(); Card (string n) ; virtual bool is_expired() const; virtual void print () const; private: string name; Card:: Card() name = ""; Card: :Card (string n) { name = n; Card::is_expired() return false; } Write definitions for each of the following derived classes. Derived Class Data IDcard ID number CallingCard Card number, PIN Driverlicense Expiration date...
I need help solving this basic C++ question. I need help fixing my code. Question: Design a class called a box that represents a box. Box classes have variables such as the length of the box, width, and height. 1. Member variables shall be dedicated members. 2. Define the creator of the Box Class. The creator may receive all of the data and may not receive any. 3. Add accessor and creator 4. Add an empty function, which indicates whether...
Write a C# application that implements a class ‘Prism’ with the following members. Five private data members ‘length’, ‘height’, ‘width’, ‘Volume’ and ‘Area’ of double data type. Implement the constructor Prism( ) to accept the length, height, and width of the rectangular prism from the user. Implement three methods, Vol(), Area(), and Result() Vol() – to calculate the volume of the prism using the formulae Volume= length ×height ×width Area() – to calculate the surface area of the prism using...
In a c++ program, Implement a Pyramid class with base and height as data members and surface area() and volume() calculations as member functions.
Creating a Class in C++ Summary In this lab, you create a programmer-defined class and then use it in a C++ program. The program should create two Rectangle objects and find their area and perimeter. Instructions Ensure the class file named Rectangle.cpp is open in your editor. In the Rectangle class, create two private attributes named length and width. Bothlength and width should be data type double. Write public set methods to set the values for lengthand width. Write public...