CSCI 2421Data Structures Assignment 2

$35.00 $17.50

Download Details:

  • Name: Homework-Assignment-2-34hidk.zip
  • Type: zip
  • Size: 4.32 KB

Category:

Description

5/5 - (1 vote)

Define a Rectangle class that provides getLength and getWidth. Using the findMax routine given below, write a main that creates an array of Rectangle and finds the largest Rectangle first on the basis of area and then on the basis of perimeter.

#include <iostream>
#include <vector>
#include <string>
#include <strings.h>
using namespace std;

// Generic findMax, with a function object, C++ style.
// Precondition: a.size( ) > 0.
template <typename Object, typename Comparator>
const Object & findMax( const vector<Object> & arr, Comparator isLessThan )
{
int maxIndex = 0;

for( int i = 1; i < arr.size( ); ++i )
if( isLessThan( arr[ maxIndex ], arr[ i ] ) )
maxIndex = i;

return arr[ maxIndex ];
}