Rework this project to include a class. As explained in class, your project should have its functionalities moved to a class, and then create each course as an object to a class that inherits all the different functionalities of the class.
You createclass function should be used as a constructor that takes in the name of the file containing the student list.
(This way different objects are created with different class list files.)
Here is the code I need you to alter.
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
using namespace std;
const int NUM_STUDENTS = 25;
struct student {
string firstname, lastname, major, city;
int studid;
float gpa;
float phonenumber;
string home;
};
int displayMenu() {
// Display menu
int choice;
cout << "1. Sort Data by First Name\n" <<
"2. Sort data by Student ID\n" <<
"3. Sort data by Home city\n" <<
"4. Sort data by GPA\n" <<
"5. Display Data\n" <<
"6. Quit" << endl;
// Ask user to enter choice
cout << "Enter choice: ";
cin >> choice;
// Return choice
return choice;
}
string convertLower(string s) {
string loweredString = "";
// Iterate over each character of string
// Convert it into lower case
// Return loweredString
for (int i = 0; i < s.size(); i++) {
loweredString += tolower(s[i]);
}
return loweredString;
}
// Sort by name
void sortByName(student studentArray[], int size) {
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
// Converts name at index i and j to lowers
case
string s1 =
convertLower(studentArray[i].firstname);
string s2 =
convertLower(studentArray[j].firstname);
// Compare them, if > 0
if ((s1.compare(s2)) > 0) {
// Swap the students at i and j
student temp = studentArray[i];
studentArray[i] = studentArray[j];
studentArray[j] = temp;
}
}
}
}
// Sort by city
void sortByCity(student studentArray[], int size) {
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
// Convert city at index i and j to lower
case
string s1 =
convertLower(studentArray[i].city);
string s2 =
convertLower(studentArray[j].city);
// Compare them
if ((s1.compare(s2)) > 0) {
// Swap the students at i and j
student temp = studentArray[i];
studentArray[i] = studentArray[j];
studentArray[j] = temp;
}
}
}
}
// Sort by student ID
void sortByID(student studentArray[], int size) {
// Sort array using bubble sort
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
// If id at i > j, swap students at i and
j
if (studentArray[i].studid >
studentArray[j].studid) {
student temp = studentArray[i];
studentArray[i] = studentArray[j];
studentArray[j] = temp;
}
}
}
}
// Sort by GPA
void sortByGPA(student studentArray[], int size) {
// Sort array using bubble sort
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
// If gpa at i > j, swap students at i and
j
if (studentArray[i].gpa > studentArray[j].gpa)
{
student temp = studentArray[i];
studentArray[i] = studentArray[j];
studentArray[j] = temp;
}
}
}
}
// Displays the student list
void displayData(student studentArray[], int size) {
cout << endl;
cout << left << setw(15) << "First Name" <<
setw(15) << "Last Name" << setw(15) << "Major"
<< setw(15) << "ID" << setw(15) << "GPA"
<< setw(15) << "Home City" << endl;
cout <<
"---------------------------------------------------------------------------------------------"
<< endl;
// Iterates loop size times and print first name, last name, major
id, GPA and home city of student
for (int i = 0; i < size; i++) {
cout << left << setw(15) <<
studentArray[i].firstname << setw(15) <<
studentArray[i].lastname << setw(15) <<
studentArray[i].major << setw(15) <<
studentArray[i].studid << setw(15) <<
studentArray[i].gpa << setw(15) << studentArray[i].city
<< endl;
}
}
void DropClass() { // drops the class for students that
request
char oldname[] = "temp.txt";
char newname[] = "studentRecords.txt";
int result;
string line, name;
cout << "Please Enter the student ID: ";
cin >> name;
ifstream myfile("studentRecords.txt");
ofstream temp;
temp.open("temp.txt");
while (getline(myfile, line)) {
if (line.substr(0, name.size()) != name)
temp << line << endl;
}
cout << "The record with the name " << name << "
has been deleted if it existed" << endl;
myfile.close();
temp.close();
remove("studentRecords.txt");
rename(oldname, newname);
}
void RegisterClass() {
student * ds;
int n, i;
cout << "Amount of student to be entered: ";
cin >> n;
ds = new student[n + 1];
if (ds == NULL) {
cout << "Error!!!" << endl;
exit(1);
}
//input data
for (i = 0; i < n; i++) {
cout << "Student #" << i << ": "
<< endl;
cout << "First Name: ";
cin >> ds[i].firstname;
cout << endl << "Last Name: ";
cin >> ds[i].lastname;
cout << endl << "Major: ";
cin >> ds[i].major;
cout << endl << "StudentId: ";
cin >> ds[i].studid;
cout << endl << "gpa: ";
cin >> ds[i].gpa;
cout << endl << "phoneNumber: ";
cin >> ds[i].phonenumber;
cout << endl << "Home: " <<
endl;
cin >> ds[i].home;
}
for (i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (ds[i].aver_grade < ds[j].aver_grade)
{
student temp = ds[i];
ds[i] = ds[j];
ds[j] = temp;
}
cout << setiosflags(ios::showpoint) <<
setprecision(1);
//display data
for (i = 0; i < n; i++)
cout << ds[i].MSV << setw(3) <<
ds[i].name << setw(5) << ds[i].name_class << endl
<< "Average Grade: " << ds[i].aver_grade;
delete ds;
}
/*
function sortbyfname {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student),
comparefirstname);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
function sortbylname {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student), comparelastname);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
function sortbymajor {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student), compareMajor);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
function sortbyid {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student),
comparestudentId);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
function sortbygpa {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student), comparegpa);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
function sortbyphone {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student),
comparephoneNumber);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
function sortbyhome {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student), compareHome);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
*/
int comparefirstname(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int FirstNamecompare = strcmp(e1->firstname,
e2->firstname);
if (FirstNamecompare == 0) /* same FirstName so sort by Studentid
*/
return e1->studid - e2->studid;
else
return -FirstNamecompare;
}
int comparelastname(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int lastNamecompare = strcmp(e1->lastname,
e2->lastname);
if (lastNamecompare == 0) /* same LastName so sort by FirstName
*/
return e1->firstname - e2->firstname;
else
return -lastNamecompare;
}
int comparestudentId(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int studentidcompare = strcmp(e1->studid, e2->studid);
if (studentidcompare == 0) /* same student id so sort by FirstName
*/
return 0; // you do not have two students with same id,
you can omit this if block
else
return -studentidcompare;
}
int comparegpa(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int gpacompare = strcmp(e1->gpa, e2->gpa);
if (gpacompare == 0) /* same gpa so sort by FirstName */
return e1->firstname - e2->firstname;
else
return -gpacompare;
}
int compareMajor(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int majorcompare = strcmp(e1->major, e2->major);
if (majorcompare == 0) /* same major id so sort by FirstName
*/
return e1->firstname - e2->firstname;
else
return -majorcompare;
}
int comparephoneNumber(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int phonecompare = strcmp(e1->phonenumber,
e2->phonenumber);
if (phonecompare == 0) /* same phone so sort by FirstName */
return e1->firstname - e2->firstname;
else
return -phonecompare;
}
int compareHome(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int homecompare = strcmp(e1->home.c_str(),
e2->home.c_str());
if (homecompare == 0) /* same home so sort by FirstName */
return e1->firstname - e2->firstname;
else
return -homecompare;
}
int main() {
ifstream ifs("studentRecords.txt");
struct student records[25];
int studid;
float gpa;
long long phonenumber;
string path = "studentRecords.txt";
string firstname, lastname, city, major;
if (ifs.fail()) {
cout << "Error opening student records file
(studentRecords.txt)" << endl;
exit(1);
}
// student s;
int i = 0;
while (!ifs.eof()) {
ifs >> studid >> firstname >>
lastname >> major >> gpa >> phonenumber >>
city;
records[i].studid = studid;
records[i].firstname = firstname;
records[i].lastname = lastname;
records[i].major = major;
records[i].gpa = gpa;
records[i].phonenumber = phonenumber;
records[i].city = city;
i++;
}
cout << "Displaying Information," << endl;
for (int j = 0; j < i; j++) {
cout << records[j].studid << " ";
cout << records[j].firstname << " ";
cout << records[j].lastname << " ";
cout << records[j].major << " ";
cout << records[j].gpa << " ";
cout << records[j].phonenumber << "
";
cout << records[j].city << endl;
}
cout << endl;
ifs.close();
DropClass();
char c;
student studList[25];
//object of if stream to read from file
std::ifstream openfile;
//string content
std::string getcontent;
//do while loop
do {
//ask if user wants to continue
cout << "Do you want to exit (y/n)?";
cin >> c;
// if file opens read the file initialize student
object add it to list and print it's content
if (openfile.is_open()) {
while (!openfile.eof()) {
student * s = new student();
getline(openfile, getcontent);
cout << getcontent <<
endl;
}
}
//throw error if file does not open
else {
cout << "There was an error opening file.
";
exit(0);
}
} while (c != 'y');
return 0;
}
?When you are done. Please also send me the code for the class that will be inside the header file.
?Also please note, this is the information inside "studentrecord.txt"
First Name Last
Name
Major Student
ID
GPA Phone
Number Home City
Jane
Porter
Math
173894
3.9
4015388833
Arlington
Clarke
Griffith
Bio
100100
4.0
3018100100
DC
Craig
Bellamy
Ctec
128490
0.2
2403849399
Bowie
Manny
Rhodes
Chem
183903
2.9
3203848499
Largo
Robert
Reyes
Ctec
137940
3.4
4103948929
Bowie
Alexis
Rodrigues
Hist
128739
3.2
3014732293
Fairfax
Daniel
Proctor
Ctec
103848
2.5
3019382923
DC
Oliver
Kostermann
Cosc
193338
3.8
2049238392
Lanham
John
Constantine
Hist
183779
3.4
3103938493
Alexandria
Nagisa
Hiroyama
Chem
129030
3.7
2402874748
Lanham
Simone
Xypher
Bio
193830
4.0
3013849292
DC
Jason
Rundelhause
Math
139480
0.9
2013874829
Bowie
Abel
Herrera
Cosc
123999
1.5
3013983722
Falls Church
Connor
Angel
Hist
197920
3.7
2402879302
Alexandria
Monica
Strauss
Bio
110030
0.8
4010393849
Greenbelt
Claire
Matteo
Hist
102837
3.1
2402884893
Largo
Farida
Ahmed
Cosc
183920
3.0
3019389282
Arlington
David
Masterson
Hist
127393
1.4
4102937498
Falls Church
Chloe
Gignac
Cosc
188292
3.7
3102338229
Fairfax
William
Tucker
Math
198339
0.5
3019912293
Greenbelt
Daniela
Moreira
Ctec
139300
3.6
2402919933
DC
Birgit
Prinz
Cosc
109022
3.9
2018473993
Bowie
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
using namespace std;
const int NUM_STUDENTS = 25;
struct student {
string firstname, lastname, major, city;
int studid;
float gpa;
float phonenumber;
string home;
};
int displayMenu() {
// Display menu
int choice;
cout << "1. Sort Data by First Name\n" <<
"2. Sort data by Student ID\n" <<
"3. Sort data by Home city\n" <<
"4. Sort data by GPA\n" <<
"5. Display Data\n" <<
"6. Quit" << endl;
// Ask user to enter choice
cout << "Enter choice: ";
cin >> choice;
// Return choice
return choice;
}
string convertLower(string s) {
string loweredString = "";
// Iterate over each character of string
// Convert it into lower case
// Return loweredString
for (int i = 0; i < s.size(); i++) {
loweredString += tolower(s[i]);
}
return loweredString;
}
// Sort by name
void sortByName(student studentArray[], int size) {
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
// Converts name at index i and j to lowers
case
string s1 =
convertLower(studentArray[i].firstname);
string s2 =
convertLower(studentArray[j].firstname);
// Compare them, if > 0
if ((s1.compare(s2)) > 0) {
// Swap the students at i and j
student temp = studentArray[i];
studentArray[i] = studentArray[j];
studentArray[j] = temp;
}
}
}
}
// Sort by city
void sortByCity(student studentArray[], int size) {
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
// Convert city at index i and j to lower
case
string s1 =
convertLower(studentArray[i].city);
string s2 =
convertLower(studentArray[j].city);
// Compare them
if ((s1.compare(s2)) > 0) {
// Swap the students at i and j
student temp = studentArray[i];
studentArray[i] = studentArray[j];
studentArray[j] = temp;
}
}
}
}
// Sort by student ID
void sortByID(student studentArray[], int size) {
// Sort array using bubble sort
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
// If id at i > j, swap students at i and
j
if (studentArray[i].studid >
studentArray[j].studid) {
student temp = studentArray[i];
studentArray[i] = studentArray[j];
studentArray[j] = temp;
}
}
}
}
// Sort by GPA
void sortByGPA(student studentArray[], int size) {
// Sort array using bubble sort
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
// If gpa at i > j, swap students at i and
j
if (studentArray[i].gpa > studentArray[j].gpa)
{
student temp = studentArray[i];
studentArray[i] = studentArray[j];
studentArray[j] = temp;
}
}
}
}
// Displays the student list
void displayData(student studentArray[], int size) {
cout << endl;
cout << left << setw(15) << "First Name" <<
setw(15) << "Last Name" << setw(15) << "Major"
<< setw(15) << "ID" << setw(15) << "GPA"
<< setw(15) << "Home City" << endl;
cout <<
"---------------------------------------------------------------------------------------------"
<< endl;
// Iterates loop size times and print first name, last name, major
id, GPA and home city of student
for (int i = 0; i < size; i++) {
cout << left << setw(15) <<
studentArray[i].firstname << setw(15) <<
studentArray[i].lastname << setw(15) <<
studentArray[i].major << setw(15) <<
studentArray[i].studid << setw(15) <<
studentArray[i].gpa << setw(15) << studentArray[i].city
<< endl;
}
}
void DropClass() { // drops the class for students that
request
char oldname[] = "temp.txt";
char newname[] = "studentRecords.txt";
int result;
string line, name;
cout << "Please Enter the student ID: ";
cin >> name;
ifstream myfile("studentRecords.txt");
ofstream temp;
temp.open("temp.txt");
while (getline(myfile, line)) {
if (line.substr(0, name.size()) != name)
temp << line << endl;
}
cout << "The record with the name " << name << "
has been deleted if it existed" << endl;
myfile.close();
temp.close();
remove("studentRecords.txt");
rename(oldname, newname);
}
void RegisterClass() {
student * ds;
int n, i;
cout << "Amount of student to be entered: ";
cin >> n;
ds = new student[n + 1];
if (ds == NULL) {
cout << "Error!!!" << endl;
exit(1);
}
//input data
for (i = 0; i < n; i++) {
cout << "Student #" << i << ": "
<< endl;
cout << "First Name: ";
cin >> ds[i].firstname;
cout << endl << "Last Name: ";
cin >> ds[i].lastname;
cout << endl << "Major: ";
cin >> ds[i].major;
cout << endl << "StudentId: ";
cin >> ds[i].studid;
cout << endl << "gpa: ";
cin >> ds[i].gpa;
cout << endl << "phoneNumber: ";
cin >> ds[i].phonenumber;
cout << endl << "Home: " <<
endl;
cin >> ds[i].home;
}
for (i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (ds[i].aver_grade < ds[j].aver_grade)
{
student temp = ds[i];
ds[i] = ds[j];
ds[j] = temp;
}
cout << setiosflags(ios::showpoint) <<
setprecision(1);
//display data
for (i = 0; i < n; i++)
cout << ds[i].MSV << setw(3) <<
ds[i].name << setw(5) << ds[i].name_class << endl
<< "Average Grade: " << ds[i].aver_grade;
delete ds;
}
/*
function sortbyfname {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student),
comparefirstname);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
function sortbylname {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student), comparelastname);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
function sortbymajor {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student), compareMajor);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
function sortbyid {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student),
comparestudentId);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
function sortbygpa {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student), comparegpa);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
function sortbyphone {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student),
comparephoneNumber);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
function sortbyhome {
student * ds;
int n, i;
for (i = 0; i < 100; ++i)
cout("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", ds[i].FirstName,
ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa,
ds[i].phoneNumber, ds[i].Home);
qsort(student, 100, sizeof(struct student), compareHome);
for (i = 0; i < 3; ++i)
cin("%s\t%s\t%s\t%d\t%d\t%s\t%s\n", info[i].id, info[i].gender,
info[i].name);
}
*/
int comparefirstname(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int FirstNamecompare = strcmp(e1->firstname,
e2->firstname);
if (FirstNamecompare == 0) /* same FirstName so sort by Studentid
*/
return e1->studid - e2->studid;
else
return -FirstNamecompare;
}
int comparelastname(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int lastNamecompare = strcmp(e1->lastname,
e2->lastname);
if (lastNamecompare == 0) /* same LastName so sort by FirstName
*/
return e1->firstname - e2->firstname;
else
return -lastNamecompare;
}
int comparestudentId(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int studentidcompare = strcmp(e1->studid, e2->studid);
if (studentidcompare == 0) /* same student id so sort by FirstName
*/
return 0; // you do not have two students with same id,
you can omit this if block
else
return -studentidcompare;
}
int comparegpa(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int gpacompare = strcmp(e1->gpa, e2->gpa);
if (gpacompare == 0) /* same gpa so sort by FirstName */
return e1->firstname - e2->firstname;
else
return -gpacompare;
}
int compareMajor(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int majorcompare = strcmp(e1->major, e2->major);
if (majorcompare == 0) /* same major id so sort by FirstName
*/
return e1->firstname - e2->firstname;
else
return -majorcompare;
}
int comparephoneNumber(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int phonecompare = strcmp(e1->phonenumber,
e2->phonenumber);
if (phonecompare == 0) /* same phone so sort by FirstName */
return e1->firstname - e2->firstname;
else
return -phonecompare;
}
int compareHome(const void * s1, const void * s2) {
struct student * e1 = (struct student *) s1;
struct student * e2 = (struct student *) s2;
int homecompare = strcmp(e1->home.c_str(),
e2->home.c_str());
if (homecompare == 0) /* same home so sort by FirstName */
return e1->firstname - e2->firstname;
else
return -homecompare;
}
int main() {
ifstream ifs("studentRecords.txt");
struct student records[25];
int studid;
float gpa;
long long phonenumber;
string path = "studentRecords.txt";
string firstname, lastname, city, major;
if (ifs.fail()) {
cout << "Error opening student records file
(studentRecords.txt)" << endl;
exit(1);
}
// student s;
int i = 0;
while (!ifs.eof()) {
ifs >> studid >> firstname >>
lastname >> major >> gpa >> phonenumber >>
city;
records[i].studid = studid;
records[i].firstname = firstname;
records[i].lastname = lastname;
records[i].major = major;
records[i].gpa = gpa;
records[i].phonenumber = phonenumber;
records[i].city = city;
i++;
}
cout << "Displaying Information," << endl;
for (int j = 0; j < i; j++) {
cout << records[j].studid << " ";
cout << records[j].firstname << " ";
cout << records[j].lastname << " ";
cout << records[j].major << " ";
cout << records[j].gpa << " ";
cout << records[j].phonenumber << "
";
cout << records[j].city << endl;
}
cout << endl;
ifs.close();
DropClass();
char c;
student studList[25];
//object of if stream to read from file
std::ifstream openfile;
//string content
std::string getcontent;
//do while loop
do {
//ask if user wants to continue
cout << "Do you want to exit (y/n)?";
cin >> c;
// if file opens read the file initialize student
object add it to list and print it's content
if (openfile.is_open()) {
while (!openfile.eof()) {
student * s = new student();
getline(openfile, getcontent);
cout << getcontent <<
endl;
}
}
//throw error if file does not open
else {
cout << "There was an error opening file.
";
exit(0);
}
} while (c != 'y');
return 0;
}
Rework this project to include a class. As explained in class, your project should have its...
Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency in sorting the employee’s net pay. //I need to use an EXSEL sort in order to combine the selection and Exchange sorts for my program. I currently have a selection sort in there. Please help me with replacing this with the EXSEL sort. //My input files: //My current code with the sel sort. Please help me replace this with an EXSEL sort. #include <fstream>...
I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include <string> #include <iomanip> using namespace std; struct Drink { string name; double cost; int noOfDrinks; }; void displayMenu(Drink drinks[], int n); int main() { const int size = 5; Drink drinks[size] = { {"Cola", 0.65, 2}, {"Root Beer", 0.70, 1}, {"Grape Soda", 0.75, 5}, {"Lemon-Lime", 0.85, 20}, {"Water", 0.90, 20} }; cout <<...
Here is the code from the previous three steps: #include <iostream> using namespace std; class Student { private: //class variables int ID; string firstName,lastName; public: Student(int ID,string firstName,string lastName) //constructor { this->ID=ID; this->firstName=firstName; this->lastName=lastName; } int getID() //getter method { return ID; } virtual string getType() = 0; //pure virtual function virtual void printInfo() //virtual function to print basic details of a student { cout << "Student type: " << getType() << endl; cout << "Student ID: " << ID...
Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters student first name, 10 characters middle name, 20 characters last name, 9 characters student ID, 3 characters age, in years (3 digits) 2- Open the input file. Check for successful open. If the open failed, display an error message and return with value 1. 3- Use a pointer array to manage all the created student variables.Assume that there will not be more than 99...
How could I separate the following code to where I have a gradebook.cpp and gradebook.h file? #include <iostream> #include <stdio.h> #include <string> using namespace std; class Gradebook { public : int homework[5] = {-1, -1, -1, -1, -1}; int quiz[5] = {-1, -1, -1, -1, -1}; int exam[3] = {-1, -1, -1}; string name; int printMenu() { int selection; cout << "-=| MAIN MENU |=-" << endl; cout << "1. Add a student" << endl; cout << "2. Remove a...
The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...
Using C++, fix the following code so that (1) Change the student array storage part so that the data is loaded from a file "students.txt". Use an appropriate data termination flag. (2) Sort the student array in ascending order of GPA using insertion sort. Print the sorted array (3) Sort the student array in ascending order of ID using insertion sort. Print the sorted array (4) Illustrate Binary search for a particular ID that would be found and one...
Have Corporate Sales for 6 divisions and their quarterly sales figures. The issue is the error function where I am unable to have user reinput the same quarterly amount without going to the next quarter input. This has affected the total sales for the company. /***************************************** This program gathers sales information for six divisions and displays the total sales for each division and total company. *****************************************/ #include<iostream> using namespace std; // Classs division sales class DivSales { private: // Variables...
C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...
C++ Assignment on Search and Sort for Chapter 8 Problem: Modify the student grade problem to include the following: • Write a Search function to search by student score • Write a Search function to search by student last name • Write a Sort function to sort the list by student score • Write a Sort function to sort the list by student last name • Write a menu function that lets user to choose any action he/she want to...