Answer to Question #5899 in C++ for hhhhhhhhhhhhh

Question #5899
write the programme in c++ that do so mainy thing:
1) Search for student by ID:system asks for student ID, if ID is valid, student’s name and his grade are displayed.
2)Search for Student by name:systems asks for student’s name, then it displays all students with that name, it displays ID, name, grades.
3)Search for students according to the average:system asks user to enter an average then it displays students whose average is equal or greater than that number (displays id, name, all grades, average).
1
Expert's answer
2012-01-06T07:10:41-0500
#include <iostream>
#include <string>
using namespace std;

struct student {
string name;
int id;
int grade;
student* next;
};

void AddStudent(student* &list) {
string _name;
int _id;
int _grade;
cout << "Enter the student's name: ";
cin >> _name;
cout << "Enter the student's ID: ";
cin >> _id;
cout << "Enter the student's grade: ";
cin >> _grade;
cout << endl;
student* temp = new student;
temp->name = _name;
temp->id = _id;
temp->grade = _grade;
temp->next = list;
list = temp;
cout << "Student added.\n\n";
system("pause");
};

void SearchByName(student* list) {
if (list == NULL) cout << "There are no students in current database.\n\n";
else {
& string _name;
& cout << "Enter the name: ";
& cin >> _name;
& cout << endl;
& bool found = false;
& while (list!=NULL) {
& if (list->name == _name) {
& cout << "Name: " << list->name << "\nID: " << list->id << "\nGrade: " << list->grade << endl << endl;
& found = true;
& };
& list = list->next;
& };
& if (!found) cout << "No students found.\n\n";
};
system("pause");
};

void SearchByID(student* list) {
if (list == NULL) cout << "There are no students in current database.\n\n";
else {
& int _id;
& cout << "Enter the ID: ";
& cin >> _id;
& cout << endl;
& bool found = false;
& while (list!=NULL) {
& if (list->id == _id) {
& cout << "Name: " << list->name << "\nID: " << list->id << "\nGrade: " << list->grade << endl << endl;
& found = true;
& };
& list = list->next;
& };
& if (!found) cout << "No students found.\n\n";
};
system("pause");
};

void SearchByAverage(student* list) {
if (list == NULL) cout << "There are no students in current database.\n\n";
else {
& int _grade;
& cout << "Enter the average: ";
& cin >> _grade;
& cout << endl;
& bool found = false;
& cout << "Students whose grade is equal or greater:\n";
& while (list!=NULL) {
& if (list->grade >= _grade) {
& cout << "Name: " << list->name << "\nID: " << list->id << "\nGrade: " << list->grade << endl << endl;
& found = true;
& };
& list = list->next;
& };
& if (!found) cout << "No students found.\n\n";
};
system("pause");
};

int MenuChoice() {
cout << "Choose your action:\n1) Enter new student\n2) Search student by ID\n3) Search student by name\n" <<
& quot;4) Search students by average\n5) Exit\n";
int a;
cin >> a;
cout << endl;
return a;
};

int main() {
student* list = new student;
list = NULL;
bool flag = true;
while (flag) {
& switch (MenuChoice()) {
& case 1:
& AddStudent(list);
& break;
& case 2:
& SearchByID(list);
& break;
& case 3:
& SearchByName(list);
& break;
& case 4:
& SearchByAverage(list);
& break;
& case 5:
& flag = false;
& break;
& };
};
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS