Question
Use two sort algorith for previous program (3) : a. Bubble Sort to sort student's name. c. Selection Sort to sort Student's letter grade Then
Use two sort algorith for previous program (3) :
a. Bubble Sort to sort student's name.
c. Selection Sort to sort Student's letter grade
Then use a search methode (linear search, or binary search) to look for specific record in this program
Here is the previous program that needs sort algorithms
#include
#include
#include
using namespace std;
class Student
{
private:
string studentFName;
string studentLName;
int testScore;
char grade;
public:
Student(string fname = "", string lname = "", int score=0)
{
studentFName = fname;
studentLName = lname;
testScore = score;
grade = ' ';
}
string getFName() { return studentFName; }
string getLName() { return studentLName; }
int getScore() { return testScore; }
char getGrade() { return grade; }
void setFName(string fname) { studentFName = fname; }
void setLName(string lname) { studentLName = lname; }
void setScore(int score) { testScore = score; }
void setGrade(char g) { grade = g; }
};
void readData(vector
{
int n;
cout << "Enter the number of students: ";
cin >> n;
for (int i = 0; i < n; i++)
{
string fname, lname;
int score;
cout << "Enter student " << i + 1 << " first name: ";
cin >> fname;
cout << "Enter student " << i + 1 << " last name: ";
cin >> lname;
cout << "Enter student " << i + 1 << " test score: ";
cin >> score;
Student student(fname, lname, score);
students.push_back(student);
}
}
// Function to assign grades **PROCESS**
void assignGrades(vector
{
for (int i = 0; i < students.size(); i++)
{
if (students[i].getScore() >= 90)
{
students[i].setGrade('A');
}
else if (students[i].getScore() >= 80)
{
students[i].setGrade('B');
}
else if (students[i].getScore() >= 70)
{
students[i].setGrade('C');
}
else if (students[i].getScore() >= 60)
{
students[i].setGrade('D');
}
else {
students[i].setGrade('F');
}
}
}
int findHighestScore(vector
{
int highestScore = 0;
for (int i = 0; i < students.size(); i++)
{
if (students[i].getScore() > highestScore)
{
highestScore = students[i].getScore();
}
}
return highestScore;
}
// Function to print students with highest score **OUTPUT**
void printStudentsWithHighestScore(vector
{
cout << endl << "Student(s) with the highest score of " << highestScore << ":" << endl << endl;
for (int i = 0; i < students.size(); i++)
{
if (students[i].getScore() == highestScore)
{
cout << students[i].getLName() << ", " << students[i].getFName() << endl << endl << "Letter Grade: " << students[i].getGrade() << endl << endl;
}
}
}
int main()
{
vector
readData(students);
assignGrades(students);
int highestScore = findHighestScore(students);
printStudentsWithHighestScore(students, highestScore);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started