diff --git a/Racer.h b/Racer.h new file mode 100644 index 0000000..2c1fd80 --- /dev/null +++ b/Racer.h @@ -0,0 +1,43 @@ +//Racer Class +#include +#include +#include +#include +using namespace std; + +#ifndef RACER_H +#define RACER_H + +//Racer class definition +class Racer +{ + +public: + //default constructor initializing Racer's names and Racer's Category + Racer(); + + //Overload constructor + Racer(string name, int category); + + //function to set the Racer name + void setRacerName(string name); + + //function to set the Racer's Category + void setRacerCategory(int category); + + //function to display information + void displayInfo() const; + + //function to retrieve the Racer's name + string getRacerName() const; + + //function to retrieve the Racer's Category + int getracerCategory() const; + +private: + string racerName; + int racerCategory; + +}; + +#endif diff --git a/Racer_Driver.cpp b/Racer_Driver.cpp new file mode 100644 index 0000000..806dd70 --- /dev/null +++ b/Racer_Driver.cpp @@ -0,0 +1,120 @@ +//Racer Driver file +#include +#include +#include +#include +#include +#include //for "exit()" on some systems + +using namespace std; + +#include "Racer.h" + +void fillVector(vector&); +void printVector(const vector&); +void printVector2(const vector&); //Need help to understand this. +int linearSearch(vector& data, auto key);//function prototype for linear search. + + +int main() +{ + string search_key, input; + int result; + vector racerArray; + + fillVector(racerArray); + + + // Implemented the linear function search from the algos lab. + // Comment out from here to "printVector2" to gain back the orginal + //implementation of this program. + + //Added a linear search algorithm; which searches the vector once filled for matching + //Racer's names, and returns the index of the name. + + cout<>search_key; + + + while(search_key != "#")//perform searches until sentinel entered + { + result = linearSearch(racerArray,search_key); + + cout<<" '"<>search_key; + } + + //printVector2(racerArray); + + system("pause"); + + return 0; + +} + +void fillVector(vector& newRacerArray) +{ + for (int x = 0; x < 4; x++) + { + int category; + string name; + cout << "Enter the Bike racer's name: "; + getline(cin, name); + + cout << "\nEnter the Bike racer's Category Level:"; + cin >> category; + cin.ignore(); + + Racer newRacer(name, category); + newRacerArray.push_back(newRacer); + cout << endl; + } + cout << endl; +} + +void printVector(const vector& newprintRacer) +{ + unsigned int vectorSize = newprintRacer.size(); + + for (unsigned int i = 0; i < vectorSize; i++) + { + cout << "Rider's name: " << newprintRacer[i].getRacerName() << endl; + cout << "Rider's category: " << newprintRacer[i].getracerCategory() << endl; + cout << endl; + } + +} + +void printVector2(const vector& newprintRacer) +{ + unsigned int vectorSize = newprintRacer.size(); + + for (unsigned int i = 0; i < vectorSize; i++) + { + newprintRacer[i].displayInfo(); + } + +} + +int linearSearch(vector& data, auto key) +{ + for (int i = 0; i < data.size(); i++) + { + if (data[i].getRacerName() == key) + { + return i; + } + } + return -1; + +} + diff --git a/Racer_Imp.cpp b/Racer_Imp.cpp new file mode 100644 index 0000000..153b0dc --- /dev/null +++ b/Racer_Imp.cpp @@ -0,0 +1,52 @@ +//Racer Class Implementation + +#include "Racer.h" + +using namespace std; + +//constructor +Racer::Racer() + { + racerName = " "; + racerCategory = 0; +} + +//Overload Constructors +Racer::Racer(string name, int category) +{ + racerName = name; + racerCategory = category; +} + +//set the Racer name +void Racer::setRacerName(string name) +{ + racerName = name; +} + +//retrieve the Racer name +string Racer::getRacerName() const +{ + return racerName; +} + +//set the Racer Category +void Racer::setRacerCategory(int category) +{ + racerCategory = category; +} + +//retrieve the Racer Category +int Racer::getracerCategory() const +{ + return racerCategory; +} + +//displays all of the Racer object's data +void Racer::displayInfo() const +{ + cout << "**** Rider's Name and Category ****" << endl; + cout << "Name: " << racerName << endl; + cout << "Category: " << racerCategory << endl; + cout << " *******************" << endl; +}