Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ PROGRAMMING This program is much easier than it looks I just really need help Please make sure the code compiles and works so I

C++ PROGRAMMING

This program is much easier than it looks I just really need help

Please make sure the code compiles and works so I can give you 5 stars :-)

PART 1:

The product of this question will be the kernel of the second, before starting read through the totality of the assignment. You will begin by defining two classes, Rectangle and Triangle. Their declarations are given below.

class Rectangle { public: Rectangle (float length = 0, float width = 0); void set(float length, float width); void get(float &length, float &width); string getType(); // Returns RECTANGLE float area(); private: float len, wid; }; class Triangle { public: Triangle(float base = 0, float height = 0); void set(float base, float height); void get(float &base, float &height); string getType(); // Returns TRIANGLE float area(); private: float b, h; };

Provide the definitions for both classes as Rectangle.cpp and Triangle.cpp.

You will then write a main.cpp program that produces the following input based on the input provided by the user. Enter the base and height for a triangle: 3 4 Enter the length and width for a rectangle: 2 3 Area of a RECTANGLE is 6 Area of a RIGHT TRIANGLE is 6 The two objects are of equal area Press any key to continue . . .

However, the main program must define two functions that use templated class types C and D. /* * Produces the output: * Area of a is */ void display(C obj); /* * Returns true if the area of obj1 and obj2 are equal, * false otherwise. */ bool equalArea(C obj1, D obj2);

These two functions must be used in the main program when producing the output above. Submit this question separately (without the content from part 2).

Part 2:

For Part 2, you will extend the Rectangle and Triangle classes with a templated method that calculates the maximum number of other objects that will fit within the same area. For example, if the area of a Rectangle I is 18 and the area of a triangle t is 3, then r.maxFill(t) will return 6.

The following method declaration needs to be added to both the Rectangle and Triangle classes, the token C is the templated class type

/* * Returns the maximum number of other objects that would fit * into the area of this object. */ float maxFill(C &other);

Add the declaration to Rectangle.h and Triangle.h and provide definitions for the method. Then modify the main program to produce the following output.

Enter the base and height for a triangle: 2 3 Enter the length and width for a rectangle: 4 3 Area of a RECTANGLE is 12 Area of a RIGHT TRIANGLE is 3 The two objects are of unequal area There are 4 triangles that will fit in the rectangle There are 0.25 rectangles that will fit in the triangle There are 1 rectangles that will fit into the rectangle Press any key to continue . . .

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_2

Step: 3

blur-text-image_3

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

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions