Quote
#include <iostream>
#include <ctime> // for random
using namespace std;
#include "rect.h"
int random(int min, int max);
template<class T>
void _sort(T * a, int n);
// **** additional functions ****
const int ARR_SIZE = 10;
int main()
{
rect arr[ARR_SIZE]; // initialize this array of pointers
for (int i = 0; i < ARR_SIZE; i++)
{
arr[ I ].set(random(1, 200), random(1, 200));
}
cout << "Current array contents: " << endl;
for (int i = 0; i < ARR_SIZE; i++)
{
cout << "arr[" << i << "] area = " << arr[ I ].area() << endl;
}
_sort(arr, ARR_SIZE);
cout << "Sorted array contents: " << endl;
for (int i = 0; i < ARR_SIZE; i++)
{
cout << "arr[" << i << "] area = " << arr[ I ].area() << endl;
}
return 0;
}
int random(int min, int max)
{
static bool ft = true;
if (ft)
{
srand((unsigned int)time(0));
ft = false;
}
return (rand() % (max - min + 1)) + min;
}
template<class T>
void _sort(T * a, int n)
{
int rh, lh, i = 0;
for (lh = 0; lh < n; lh++)
{
if (a[lh] < a[rh])
{
lh = i;
}
swap(a[lh], a[rh]);
}
}
void swap(int a, int b)
{
int temp = a;
int a = b;
int b = temp;
}
header file
Quote
#ifndef _RECT_H_
#define _RECT_H_
class rect {
private:
double _height;
double _width;
public:
rect() : _height(0), _width(0)
{
}
rect(int width, int height) : _height(height), _width(width)
{
}
void set(double width, double height)
{
_height = height;
_width = width;
}
double height() const
{
return _height;
}
double width() const
{
return _width;
}
double area() const
{
return _height * _width;
}
// ***** additional functions *****
};
#endif
error c2082 redefinition of formal paramater a/b
any help appreciated
This post was edited by Darnderin on Dec 7 2016 06:38pm