Question: MY DATA IS NOT DISPLAYING ON MY CODE!!! Here is my code; #include #include #include #include using namespace std; struct Result { int bibNumber; string

MY DATA IS NOT DISPLAYING ON MY CODE!!!

Here is my code;

#include

#include

#include

#include

using namespace std;

struct Result {

int bibNumber;

string name;

double distance;

string time;

};

void readDataset(ifstream& in, Result results[], int &size);

void displayDataset(Result results[], int size);

int linearSearchByName(Result results[], int size, string name);

int binarySearchByNumber(Result results[], int size, int Number);

void sortByNumber(Result results[], int size);

void sortByDistanceTime(Result results[], int size);

void displayMenu();

int main() {

Result results[100];

int size = 0;

string filename;

int choice;

cout <<

"Menu";

cin >> filename;

ifstream in;

in.open(filename);

if (!in) {

cout << "Error: File could not be opened." << endl;

return 1;

}

readDataset(in, results, size);

do {

displayMenu();

cin >> choice;

switch(choice) {

case 1:

sortByNumber(results, size);

displayDataset(results, size);

break;

case 2:

sortByDistanceTime(results, size);

displayDataset(results, size);

break;

case 3: {

string Name;

cout << "Enter the name: ";

cin.ignore();

getline(cin, Name);

int index = linearSearchByName(results, size, Name);

if (index == -1) {

cout << "Racer not found." << endl;

} else {

cout << "Bib number: " << results[index].bibNumber << endl;

}

break;

}

case 4: {

int Number;

cout << "Enter the bib number: ";

cin >> Number;

int index = binarySearchByNumber(results, size, Number);

if (index == -1) {

cout << "Racer not found." << endl;

} else {

cout << "Bib number: " << results[index].bibNumber << endl;

cout << "Name: " << results[index].name << endl;

cout << "Distance: " << results[index].distance << endl;

cout << "Time: " << results[index].time << endl;

}

break;

}

case 5:

cout << "Exiting the program..." << endl;

break;

default:

cout << "Please, enter 1, 2, 3, 4 or 5:" << endl;

}

} while (choice != 5);

return 0;

}

void readDataset(ifstream& in, Result results[], int &size) {

while (in >> results[size].bibNumber) {

in.ignore();

getline(in, results[size].name);

in >> results[size].distance;

in >> results[size].time;

size++;

}

}

void displayDataset(Result results[], int size) {

cout << " Bib Number" << '\t' << "Name" << '\t'<< '\t' << "Distance" << '\t' << "Time" << endl;

for (int i = 0; i < size; i++) {

cout << results[i].bibNumber << '\t' << results[i].name << '\t' << results[i].distance << '\t'<< '\t' << results[i].time << endl;

}

cout << endl;

}

int linearSearchByName(Result results[], int size, string Name) {

for (int i = 0; i < size; i++) {

if (results[i].name == Name) {

return i;

}

}

return -1;

}

int binarySearchByNumber(Result results[], int size, int Number) {

int left = 0;

int right = size - 1;

while (left <= right) {

int mid = (left + right) / 2;

if (results[mid].bibNumber == Number) {

return mid;

} else if (results[mid].bibNumber < Number) {

left = mid + 1;

} else {

right = mid - 1;

}

}

return -1;

}

void sortByNumber(Result results[], int size) {

for (int i = 0; i < size - 1; i++) {

for (int j = 0; j < size - i - 1; j++) {

if (results[j].bibNumber > results[j + 1].bibNumber) {

Result temp = results[j];

results[j] = results[j + 1];

results[j + 1] = temp;

}

}

}

}

void sortByDistanceTime(Result results[], int size) {

for (int i = 0; i < size - 1; i++) {

for (int j = 0; j < size - i - 1; j++) {

if (results[j].distance > results[j + 1].distance) {

Result temp = results[j];

results[j] = results[j + 1];

results[j + 1] = temp;

} else if (results[j].distance == results[j + 1].distance) {

if (results[j].time > results[j + 1].time) {

Result temp = results[j];

results[j] = results[j + 1];

results[j + 1] = temp;

}

}

}

}

}

void displayMenu() {

cout << endl;

cout << "1. Display Results Sorted by bib number" << endl;

cout << "2. Display Results sorted by distance, then time" << endl;

cout << "3. Lookup a bib number given a name" << endl;

cout << "4. Lookup a result by bib number" << endl;

cout << "5. Quit the program" << endl;

cout << "Enter your choice:";

}

whenever I run it though, the display list is blank.

HELP!!

EXPECTED OUTPUT :

10 John Smith 122.0 05:40:52

12 Julio Garza 97.6 05:35:00

15 Tom Stanford 91.5 05:36:07

20 Gary Benson 115.9 05:50:40

22 David Warner 109.8 05:48:02

25 David Myers 103.7 05:53:16

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!