Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Racer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//Racer Class
#include<string>
#include<array>
#include<iostream>
#include<iomanip>
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
120 changes: 120 additions & 0 deletions Racer_Driver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//Racer Driver file
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>//for "exit()" on some systems

using namespace std;

#include "Racer.h"

void fillVector(vector<Racer>&);
void printVector(const vector<Racer>&);
void printVector2(const vector<Racer>&); //Need help to understand this.
int linearSearch(vector<Racer>& data, auto key);//function prototype for linear search.


int main()
{
string search_key, input;
int result;
vector<Racer> 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<<endl<<"To end input type the #-character (followed by Enter)"<<endl<<endl;
cout<<"Enter a value to search for: ";
cin>>search_key;


while(search_key != "#")//perform searches until sentinel entered
{
result = linearSearch(racerArray,search_key);

cout<<" '"<<search_key<<"' was ";

if (result == -1)
cout<<"not found";
else
cout<<"found at index "<<result;


cout<<endl<<endl<<"Enter a value to search for: ";
cin>>search_key;
}

//printVector2(racerArray);

system("pause");

return 0;

}

void fillVector(vector<Racer>& 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<Racer>& 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<Racer>& newprintRacer)
{
unsigned int vectorSize = newprintRacer.size();

for (unsigned int i = 0; i < vectorSize; i++)
{
newprintRacer[i].displayInfo();
}

}

int linearSearch(vector<Racer>& data, auto key)
{
for (int i = 0; i < data.size(); i++)
{
if (data[i].getRacerName() == key)
{
return i;
}
}
return -1;

}

52 changes: 52 additions & 0 deletions Racer_Imp.cpp
Original file line number Diff line number Diff line change
@@ -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;
}