Program 24 \"Sorting Students\" Write a C++ program that will open a file named stDATA.txt.
This file contains an unknown number of student records, one per line. The total number of
records will be less than or equal to 100. Your program should print a list of students sorted by
GPA. If two students have the same GPA they should be sub-sorted by classification (SR, JR,
SO, FR). If two students have the same GPA and the same classification, they should be sub-
sorted by last name. If two students have the same GPA, classification, and last name they
should be sub-sorted by first name. If two students have the same GPA, classification, last name
and first name, the second student\'s record should not be printed; instead the message: \"I
THINK THIS IS A DUPLICATE RECORD\" should be printed. [edit]Deliverables main.cpp
prog24Functions.h prog24Functions.cpp Sample data file: FirstName LastName CLASS ZIP
AGE HomeTown GPA Hailee Ferrel FR 72275 20 Layton 3.63 Perry Caldwell-Reed SO 4164
19 Racine 2.96 Andrew Dawson JR 39123 21 Huntington 2.29 William Senser SR 15886 25
Fontana 2.14 Shelby Santiago FR 57021 23 Winter 3.15 Matthew Brannon SO 54064 18 Santa
3.35 Christopher Kou JR 31907 22 Monroe 2.36 Cassidy Monjaras SR 41928 24 Jefferson 2.13
Lauren Shah FR 65008 23 Visalia 2.66 Jonathan Quintanilla SO 79343 16 Howell 3.69 Andrew
Chen JR 86176 18 Brownsville 3.32 Brendel Unruh SR 37743 20 Lansing 2.48 Christopher
Royse FR 8095 22 Anchorage 3.98 Jose Harrison SO 33128 17 Greenville 2.09 Alexander
Seiford JR 96517 16 Greenville 2.88 Quinton Johnson SR 56102 20 Winston 3.89 Tristan
Gardner FR 74489 21 Brighton 2.22 Alexander Motz SO 49195 24 Cathedral 3.13 Molly Atkins
JR 27698 15 Des 3.54 William Savells SR 17951 19 Shreveport 3.16 Shawn Wilcoxen FR 86284
21 Syracuse 3.11 Austin Hardy SO 73491 15 Birmingham 2.52 Jason Ammons JR 94515 22
Atlanta 2.86 Phillip Dutta SR 19503 19 Milwaukee 2.34 Wesley Elliott FR 8885 17 Eugene 2.64
Alexander Childers SO 55503 17 Thornton 2.76 Cameron Jones JR 77131 20 New 2.56 Jessica
Louis SR 66868 24 Asheville 3.41 Ryan Kliphon FR 6054 16 Kissimmee 3.26 Zachariah
Qureshi SO 18845 19 Harlingen 2.65 Ryan Cadenas JR 35181 16 Olathe 3.45 Chandrima Bryant
SR 64898 18 Chicago 3.74 Doraliz Hansen FR 30588 23 Boston 2.61 Alonso Greer SO 94115
20 Victorville 3.19 David Llamas JR 84133 19 Hesperia 2.54 Caleb Dylag SR 35101 15
Sebastian 3.91 Rachel Zust FR 42196 16 Westminster 2.74 Tyler DeRosa SO 14421 19
Westminster 3.21 Kendall Sedate JR 43036 22 Moreno 2.29 Matthew Ortiz-Vitali SR 14801 22
Cary 2.03 Ryan Al-Nimri FR 53238 16 Mission 3.75 Daniel Dratz SO 59534 22 Mission 2.83
Weston Gage JR 56011 18 Macon 2.43 Asad Riggins SR 67131 25 Macon 2.06 John Thompson
FR 15386 21 Olympia 3.82 James Seunsom SO 42143 21 Richmond 3.58 Corbin Bodden JR
32787 16 Provo 2.96 Allison Veselka SR 99047 21 Wilmington 3.35 Shawn Renton FR 74027
24 Fort 2.21 Michael Martin SO 74146 16 Bryan 2.82 Austin Huizinga JR 49494 15 Leominster
3.35 Caleb Berko.
Program 24 Sorting Students Write a C++ program that will open a.pdf
1. Program 24 "Sorting Students" Write a C++ program that will open a file named stDATA.txt.
This file contains an unknown number of student records, one per line. The total number of
records will be less than or equal to 100. Your program should print a list of students sorted by
GPA. If two students have the same GPA they should be sub-sorted by classification (SR, JR,
SO, FR). If two students have the same GPA and the same classification, they should be sub-
sorted by last name. If two students have the same GPA, classification, and last name they
should be sub-sorted by first name. If two students have the same GPA, classification, last name
and first name, the second student's record should not be printed; instead the message: "I
THINK THIS IS A DUPLICATE RECORD" should be printed. [edit]Deliverables main.cpp
prog24Functions.h prog24Functions.cpp Sample data file: FirstName LastName CLASS ZIP
AGE HomeTown GPA Hailee Ferrel FR 72275 20 Layton 3.63 Perry Caldwell-Reed SO 4164
19 Racine 2.96 Andrew Dawson JR 39123 21 Huntington 2.29 William Senser SR 15886 25
Fontana 2.14 Shelby Santiago FR 57021 23 Winter 3.15 Matthew Brannon SO 54064 18 Santa
3.35 Christopher Kou JR 31907 22 Monroe 2.36 Cassidy Monjaras SR 41928 24 Jefferson 2.13
Lauren Shah FR 65008 23 Visalia 2.66 Jonathan Quintanilla SO 79343 16 Howell 3.69 Andrew
Chen JR 86176 18 Brownsville 3.32 Brendel Unruh SR 37743 20 Lansing 2.48 Christopher
Royse FR 8095 22 Anchorage 3.98 Jose Harrison SO 33128 17 Greenville 2.09 Alexander
Seiford JR 96517 16 Greenville 2.88 Quinton Johnson SR 56102 20 Winston 3.89 Tristan
Gardner FR 74489 21 Brighton 2.22 Alexander Motz SO 49195 24 Cathedral 3.13 Molly Atkins
JR 27698 15 Des 3.54 William Savells SR 17951 19 Shreveport 3.16 Shawn Wilcoxen FR 86284
21 Syracuse 3.11 Austin Hardy SO 73491 15 Birmingham 2.52 Jason Ammons JR 94515 22
Atlanta 2.86 Phillip Dutta SR 19503 19 Milwaukee 2.34 Wesley Elliott FR 8885 17 Eugene 2.64
Alexander Childers SO 55503 17 Thornton 2.76 Cameron Jones JR 77131 20 New 2.56 Jessica
Louis SR 66868 24 Asheville 3.41 Ryan Kliphon FR 6054 16 Kissimmee 3.26 Zachariah
Qureshi SO 18845 19 Harlingen 2.65 Ryan Cadenas JR 35181 16 Olathe 3.45 Chandrima Bryant
SR 64898 18 Chicago 3.74 Doraliz Hansen FR 30588 23 Boston 2.61 Alonso Greer SO 94115
20 Victorville 3.19 David Llamas JR 84133 19 Hesperia 2.54 Caleb Dylag SR 35101 15
Sebastian 3.91 Rachel Zust FR 42196 16 Westminster 2.74 Tyler DeRosa SO 14421 19
Westminster 3.21 Kendall Sedate JR 43036 22 Moreno 2.29 Matthew Ortiz-Vitali SR 14801 22
Cary 2.03 Ryan Al-Nimri FR 53238 16 Mission 3.75 Daniel Dratz SO 59534 22 Mission 2.83
Weston Gage JR 56011 18 Macon 2.43 Asad Riggins SR 67131 25 Macon 2.06 John Thompson
FR 15386 21 Olympia 3.82 James Seunsom SO 42143 21 Richmond 3.58 Corbin Bodden JR
32787 16 Provo 2.96 Allison Veselka SR 99047 21 Wilmington 3.35 Shawn Renton FR 74027
24 Fort 2.21 Michael Martin SO 74146 16 Bryan 2.82 Austin Huizinga JR 49494 15 Leominster
3.35 Caleb Berkovsky SR 3711 24 Leominster 3.51 Taylor Brown FR 69305 24 Kailua 2.18
2. Elizabeth Taylor SO 54950 17 Tempe 2.95 Alexandra Itskin JR 35943 16 Denver 3.12 Reagan
Zipoy SR 3892 16 Pomona 2.70 Edgar Leblanc FR 52703 22 Riverside 3.12 Brian Stevens SO
93293 23 Nashua 3.26 Sam Pearson JR 69161 17 Danbury 3.14 Colin Peterson SR 77027 24
Gulfport-Biloxi 2.72 Diana Sharpe FR 65253 22 Palmdale 3.35 Ching-Jung Labrada SO 48635
20 Aberdeen 3.93 Roberto Haddad JR 69486 19 Escondido 2.70 Mahlet Shifflet SR 82554 15
Appleton 3.32 Parker Miller FR 93219 20 South 2.32 Matthew Leake SO 49468 19 Mesa 3.55
Corey McBrayer JR 71592 18 Santa 2.45 David Tramontano SR 38229 24 Murrieta 3.51 John
Rundquist FR 78321 16 Clarke 2.42 Caroline Christenberry SO 42590 24 Poughkeepsie 3.04
Ashley Thomas JR 86691 17 Louisville 2.95 Kyle Andras SR 43291 25 Bakersfield 2.62 Trey
Bolling FR 74843 16 Muskegon 3.79 Adam Brown SO 76537 21 Fort 3.89 Michael Handley JR
58339 19 Lancaster 2.29 Andrew Zinah SR 88135 22 Odessa 3.55 Shawn Wilcoxen FR 86284
21 Syracuse 3.11 Austin Hardy SO 73491 15 Birmingham 2.52 Jason Ammons JR 94515 22
Atlanta 2.86 Phillip Dutta SR 19503 19 Milwaukee 2.34 Wesley Elliott FR 8885 17 Eugene 2.64
Phillip Dutta SR 19503 19 Milwaukee 2.34 Wesley Elliott FR 8885 17 Eugene 2.64 Diana
Sharpe FR 65253 22 Palmdale 3.35 Diana Sharpe FR 65253 22 Palmdale 3.35 Diana Sharpe FR
65253 22 Palmdale 3.35 Sample Output: First Name Last Name Class Zip Age HomeTown GPA
Matthew Ortiz-Vitali SR 14801 22 Cary 2.03 Asad Riggins SR 67131 25 Macon 2.06 Jose
Harrison SO 33128 17 Greenville 2.09 Cassidy Monjaras SR 41928 24 Jefferson 2.13 William
Senser SR 15886 25 Fontana 2.14 Taylor Brown FR 69305 24 Kailua 2.18 Shawn Renton FR
74027 24 Fort 2.21 Tristan Gardner FR 74489 21 Brighton 2.22 Andrew Dawson JR 39123 21
Huntington 2.29 Michael Handley JR 58339 19 Lancaster 2.29 Kendall Sedate JR 43036 22
Moreno 2.29 Parker Miller FR 93219 20 South 2.32 Phillip Dutta SR 19503 19 Milwaukee 2.34
I THINK THIS IS A DUPLICATE RECORD I THINK THIS IS A DUPLICATE RECORD
Christopher Kou JR 31907 22 Monroe 2.36 John Rundquist FR 78321 16 Clarke 2.42 Weston
Gage JR 56011 18 Macon 2.43 Corey McBrayer JR 71592 18 Santa 2.45 Brendel Unruh SR
37743 20 Lansing 2.48 Austin Hardy SO 73491 15 Birmingham 2.52 I THINK THIS IS A
DUPLICATE RECORD David Llamas JR 84133 19 Hesperia 2.54 Cameron Jones JR 77131 20
New 2.56 Doraliz Hansen FR 30588 23 Boston 2.61 Kyle Andras SR 43291 25 Bakersfield 2.62
Wesley Elliott FR 8885 17 Eugene 2.64 I THINK THIS IS A DUPLICATE RECORD I THINK
THIS IS A DUPLICATE RECORD Zachariah Qureshi SO 18845 19 Harlingen 2.65 Lauren
Shah FR 65008 23 Visalia 2.66 Roberto Haddad JR 69486 19 Escondido 2.70 Reagan Zipoy SR
3892 16 Pomona 2.70 Colin Peterson SR 77027 24 Gulfport-Biloxi 2.72 Rachel Zust FR 42196
16 Westminster 2.74 Alexander Childers SO 55503 17 Thornton 2.76 Michael Martin SO 74146
16 Bryan 2.82 Daniel Dratz SO 59534 22 Mission 2.83 Jason Ammons JR 94515 22 Atlanta 2.86
I THINK THIS IS A DUPLICATE RECORD Alexander Seiford JR 96517 16 Greenville 2.88
Ashley Thomas JR 86691 17 Louisville 2.95 Elizabeth Taylor SO 54950 17 Tempe 2.95 Corbin
3. Bodden JR 32787 16 Provo 2.96 Perry Caldwell-Reed SO 4164 19 Racine 2.96 Caroline
Christenberry SO 42590 24 Poughkeepsie 3.04 Shawn Wilcoxen FR 86284 21 Syracuse 3.11 I
THINK THIS IS A DUPLICATE RECORD Edgar Leblanc FR 52703 22 Riverside 3.12
Alexandra Itskin JR 35943 16 Denver 3.12 Alexander Motz SO 49195 24 Cathedral 3.13 Sam
Pearson JR 69161 17 Danbury 3.14 Shelby Santiago FR 57021 23 Winter 3.15 William Savells
SR 17951 19 Shreveport 3.16 Alonso Greer SO 94115 20 Victorville 3.19 Tyler DeRosa SO
14421 19 Westminster 3.21 Ryan Kliphon FR 6054 16 Kissimmee 3.26 Brian Stevens SO 93293
23 Nashua 3.26 Andrew Chen JR 86176 18 Brownsville 3.32 Mahlet Shifflet SR 82554 15
Appleton 3.32 Diana Sharpe FR 65253 22 Palmdale 3.35 I THINK THIS IS A DUPLICATE
RECORD I THINK THIS IS A DUPLICATE RECORD I THINK THIS IS A DUPLICATE
RECORD Austin Huizinga JR 49494 15 Leominster 3.35 Matthew Brannon SO 54064 18 Santa
3.35 Allison Veselka SR 99047 21 Wilmington 3.35 Jessica Louis SR 66868 24 Asheville 3.41
Ryan Cadenas JR 35181 16 Olathe 3.45 Caleb Berkovsky SR 3711 24 Leominster 3.51 David
Tramontano SR 38229 24 Murrieta 3.51 Molly Atkins JR 27698 15 Des 3.54 Matthew Leake SO
49468 19 Mesa 3.55 Andrew Zinah SR 88135 22 Odessa 3.55 James Seunsom SO 42143 21
Richmond 3.58 Hailee Ferrel FR 72275 20 Layton 3.63 Jonathan Quintanilla SO 79343 16
Howell 3.69 Chandrima Bryant SR 64898 18 Chicago 3.74 Ryan Al-Nimri FR 53238 16 Mission
3.75 Trey Bolling FR 74843 16 Muskegon 3.79 John Thompson FR 15386 21 Olympia 3.82
Adam Brown SO 76537 21 Fort 3.89 Quinton Johnson SR 56102 20 Winston 3.89 Caleb Dylag
SR 35101 15 Sebastian 3.91 Ching-Jung Labrada SO 48635 20 Aberdeen 3.93 Christopher
Royse FR 8095 22 Anchorage 3.98
Solution
#include
#include
using namespace std;
//student class to capture students data
class Student
{
//instance c=variables for students
public:
string fname;
string lname;
4. string classs;
int zip;
int age;
string town;
float gpa;
//constructor
Student(string fn,string ln,string c,int z,int a,string h,float g)
{
fname=fn;
lname=ln;
classs=c;
zip=z;
age=a;
town=h;
gpa=g;
}
//default constructor
Student()
{
}
};
//function to read data frm file
//returns no of records read
int readFromFile(Student students[100])
{
int size=0;
string fname,lname,town,classs;
int zip,age;
float gpa;
ifstream myfile ("stDATA.txt");
if (myfile.is_open())
{
6. students[j] = tmp;
}
//if students gpa and classfictaion match, compare lname
else
if(students[i].classs == students[j].classs)
{
if(students[i].lname >students[j].lname)
{
tmp = students[i];
students[i] = students[j];
students[j] = tmp;
}
// f students gpa and classfictaion and lname match, compare fname
else
if(students[i].lname == students[j].lname)
{
if(students[i].fname >students[j].fname)
{
tmp = students[i];
students[i] = students[j];
students[j] = tmp;
}
// if students gpa and classfictaion and lname and fname match it emans it's a
duplkictae record
//set a flag to identify it
else
if(students[i].fname ==students[j].fname)
{
students[j].fname="Duplicate";
}
}
}
}
}
7. }
//sort
}
//main fucntion which triggers
int main()
{
Student students[100];
int size=readFromFile(students);
sort(students,size);
display(students,size);
cout<