Given main:
#include <iostream>
using namespace std;
#include <stdlib.h>
#include "minivector.h"
#include "bubbleSort.h"
#include "Fraction.h"
int main()
{
int arr[]={99, 12, 50, 80, 1, 79, 20};
cout << endl << "bubbleSort ints" << endl;
bubbleSort(arr, 7);
for (int i=0; i < 7; i++)
cout << arr[i]<< endl;
double arr2[]={99.2, 12.9, 50.5, 80.7, 1.8, 79.0, 20.3};
cout << endl<< "bubbleSort doubles" << endl;
bubbleSort(arr2, 7);
for (int i=0; i < 7; i++)
cout << arr2[i]<< endl;
Fraction arr3[]={Fraction(1,2), Fraction(1,3), Fraction(1,4),
Fraction(5,6), Fraction(3,4), Fraction(7,3),
Fraction(9,4)};
cout << endl<< "bubbleSort Fractions" << endl;
bubbleSort(arr3, 7);
for (int i=0; i < 7; i++)
cout << arr3[i]<< endl;
cout << endl<< endl<< "miniVector sutff"<< endl;
miniVector<Fraction> varr;
varr.push_back(Fraction(12,14));
varr.push_back(Fraction(5,7));
varr.push_back(Fraction(2,5));
varr.push_back(Fraction(1,6));
varr.push_back(Fraction(3,7));
bubbleSort(varr);
for (int i=0; i < varr.size(); i++)
cout << varr[i] << endl;
return 0;
}
Given miniVector.h:
#ifndef MINI_VECTOR
#define MINI_VECTOR
template <typename T>
class miniVector
{
public:
miniVector(int size = 0);
// constructor.
// Postconditions: allocates array with size number of elements
// and capacity. elements are initialized to T(), the default
// value for type T
miniVector(const miniVector<T>& obj);
// copy constructor
// Postcondition: creates current vector as a copy of obj
~miniVector();
// destructor
// Postcondition: the dynamic array is destroyed
miniVector& operator= (const miniVector<T>& rhs);
// assignment operator.
// Postcondition: current vector holds the same data
// as rhs
T& back();
// return the element at the rear of the vector.
// Precondition: the vector is not empty. if vector
// is empty, throws the underflowError exception
T& operator[] (int i);
// provides general access to elements using an index.
// Precondition: 0 <= i < vSize. if the index is out
// of range, throws the indexRangeError exception
void push_back(const T& item);
// insert item at the rear of the vector.
// Postcondition: the vector size is increased by 1
int size() const;
// return current list size
bool empty() const;
// return true if vector is empty and false otherwise
int capacity() const;
// return the current capacity of the vector
private:
int vCapacity; // amount of available space
int vSize; // number of elements in the list
T *vArr; // the dynamic array
void reserve(int n);
// called by public functions only if n > vCapacity. expands
// the vector capacity to n elements, copies the existing
// elements to the new space
};
#endif // MINI_VECTOR
I need to create a bubbleSort.h and Fraction.h
So far, everything I've tried is garbage! lol
My attempt at somewhat of a Fraction.h:
class Fraction
{
int num;
int denom;
public:
Fraction(): num(1), denom(1)
{}
Fraction(int n, int d): num(n), denom(d)
{}
Fraction add(const Fraction & op) const;
Fraction subtract(const Fraction & op) const;
Fraction multiply(const Fraction & op) const;
Fraction divide(const Fraction & op) const;
bool operator < (Fraction &f);
void reduce();
void display(const char * label) const;
void readin(const char * label);
friend ostream& operator << (ostream &s, Fraction &f);
};
And my attempt at bubbleSort.h:
//bubbleSort header for HW
template <typename T>
class bubbleSort
{
public:
//bubbleSort(int &arr, int num); //DO I NEED THIS ALSO?!?
bubbleSort(miniVector<T> &arr, int []);
};
template <typename T>
void bubbleSort(miniVector<T> &arr, int [])
{
int smallIndex; // index of smallest element in the sublist
int pass, j;
T temp;
int n = arr.size();
// pass has the range 0 to n-2
for (pass = 0; pass < n-1; pass++)
{
// scan the sublist starting at index pass
smallIndex = pass;
// j traverses the sublist arr[pass+1] to arr[n-1]
for (j = pass+1; j < n; j++)
// update if smaller element found
if (arr[j] < arr[smallIndex])
smallIndex = j;
// if smallIndex and pass are not the same location,
// exchange the smallest item in the sublist with arr[pass]
if (smallIndex != pass)
{
temp = arr[pass];
arr[pass] = arr[smallIndex];
arr[smallIndex] = temp;
}
}
}
HELP PLEASE!!?