Question: I don't know how to sort an array of pointers to object. I attached the problem, input data, my code; (The question problem is) :

I don't know how to sort an array of pointers to object. I attached the problem, input data, my code;

(The question problem is) :

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.

(The input data is) :

Firstname Lastname GPA ID email

Joeash 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

(my code):

#include #include #include #include

using namespace std;

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

public: void setRecord(string Firstname, string Lastname, string ID, string Email, double GPA);

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 show() const; };

void Records::setRecord(string f, string l, string i, string e, double g) { Firstname = f; Lastname = l; ID = i; Email = e; GPA = g; }

void inputData(Records RecArr[], int &numRecs) { fstream inFile; inFile.open("input.txt");

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

while (inFile >> f >> l >> g >> i >> e) { RecArr[count].setRecord(f, l, i, e, g); count++; } numRecs = count;

inFile.close(); }

void sortedData() { // hear I need help }

int main() { const int SIZE = 100; Records RecArr[SIZE];

int numRecs;

inputData(RecArr, numRecs);

return 0; }

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!