CSCI 261 - Programming Concepts - Spring 2022

Lab 5E - Procedural and Object-Oriented

This lab is due by Wednesday, April 13, 2022 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.


Instructions


For this lab, we will continue to make our sorting more flexible.

Begin by creating a Rectangle class. The class will need data members to store the base and height (as floats) plus the appropriate getters/setters for each. Have the constructor set each to be 1 by default.

We will want to be able to compare two Rectangles as well. Overload the < and > operators. These operators are resolved as follows:

Make a list of Rectangles (array or LinkedList). Now modify one of your previous sort methods (selection, insertion, bubble, merge) to accept a function pointer for how to do the comparison when sorting. Create an ascending function and a descending function that can be used as the comparing function.

To test your implementations, perform the following steps:

  1. Ask the user how many Rectangles to create
  2. Create a list of n Rectangles
  3. Assign each a random base and height
  4. Print the list forwards (print the rectangle as basexheight)
  5. Sort the list ascending
  6. Print the list forwards (print the rectangle as basexheight)
  7. Sort the list descending
  8. Print the list forwards (print the rectangle as basexheight)

Lab Submission


Submit your main.cpp, Makefile, *.hpp, *.h, *.cpp file(s).

You will submit your solution to this lab with the rest of Set5. Detailed instructions for doing this are posted in Assignment 5.


This lab is due by Wednesday, April 13, 2022 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.