0% found this document useful (0 votes)
12 views5 pages

Student Grades Management Program

The document contains a C++ program that manages student records, allowing users to input quiz scores, view grades for individual students or all students, and ensures a minimum of three students are recorded. It includes a structure for students with methods to calculate average scores and validate input. The program runs in a loop, providing options for the user until they choose to exit.

Uploaded by

eugenepabol2020
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

Student Grades Management Program

The document contains a C++ program that manages student records, allowing users to input quiz scores, view grades for individual students or all students, and ensures a minimum of three students are recorded. It includes a structure for students with methods to calculate average scores and validate input. The program runs in a loop, providing options for the user until they choose to exit.

Uploaded by

eugenepabol2020
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#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;

You might also like