Menu)
In an infinite loop, provide the user the following options:
A) Save student information (Assume there will not be more than eleven students)
B) Display information of all students
C) Search the student by id and display only that student's information
D) Calculate and display the average course marks of the entire class
E) Display the information of all the students who have a GPA more than x (x is a value entered by the user)
F) Quit.
To select an option, the user would either input A, or B, or C, or D, or E, or F. For any input other than these, the user would be told “Invalid choice” and the menu will be displayed again.
RUN THE CODE ONCE AND ATTACH A SCREENSHOT OF THE MENU IN YOUR WORD DOCUMENT
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
cout << "|||| Menu ||||\n";
cout << "A) Save student information (Assume there will not be more than eleven students)\n";
cout << "B) Display information of all students\n";
cout << "C) Search the student by id and display only that student's information\n";
cout << "D) Calculate and display the average course marks of the entire class\n";
cout << "E) Display the information of all the students who have a GPA more than x (x is a value entered by the user)\n";
cout << "F) Quit.\n";
int n = 2;
string studentNames[n];
int studentIds[n];
float courseMarks[n], studentGPA[n];
char option;
while (true) {
cout << "\nSelect your choice: \n";
cin >> option;
if (option == 'A') {
for (int i = 0; i < n; i++) {
cout << "\nEnter " << i + 1 << " - student information: \n";
string name;
cout << "student name: "; cin >> name;
studentNames[i] = name;
int id;
cout << "student id: "; cin >> id;
studentIds[i] = id;
float mark;
cout << "student course mark: "; cin >> mark;
courseMarks[i] = mark;
float gpa;
cout << "student gpa: "; cin >> gpa;
studentGPA[i] = gpa;
}
}
else if (option == 'B') {
cout << setw(20) << "studentName" << setw(20) << "studentIds" << setw(20) << "CourseMarks" << setw(20) << "studentGPA\n";
for (int i = 0; i < n; i++) {
cout << setw(20) << studentNames[i] << setw(20) << studentIds[i] << setw(20) << courseMarks[i] << setw(20) << studentGPA[i] << endl;
}
}
else if (option == 'C') {
int searchId, t = 0;
cout << "Enter Id for search: "; cin >> searchId;
for (int i = 0; i < n; i++) {
if (studentIds[i] == searchId) {
cout << setw(20) << studentNames[i] << setw(20) << studentIds[i] << setw(20) << courseMarks[i] << setw(20) << studentGPA[i] << endl;
}
}
if (t == n) {
cout << "Not found!" << endl;
}
}
else if (option == 'D') {
float avarageCourseMarks = 0, avarageCourseGPA = 0;
for (int i = 0; i < n; i++) {
avarageCourseMarks += courseMarks[i];
avarageCourseGPA += studentGPA[i];
}
cout << "avarageCourseMarks: " << avarageCourseMarks / n << endl;
cout << "avarageCourseGPA: " << avarageCourseGPA / n << endl;
}
else if (option == 'E') {
int x;
cout << "Enter x (max GPA = 5): "; cin >> x;
for (int i = 0; i < n; i++) {
if (studentGPA[i] >= x) {
cout << setw(20) << studentNames[i] << setw(20) << studentIds[i] << setw(20) << courseMarks[i] << setw(20) << studentGPA[i] << endl;
}
}
}
else if (option == 'F') {
break;
}
else {
cout << "Invalid choice.\n";
cout << "|||| Menu ||||\n";
cout << "A) Save student information (Assume there will not be more than eleven students)\n";
cout << "B) Display information of all students\n";
cout << "C) Search the student by id and display only that student's information\n";
cout << "D) Calculate and display the average course marks of the entire class\n";
cout << "E) Display the information of all the students who have a GPA more than x (x is a value entered by the user)\n";
cout << "F) Quit.\n";
}
}
return 0;
}
Comments
Leave a comment