Question: I'm trying to solve this problem and I having hard time I can make a bubble sort, but I don't know about the pointer part...

I'm trying to solve this problem and I having hard time I can make a bubble sort, but I don't know about the pointer part... can you show me in my code?

Problem:

Modify Lab 2 Part I by adding sort options.

Add menu options to sort by various fields: first name, last name, gpa, id , and email.

Write one function, that can sort by any field using array of pointers. Do not copy and paste sort code five times into the same function. Tip: use bubble sort. It is easier to modify.

My code:

#include #include #include #include

using namespace std;

class Records { private: string Firstname, Lastname, Email, ID; double GPA;

public: void setFname(string x) { Firstname = x; } void setLname(string x) { Lastname = x; } void setID(string x) { ID = x; } void setEmail(string x) { Email = x; } void setGPA(double x) { GPA = x; }

string getFname() const { return Firstname; } string getLname() const { return Lastname; } string getEmail() const { return Email; } string getID() const { return ID; } double getGPA() const { return GPA; } };

void inputData(Records RecArr[], int &x); void UnsortedPrint(Records StudentRc[], int x); void IDsearchRecord(Records StudentRc[], int x);

void inputData(Records RecArr[], int &x) { fstream inFile; inFile.open("C:\\Users\\JONGMIN\\Desktop\\input.txt");

string f, l, e, i; double g; int count = 0;

while (inFile >> f >> l >> g >> i >> e) { RecArr[count].setFname(f); RecArr[count].setLname(l); RecArr[count].setGPA(g); RecArr[count].setID(i); RecArr[count].setEmail(e); count++; } x = count;

inFile.close(); }

void UnsortedPrint(Records StudentRc[], int x) { cout << setw(15) << "First Name" << setw(15) << "LastName" << setw(7) << "GPA" << setw(15) << "ID" << setw(30) << "Email" << endl; for (int i = 0; i < x; i++) { cout << setw(15) << StudentRc[i].getFname() << setw(15) << StudentRc[i].getLname() << setw(7) << StudentRc[i].getGPA() << setw(15) << StudentRc[i].getID() << setw(30) << StudentRc[i].getEmail() << endl; } }

void IDsearchRecord(Records StudentRc[], int x) { string Num; bool found = false; cout << " \tEnter student ID: "; cin >> Num; for (int i = 0; i < x; i++) { if (StudentRc[i].getID() == Num) { cout << setw(15) << "First Name" << setw(15) << "LastName" << setw(7) << "GPA" << setw(15) << "ID" << setw(30) << "Email" << endl; cout << setw(15) << StudentRc[i].getFname() << setw(15) << StudentRc[i].getLname() << setw(7) << StudentRc[i].getGPA() << setw(15) << StudentRc[i].getID() << setw(30) << StudentRc[i].getEmail() << endl; found = true; } } if (!found) cout << " \t" << Num << " is not found in the data." << endl; }

void sortedData(Records RecArr[], int x) {

}

int main() { Records RecArr[100]; int x; bool Program = true; char Option = 'x'; inputData(RecArr, x); while (Program == true) { cout << " \tA. Print records that is unsorted" << endl; cout << "\tB. Search student records by studentID" << endl; cout << "\tC. Quit the progream" << endl; cout << "\tOption : "; cin >> Option; switch (Option) { case 'A': case 'a': UnsortedPrint(RecArr, x); break; case 'B': case 'b': IDsearchRecord(RecArr, x); break; case 'C': case 'c': Program = false; break; default: cout << " \tYou entered a wrong option. Please enter the option in the Menu "; break; } } return 0; }

input data:

Jongmin Choi 3.42 900092029 Hoycoi124@naver.com Hony Jang 3.92 900092030 joeychoi9624@naver.com Amy Hges 3.22 900092031 amydaei724@naver.com Sunny Awda 3.98 900092032 sunnyaghwi1114@naver.com Jhon Llikea 2.84 900092033 ceiwn2871@naver.com Piter Harke 3.11 900092034 bijii100000@naver.com

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!