Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include "rectangle.h" using namespace std; int main()

{ 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 "<getWidth()<getLength()<getArea()<

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions