Question
Hello I have a question. I would like to check if the code follows this requirement. Rectangle.h - A complete Rectangle Class including both declaration
Hello I have a question. I would like to check if the code follows this requirement.
Rectangle.h - A complete Rectangle Class including both declaration and definition
appRectangle,cpp
separate in two different files the class definition and implementation
Code:
rectangle.h
// Rectangle class declaration.
class Rectangle
{
private:
double width;
double length;
public:
void setWidth(double);
void setLength(double);
double getWidth() const;
double getLength() const;
double getArea() const;
};
//**************************************************
// setWidth assigns a value to the width member. *
//**************************************************
void Rectangle::setWidth(double w)
{
width = w;
}
//**************************************************
// setLength assigns a value to the length member. *
//**************************************************
void Rectangle::setLength(double len)
{
length = len;
}
//**************************************************
// getWidth returns the value in the width member. *
//**************************************************
double Rectangle::getWidth() const
{
return width;
}
//****************************************************
// getLength returns the value in the length member. *
//****************************************************
double Rectangle::getLength() const
{
return length;
}
//*****************************************************
// getArea returns the product of width times length. *
//*****************************************************
double Rectangle::getArea() const
{
return width * length;
}
rectangle.cpp
#include
{ Rectangle *rec=new Rectangle();
double width,length; cout<<"This program will calculate the area of a reactangle."; cout << " What is the width? ";
cin >> width; // Get the width
cout << "What is the length? ";
cin >> length; // Get the length
rec->setLength(length); rec->setWidth(width); cout << "here is rectangle's data "; cout<<"width "< return 0; }
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