Question
With the class (Soccer) and the given SimpleVector class, make a new class called SortableVector which will sort an array of the object Soccer via
With the class (Soccer) and the given SimpleVector class, make a new class called SortableVector which will sort an array of the object Soccer via the number of points scored by the players or by the number of the players.
//Please follow a similair template for SortableVector
//SortableVector_h
#include "SimpleVector.h"
template
//Constructor SortableVector(int size) :SimpleVector
//Copy SortableVector(const SortableVector&); //Accessor void SelectionSort(); };
//Copy Constructor template
this->operator[](count) = obj[count]; }
//template
for (startScan = 0; startScan < (this->getSize() - 1); startScan++) { minIndex = startScan; minValue = array[startScan]; for (int index = startScan + 1; index < this->getSize(); index++) { if (array[index] < minValue) { minValue = array[index]; minIndex = index; } } array[minIndex] = array[startScan]; array[startScan] = minValue; } } */
//SimpleVector_h
#ifndef SimpleVector_h #define SimpleVector_h // SimpleVector class template #include
template
// Constructor declaration SimpleVector(int); // Copy constructor declaration SimpleVector(const SimpleVector&); // Destructor declaration ~SimpleVector(); // Accessor to return the array size int getSize() const { return arraySize; }
// Accessor to return a specific element T getElementAt(int position);
// Overloaded [] operator declaration T& operator[](const int&);
void setValue(T value, int index); }; template
// Initialize the array. //for (int count = 0; count < arraySize; count++) // *(aptr + count) = 0; }
//******************************************* // Copy Constructor for SimpleVector class. * //*******************************************
template
// Allocate memory for the array. aptr = new T[arraySize]; if (aptr == 0) memError(); // Copy the elements of obj's array. for (int count = 0; count < arraySize; count++) *(aptr + count) = *(obj.aptr + count); }
//************************************** // Destructor for SimpleVector class. * //**************************************
template
//******************************************************** // memError function. Displays an error message and * // terminates the program when memory allocation fails. * //********************************************************
template
//************************************************************ // subError function. Displays an error message and * // terminates the program when a subscript is out of range. * //************************************************************
template
//******************************************************* // getElementAt function. The argument is a subscript. * // This function returns the value stored at the * // subcript in the array. * //*******************************************************
template
//******************************************************** // Overloaded [] operator. The argument is a subscript. * // This function returns a reference to the element * // in the array indexed by the subscript. * //********************************************************
template
template
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////
///Soccer_h
#include
Soccer::Soccer() : name(temp2), number(0), points(0) { int number = 10; int points = 30; } Soccer::Soccer(string aName, int aNumber, int p) : name(aName), number(aNumber), points(p) { setNumber(30); setPoints(20); } Soccer::Soccer(const Soccer& obj) : name(obj.name), number(obj.number), points(obj.points) { }
Soccer::~Soccer() {
}
void Soccer::setName(string aName) { name = aName; }
void Soccer::setNumber(int aNumber) { number = aNumber; }
void Soccer::setPoints(int p) { points = p; }
string Soccer::getName() const { return this->name; }
int Soccer::getNumber() const { return this->number; }
int Soccer::getPoints() const { return this->points; }
Soccer& Soccer::operator=(const Soccer& obj) { this->name = obj.getName(); this->number = obj.getNumber(); this->points = obj.getPoints(); return *this; }
Soccer& Soccer::operator[](const Soccer& obj) { this->name = obj.getName(); this->number = obj.getNumber(); this->points = obj.getPoints(); return *this; }
ostream& operator<<(ostream& output, const Soccer& obj) { output << "Player's name: " << obj.name << endl; output << "Player's number: " << obj.number << endl; output << "Player's scored points: " << obj.points << endl; return output; }
istream& operator>>(istream& input, Soccer& obj) { cin.ignore(); cout << "Nombre: "; input >> obj.name; cout << "Numero: "; input >> obj.number; cout << "Puntos acumulados: "; input >> obj.points; return input; }
///////////////////////////////////////////////////////////////////////////////////////////
//main.cpp
#include "Soccer.h" #include
int main()
{
int size;
cin >> size;
SortableVector
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started