Need some help and hints for writing C++ program. C++ program has to store a lis
ID: 3886389 • Letter: N
Question
Need some help and hints for writing C++ program. C++ program has to store a list of names in a class along with their grades. Then it should grant acces for the user to carry out the following functions.
1) Sorting the date by name in alphabetical order
2) It should sort the data by grade of increasing order
3) Searches for a grade for the student whos name was entered by the user
4) It should find the names of students who have a certain grade or over.
Once the program runs it should display the above items like similar to a menu, It will require the user to select an item by typing a number. It should obtain any additonal information needed from the user to carry out the task.
Use the list given below along with your own name and a grade you choose as the data.
Simmons 93
Rogers 68
Trueman 87
Roberts 98
Myers 45
Kinney 82
Baar 88
Lennon 75
Cohen 90
Wallah 62
Vernon 78
Please show step by step on how to write this program.
Explanation / Answer
Bubble sort and structure used:
#include<iostream>
#include<cstring>
using namespace std;
class student {
struct student_info {
string name;
int marks;
};
private:
student_info* data;
int n;
public:
void sort_marks() {
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < n - i - 1; j++)
if (data[j].marks > data[j+1].marks) {
student_info tmp = data[j];
data[j] = data[j+1];
data[j+1] = tmp;
}
}
void sort_name() {
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < n - i - 1; j++)
if (strcmp(data[i].name.c_str(), data[i+1].name.c_str()) > 0) {
student_info tmp = data[j];
data[j] = data[j+1];
data[j+1] = tmp;
}
}
void print() {
for (int i = 0; i < n ; i++)
std::cout << data[i].name << " " << data[i].marks << endl;
}
student() {
std::cout << "Enter number of students: ";
std::cin >> n;
data = new student_info[n];
std::cout << "Enter name and marks of students: ";
for (int i = 0; i < n; i++) {
cin >> data[i].name;
cin >> data[i].marks;
}
}
};
int main() {
student s;
cout << "Original" <<endl;
s.print();
s.sort_marks();
cout << "marks sorted" <<endl;
s.print();
s.sort_name();
cout << "name sorted" <<endl;
s.print();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.