Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm spending too much time debugging this C++ lab and I'm not sure if I'm even approaching this correctly, please help me with a baseline

I'm spending too much time debugging this C++ lab and I'm not sure if I'm even approaching this correctly, please help me with a baseline example.

Assignment objectives

In this assignment, you are going to implement a relatively simple Rectangle class that is split into a header file and an implementation file. You will also create an abstract base class (interface) that defines the public interface for your class.

Note that you will not use a class template for this assignment. But you will use an abstract class with inheritance.

Assignment Details

Create a class called Rectangle to represent a rectangle. You will also write a small driver program to test your class. DO NOT CREATE A CLASS TEMPLATE. For this assignment, we will just create a class.

Rectangle Class Members

Your class should have private data fields (member variables or data members) of type double to represent the length and width of the rectangle.

Your class should have the following public methods (member functions):

A default (no argument) constructor that sets initializes the length and width of the rectangle to 1.0..

A method called set that allows the client to update the rectangle's length and width. This method will have two parameters that allow the client to provide new values for the length and width. This method has a prerequisite - the new values provided for the length and width must both be larger than 0.0. If they are both larger than zero, the Rectangle object will be updated and the method will return true. Otherwise, the object will not be updated and the method will return false.

A constant method called getLength that returns the length of the rectangle.

A constant method called getWidth that returns the width of the rectangle.

A constant method called getArea that returns the area of the rectangle. The area of a rectangle is the length times the width.

Your method prototypes should be:

Rectangle();

bool set( double newLength, double newWidth );

double getLength() const;

double getWidth() const;

double getArea() const;

If you have not used inheritance and/or abstract classes before, you may want to implement and test your class before you continue to the next step. You must keep your test code separate from your class code, and you must put class definition in a class header file and the implementations for the class methods in a class implementation file.

Rectangle Interface File

Create an interface file for your Rectangle class

It is important to note:

Constructor methods are not included in the abstract class.

You must include a virtual destructor for the abstract class with an empty implementation (see the examples).

Include documentation in your interface file similar to the documentation (comments) in the examples.

Debugging and Testing Tips

If you see linker error messages like: Undefined reference to vtable ...

undefined reference to 'interface-destructor-method'

you have a problem with the destructor in the interface file. Check again that this destructor matches the destructors in the example programs. Also, you may have to delete the object (.o) files in your project folder before you try to compile and link your changes.

When you are testing a method that contains an if statement, be sure that you try calling the method with data that will make the condition of the if statement true, and also with data that will make the condition false.

Requirements:

Your program must be split into 4 files: the driver program, the class interface, the class header file (class definition), and class implementation file.

2.Your class methods should not contain any input or output operations. All input and output should be done in your driver.

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

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions