0% found this document useful (0 votes)
75 views6 pages

Student Grade Calculator in C++

This C++ program calculates student grades by taking student details as input, calculating the total marks, average, grade and result status. It uses a class with methods to input student details, calculate grade, and display the output. The main function takes the number of students as input, calls the input and display methods in a loop to get details from and display results for each student.

Uploaded by

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

Student Grade Calculator in C++

This C++ program calculates student grades by taking student details as input, calculating the total marks, average, grade and result status. It uses a class with methods to input student details, calculate grade, and display the output. The main function takes the number of students as input, calls the input and display methods in a loop to get details from and display results for each student.

Uploaded by

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

STUDENT GRADES

AIM

To calculate the grades of a list of students with attributes(Name, Roll no, Marks of
3 subjects) using class with member functions input(), calcGrade(), display()

PROGRAM

#include <iostream>
using namespace std;

int p;
class student
{
int Roll_no;
char Name[40];
int subject1;
int subject2;
int subject3;
int total_marks;
char grade;
float avg;
string status;

public:
void input();
void display();
void calcGrade();
};

void student::input()

cout << "\n\nEnter name of the student" << endl;

cin >> Name;


cout << "Enter roll no of the student" << endl;

cin >> Roll_no;


cout<<"\n_____________________________________";

cout << "\nEnter marks for subject 1 out of 100" << endl;

cin >> subject1;

cout << "Enter marks for subject 2 out of 100" << endl;

cin >> subject2;

cout << "Enter marks for subject 3 out of 100" << endl;

cin >> subject3;


cout<<"\n\n_____________________________________";

void student::calcGrade()
{
total_marks = (subject1 + subject2 + subject3);
avg=total_marks/3;
if (avg>=90)

{grade = ’A’;
status="PASS";
}
else if (avg<90 && avg>=70)

{grade = ’B’;
status="PASS";
}
else if(avg<70 && avg>=50)

{grade = ’C’;

2
status="PASS";
}
else
{grade=’F’;
status="FAIL";
}
}

void student::display()
{
cout << "\n\n*********Displaying details of student************";
cout << "\n\nName of student:" << Name << endl;
cout << "Roll no of student:" << Roll_no << endl;
cout << "Marks for subject1 out of 100- " << subject1 << endl;
cout << "Marks for subject2 out of 100- " << subject2 << endl;
cout << "Marks for subject3 out of 100- " << subject3 << endl;
cout<<"\n\n_____________________________________________________";

calcGrade();
cout<<"\n\n_____________________________________________________";
cout << "\nTotal marks of student out of 300:" << total_marks << endl;
cout<<"Average marks of student:"<<avg<<endl;
cout << "Grade of student:" << grade << endl;
cout<<"Status:"<<status<<endl;
}

int main()

{
cout<<"\n\n\n****************WELCOME********************";
cout << "\n\nEnter number of students whose details should be taken:";
cin >> p;
student S[p] ;

for (int i = 0; i < p; i++)

3
{
cout<<"\n\n______________________________________________________";
cout << "\nEnter details of student " << i + 1 << ":" << endl;

S[i].input();
}

for (int i = 0; i < p; i++)

{
S[i].display();

}
cout <<"\n\n*******************Thank you************************"<<endl;

return 0;

4
SAMPLE INPUT-OUTPUT

5
6

Common questions

Powered by AI

Using an array of objects is an effective choice for handling multiple students, as it allows the program to easily manage multiple instances of the student data structure with fixed size. This approach also facilitates streamlined input and output operations through iteration. However, it limits the program's ability to dynamically handle a variable number of students at runtime, potentially leading to memory inefficiencies if the number of students isn't known beforehand. An alternative could involve dynamic memory allocation using lists or vectors to handle any number of student records effectively.

To enhance usability, the program could incorporate input validation to ensure correct data types and meaningful error messages for invalid entries. Implementing a user interface with more interactive prompts or even a graphical interface could improve user interaction. Moreover, incorporating features like summary statistics or easy navigation between student records could enhance the user experience significantly.

To modify the program to handle more than three subjects, parameters related to subjects (such as input variables in the class, subject1, subject2, and subject3) could be replaced with an array or a dynamic data structure like a vector to store an arbitrary number of subject marks. Changes would include modifying the input() function to dynamically accept subject scores, iterating over these scores in calcGrade() to compute total marks, and adjusting the logic for average mark calculation accordingly. This allows flexibility and scalability.

The program calculates the total marks for each student by summing the scores from three subjects using the formula: total_marks = (subject1 + subject2 + subject3). To find the average, it divides the total marks by 3, expressed as avg = total_marks/3.

The calcGrade() function is crucial for the program's functionality as it calculates the total marks, average, and determines the grade and status based on conditions. It is invoked within display(), ensuring that grades and status are calculated and updated before the display of information. This encapsulation within display() maintains cohesion and modularity, ensuring input data is processed and evaluated seamlessly.

The program uses 'cout' statements to display prompts and instructions in the console, guiding users to enter necessary details. It uses 'cin' statements to capture user input for the student's name, roll number, and subject marks. The 'cout' statements are again used in the display function to show the calculated grades, total and average marks, and status of each student.

In the student class, private access specifiers safeguard data members such as Roll_no, Name, subject marks, and computed grades, restricting direct access from outside the class. These attributes can only be manipulated through public member functions like input(), calcGrade(), and display(), ensuring controlled access and maintaining encapsulation within the class structure.

The program assigns grades based on the average marks calculated. If the average is greater than or equal to 90, it assigns an 'A' grade and marks the student's status as 'PASS'. For averages between 70 and 89 inclusive, the grade is 'B', and the status is 'PASS'. Averages from 50 to 69 result in a 'C' grade and a 'PASS' status. Averages below 50 receive an 'F' grade and a 'FAIL' status.

The program uses an array of 'student' objects to process multiple records. It first takes the total number of students (p) as input, and then repeatedly calls the input() method for each student object to gather student details. Following this, the program iteratively calls the display() method to process and show grades for each student. This array-based approach allows the program to handle and display information for multiple students.

To implement a summary report functionality, an additional method could be introduced to iterate over all student objects, collecting data on grade distributions and average scores. This method could compute statistics such as the number of students per grade category, overall pass/fail rates, and class averages. Introducing an additional data structure to hold these statistics could facilitate outputting a comprehensive summary, providing insights at the end of the program.

You might also like