Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a 2D rectangle class called Rect. You are intended to use your Vec class from the previous exercise. Your class Rect must contain the

Design a 2D rectangle class called Rect. You are intended to use your Vec class from the previous exercise.

Your class Rect must contain the following: - 4 floats to represent the rectangle, where two are the coordinates (x,y) of the upper-left corner of the rectangle, and the other two are the dimensions (width and height) of the rectangle - at least one constructor that receives the four floats defining the rectangle - a method called "contains" which receives a Vec as parameter and returns true if the Vec is inside the rectangle, and false if the Vec is outside the rectangle

Your Rect class should allow the rectangles.cpp file to run without generating any error messages.

NOTE: Because the (x,y) coordinates specify the UPPER-LEFT corner of the rectangle, the rectangle's "height" actually goes down!

rectangles.cpp

#include

#include "Rect.h"

using namespace std;

Vec nullvec( 0.0f, 0.0f );

int main( int argc, const char* argv[] )

{

Rect a( -1.0f, 1.0f, 3.0f, 4.0f );

Rect b( -5.0f, -5.0f, 2.0f, 2.0f );

Rect c( 5.0f, 8.0f, 2.0f, 2.0f );

if( a.contains( nullvec ) == true ) cout << "Test 1 passed! ";

else cout << "error1 ";

if( b.contains( nullvec ) == false ) cout << "Test 2 passed! ";

else cout << "error2 ";

if( c.contains( nullvec ) == false ) cout << "Test 3 passed! ";

else cout << "error3 ";

if( a.contains( Vec( 0.0f, 3.0f ) ) == false ) cout << "Test 4 passed! ";

else cout << "error4 ";

if( b.contains( Vec( -4.0f, -6.0f ) ) == true ) cout << "Test 5 passed! ";

else cout << "error5 ";

if( c.contains( Vec( 6.0f, 9.0f ) ) == false ) cout << "Test 6 passed! ";

else cout << "error6 ";

cout << "Finished! ";

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

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago