Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I just need part D: Delete a Student from the List, G: Sort List by Last Name, a

ID: 3742173 • Letter: I

Question

I just need part D: Delete a Student from the List, G: Sort List by Last Name, and H: Sort List By GPA. Thanks in advance :-)

Program Summary

Write a C++ object-oriented program to manage a file system for students.

First Name – string

Last Name – string

Student ID – unsigned integer

Email – string

GPA - float

The program will manipulate the student list based on students from the file students.dat

Class requirements

Create a student class or struct based on the student structure

Create a students class which contains three private members – an array of students, the size of the array, and a function to print the contents of a process. The processes class will also provide the following functionality.

Load data from a data file into a student list

Retrieve and print a student from the student list

Insert a student into the student list

Delete a student from the student list

Print the contents of a student record

Print the contents for a list of students

Sort the student list by last Name

Sort the student list by GPA

Processing requirements

Load the students file students.dat

Create a menu to carry out the given operations

Implement input validation to avoid erroneous program errors

Structure of the file

students.dat – First Name, Last Name, Student ID, Email, GPA

Smith Jefferey 891789 j.smith@spartans.nsu.edu 3.75
Lee Jackson 3678902 j.lee@spartans.nsu.edu 3.66
Gonzales Mariana 168790 m.gonzales18@spartans.nsu.edu 4.0
Jones Mike 8973125 m.jones143@spartans.nsu.edu 3.1
Williams Anita 2985465 a.williams@spartans.nsu.edu 3.64
Ronsinson Taylor 3278976 t.robinson@spartans.nsu.edu 3.55
Clark Allen 1094567 a.clark@spartans.nsu.edu 3.48
Turner Tavon 318796 t.turner@spartans.nsu.edu 3.2
Jenkins Nelson 289563 n.jenkins@spartans.nsu.edu 3.0

*********************************MY CODE:

#include <fstream>

#include <string>

#include <iomanip>

using namespace std;

struct studentInfo

{

string firstName;

string lastName;

unsigned int studentID;

string email;

float gpa;

};

class studentsProc

{

public:

void studentList();

void loadList();

void retrieveStudent();

void insertStudent();

void deleteStudent();

void printStudent();

void displayStudent();

void sortLastName();

void sortGpa();

studentsProc();

private:

studentInfo students[40];

int size;

void printList() const;

};

studentsProc::studentsProc()

{

size = 0;

}

void studentsProc::studentList()

{

cout << "0. Smith, Jefferey" << endl;

cout << "1. Lee, Jackson" << endl;

cout << "2. Gonzales, Mariana" << endl;

cout << "3. Jones, Mike" << endl;

cout << "4. Wiliams, Anita" << endl;

cout << "5. Ronsinson, Taylor" << endl;

cout << "6. Clark, Allen" << endl;

cout << "7. Turner, Tavon" << endl;

cout << "8. Jenkins, Nelson" << endl << endl;

}

void studentsProc::loadList()

{

ifstream infile;

infile.open("students.dat");

size = 0;

while (!infile.eof())

{

infile >> students[size].lastName;

infile >> students[size].firstName;

infile >> students[size].studentID;

infile >> students[size].email;

infile >> students[size].gpa;

size++;

}

infile.close();

}

void studentsProc::retrieveStudent()

{

int number;

studentsProc::studentList();

cout << "Please Enter the Position of the Student you Wish to Retrieve " << endl;

cin >> number;

{

cout << "Student Name: " << students[number].firstName << " " << students[number].lastName << endl;

}

}

void studentsProc::insertStudent()

{

int position;

cout << "Enter the Position of the New Student you Would Like to Add: " << endl;

cin >> position;

cout << endl;

cout << "Enter the Following Information About The Student: " << endl;

cout << "First Name: "; cin >> students[position].firstName;

cout << "Last Name: "; cin >> students[position].lastName;

cout << "Student ID: "; cin >> students[position].studentID;

cout << "E-Mail: "; cin >> students[position].email;

cout << "GPA: "; cin >> students[position].gpa;

cout << "The New List Is: " << endl;

studentsProc::displayStudent();

}

void studentsProc::deleteStudent()

{

}

void studentsProc::printStudent()

{

int number;

studentsProc::studentList();

cout << "Please Enter the Number of the Student's Record You Wish to View " << endl;

cin >> number;

{

cout << "First Name: " << students[number].firstName << " || "

<< "Last Name: " << students[number].lastName << " || "

<< "Student ID: " << students[number].studentID << " || "

<< "Student E-mail: " << students[number].email << " || "

<< "Student GPA: " << students[number].gpa << endl;

}

}

void studentsProc::displayStudent()

{

studentsProc::printList();

}

void studentsProc::printList() const

{

cout << "Student List" << endl;

for (int i = 0; i < size; i++)

{

cout << "Last Name: " << students[i].lastName << " || "

<< "First Name: " << students[i].firstName << " || "

<< "Student ID: " << students[i].studentID << " || "

<< "Student E-mail: " << students[i].email << " || "

<< "Student GPA: " << students[i].gpa << endl;

}

}

void studentsProc::sortLastName()

{

}

void studentsProc::sortGpa()

{

}

int main()

{

studentsProc student1;

student1.loadList();

int choice;

do

{

cout << "Please Choose an Option from this Menu" << endl << endl;

cout << "1. Retrieve and Print a Student from the Student List " << endl;

cout << "2. Insert a Student into the Student List " << endl;

cout << "3. Delete a Student from the Student List " << endl;

cout << "4. Print the Contents of a Student Record " << endl;

cout << "5. Print the Contents for a List of Students " << endl;

cout << "6. View the Students List Sorted by Last Name " << endl;

cout << "7. View the Students List Sorted by GPA " << endl;

cin >> choice;

cout << endl;

  

switch (choice)

{

case 1: student1.retrieveStudent();

break;

case 2: student1.insertStudent();

break;

case 3: student1.deleteStudent();

break;

case 4: student1.printStudent();

break;

case 5: student1.displayStudent();

break;

case 6: student1.sortLastName();

break;

case 7: student1.sortGpa();

break;   

default: cout << "Please enter a value 1-7" << endl;

}//end switch

cout << endl << endl;  

} while (choice != 7);

return 0;

}

Explanation / Answer

If you have any doubts, please give me comment...

#include <iostream>

#include <fstream>

#include <string>

#include <iomanip>

using namespace std;

struct studentInfo

{

string firstName;

string lastName;

unsigned int studentID;

string email;

float gpa;

};

class studentsProc

{

public:

void studentList();

void loadList();

void retrieveStudent();

void insertStudent();

void deleteStudent();

void printStudent();

void displayStudent();

void sortLastName();

void sortGpa();

studentsProc();

private:

studentInfo students[40];

int size;

void printList() const;

};

studentsProc::studentsProc()

{

size = 0;

}

void studentsProc::studentList()

{

cout << "0. Smith, Jefferey" << endl;

cout << "1. Lee, Jackson" << endl;

cout << "2. Gonzales, Mariana" << endl;

cout << "3. Jones, Mike" << endl;

cout << "4. Wiliams, Anita" << endl;

cout << "5. Ronsinson, Taylor" << endl;

cout << "6. Clark, Allen" << endl;

cout << "7. Turner, Tavon" << endl;

cout << "8. Jenkins, Nelson" << endl

<< endl;

}

void studentsProc::loadList()

{

ifstream infile;

infile.open("students.dat");

size = 0;

while (!infile.eof())

{

infile >> students[size].lastName;

infile >> students[size].firstName;

infile >> students[size].studentID;

infile >> students[size].email;

infile >> students[size].gpa;

size++;

}

infile.close();

}

void studentsProc::retrieveStudent()

{

int number;

studentsProc::studentList();

cout << "Please Enter the Position of the Student you Wish to Retrieve " << endl;

cin >> number;

{

cout << "Student Name: " << students[number].firstName << " " << students[number].lastName << endl;

}

}

void studentsProc::insertStudent()

{

int position;

cout << "Enter the Position of the New Student you Would Like to Add: " << endl;

cin >> position;

cout << endl;

cout << "Enter the Following Information About The Student: " << endl;

cout << "First Name: ";

cin >> students[position].firstName;

cout << "Last Name: ";

cin >> students[position].lastName;

cout << "Student ID: ";

cin >> students[position].studentID;

cout << "E-Mail: ";

cin >> students[position].email;

cout << "GPA: ";

cin >> students[position].gpa;

cout << "The New List Is: " << endl;

studentsProc::displayStudent();

}

void studentsProc::deleteStudent()

{

int position;

cout << "Enter the Position of the Student you Would Like to Delete: " << endl;

cin >> position;

for(int i=position;i<size-1; i++){

students[i] = students[i+1];

}

size--;

}

void studentsProc::printStudent()

{

int number;

studentsProc::studentList();

cout << "Please Enter the Number of the Student's Record You Wish to View " << endl;

cin >> number;

{

cout << "First Name: " << students[number].firstName << " || "

<< "Last Name: " << students[number].lastName << " || "

<< "Student ID: " << students[number].studentID << " || "

<< "Student E-mail: " << students[number].email << " || "

<< "Student GPA: " << students[number].gpa << endl;

}

}

void studentsProc::displayStudent()

{

studentsProc::printList();

}

void studentsProc::printList() const

{

cout << "Student List" << endl;

for (int i = 0; i < size; i++)

{

cout << "Last Name: " << students[i].lastName << " || "

<< "First Name: " << students[i].firstName << " || "

<< "Student ID: " << students[i].studentID << " || "

<< "Student E-mail: " << students[i].email << " || "

<< "Student GPA: " << students[i].gpa << endl;

}

}

void studentsProc::sortLastName()

{

for(int i=0; i<size; i++){

for(int j=i; j<size; j++){

if(students[i].lastName.compare(students[i].lastName)>0){

studentInfo temp = students[i];

students[i] = students[j];

students[j] = students[i];

}

}

}

printList();

}

void studentsProc::sortGpa()

{

for(int i=0; i<size; i++){

for(int j=i; j<size; j++){

if(students[i].gpa<students[j].gpa){

studentInfo temp = students[i];

students[i] = students[j];

students[j] = students[i];

}

}

}

printList();

}

int main()

{

studentsProc student1;

student1.loadList();

int choice;

do

{

cout << "Please Choose an Option from this Menu" << endl

<< endl;

cout << "1. Retrieve and Print a Student from the Student List " << endl;

cout << "2. Insert a Student into the Student List " << endl;

cout << "3. Delete a Student from the Student List " << endl;

cout << "4. Print the Contents of a Student Record " << endl;

cout << "5. Print the Contents for a List of Students " << endl;

cout << "6. View the Students List Sorted by Last Name " << endl;

cout << "7. View the Students List Sorted by GPA " << endl;

cin >> choice;

cout << endl;

switch (choice)

{

case 1:

student1.retrieveStudent();

break;

case 2:

student1.insertStudent();

break;

case 3:

student1.deleteStudent();

break;

case 4:

student1.printStudent();

break;

case 5:

student1.displayStudent();

break;

case 6:

student1.sortLastName();

break;

case 7:

student1.sortGpa();

break;

default:

cout << "Please enter a value 1-7" << endl;

} //end switch

cout << endl

<< endl;

} while (choice != 7);

return 0;

}