Write a friend function to compare the area of a rectangle


Re-combine the three files from the last assignment into one file (so it will be easier to submit and to grade). Add a child class called Parallelogram which has two more private member-variables, one for the acute angle in degrees, and the other for area. Write two constructors, one a default constructor that initializes the acute angle in the parallelogram to be 60 degrees; and the other to pass in an argument for the acute angle in the parallelogram. Write an accessor function to get the angle. Write a member-function that calculates the parallelogram's area.

Write a friend function to compare the area of a rectangle with sides 12 and 8 to the area of a parallelogram with sides 14 and 18 and an acute angle of 40 degrees. Test it in main, and check the answer by hand.

Write a main program to test these functions.

HII\ TS: Set the side lengths and the angle in constructors. Depending on whether you use the inherited constructor, you may have to refer to the handout that had the 4-combinations-of¬constructors. When you want to compare areas, use a friend function to get at that data, and you will probably have to list the friend function in BOTH classes, since you want the Quadrilateral's private data and also the Parallelogram's private data. Then that means you will need to put a "forward reference" at the beginning of your program. Here's how to put in a forward reference: on the next line after using namespace std; you just type class Parallelogram; and that's just before you start the definition of class Quadrilateral. Then later on you have your usual definition of the class Parallelogram with all the listing of its member-functions and member-variables.

(The reason for the forward reference is so you can say, in the friend function's arguments, that you have a variable of type Parallelogram and your program will recognize it is a variable type to-be-defined soon.)

 

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Write a friend function to compare the area of a rectangle
Reference No:- TGS0655454

Now Priced at $40 (50% Discount)

Recommended (92%)

Rated (4.4/5)