Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

recognise typical interviewer errors and explain how to avoid them

Answered: 1 week ago

Question

identify and evaluate a range of recruitment and selection methods

Answered: 1 week ago

Question

understand the role of competencies and a competency framework

Answered: 1 week ago