#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct Student {
string name;
int scores[100];
int scoreCount;
double calculateAverage() {
if (scoreCount == 0) return 0.0;
int total = 0;
for (int i = 0; i < scoreCount; ++i) {
total += scores[i];
return static_cast<double>(total)/ scoreCount;
};
void inputQuizScores(Student students[], int studentCount) {
int totalItems;
cout << "\nEnter the total number of quiz items: ";
cin >> totalItems;
for (int i = 0; i < studentCount; ++i) {
int score;
while (true) {
cout << "Enter the score of " << students[i].name << ": ";
cin >> score;
if (score >= 0 && score <= totalItems) {
students[i].scores[students[i].scoreCount++] = (score * 100) / totalItems;
break;
} else {
cout << "Invalid score! Please enter a score between 0 and " << totalItems << ".\n";
void viewGrades(Student students[], int studentCount) {
cout << "\nGrades of all students:\n";
for (int i = 0; i < studentCount; ++i) {
cout << "Name: " << students[i].name
<< "\nAverage Grade: " << fixed << setprecision(0)
<< students[i].calculateAverage()<<"%"<<endl;
void oneStudent(Student students[], int studentCount) {
string studentName;
cout << "\nEnter the name of the student: ";
[Link]();
getline(cin, studentName);
for (int i = 0; i < studentCount; ++i) {
if (students[i].name == studentName) {
cout << "Name: " << students[i].name << endl;
cout << "Grades: "<< fixed << setprecision(0)
<< students[i].calculateAverage()<<"%"<<endl;
return;
cout << "Student not found." << endl;
int main() {
Student students[100];
int studentCount;
cout << "----------------------- STUDENT RECORD PROGRAM----------------------------\n\n";
do {
cout << "Please enter the number of students to record (minimum 3 students): \n";
cin >> studentCount;
[Link]();
if (studentCount < 3) {
cout << "You need to enter at least 3 students. Please try again.\n";
} while (studentCount < 3);
for (int i = 0; i < studentCount; ++i) {
cout << "Enter name of student " << i + 1 << ": ";
getline(cin, students[i].name);
while (true) {
cout << "\nOptions:\n";
cout << "1. View Grades\n";
cout << "2. Input Quiz Scores\n";
cout << "3. EXIT PROGRAM\n";
cout << "Enter your choice: ";
int choice;
cin >> choice;
switch (choice) {
case 1: {
cout << "1. View grades of one student.\n2. View grades of all the students.\n";
int option;
cin >> option;
if (option == 1) {
oneStudent(students, studentCount);break;
} else if (option == 2) {
viewGrades(students, studentCount);
} else {
cout << "Invalid option. Returning to main menu.\n";
break;
case 2:
inputQuizScores(students, studentCount);
break;
case 3:
cout << "Exiting program. Goodbye!" << endl;
return 0;
default:
cout << "Invalid choice. Please try again." << endl;
return 0;