Write a C++ program using classes and object to simulate result preparation system for 20 students. The data available for each student include roll no, name and marks in three subject. The percentage marks and grade are to be calculated from the above information. The percentage marks are the average marks and the grade is calculated as follows:

% Marks Grade

<50 'F

>50<60 ‘D’

>60<75 'C'

>75<90 'B'

>=90<100 ‘A’


 Here is a C++ program that simulates a result preparation system for 20 students using classes and objects. The program calculates the percentage marks and assigns grades based on the given criteria:


#include <iostream> #include <string> #include <vector> using namespace std; class Student { private: int rollNo; string name; float marks[3]; float percentage; char grade; void calculatePercentage() { float total = 0; for (int i = 0; i < 3; ++i) { total += marks[i]; } percentage = total / 3; } void calculateGrade() { if (percentage < 50) { grade = 'F'; } else if (percentage >= 50 && percentage < 60) { grade = 'D'; } else if (percentage >= 60 && percentage < 75) { grade = 'C'; } else if (percentage >= 75 && percentage < 90) { grade = 'B'; } else if (percentage >= 90 && percentage <= 100) { grade = 'A'; } else { grade = 'I'; // Invalid } } public: void inputDetails() { cout << "Enter roll number: "; cin >> rollNo; cout << "Enter name: "; cin.ignore(); getline(cin, name); for (int i = 0; i < 3; ++i) { cout << "Enter marks for subject " << i + 1 << ": "; cin >> marks[i]; } calculatePercentage(); calculateGrade(); } void displayDetails() const { cout << "Roll No: " << rollNo << endl; cout << "Name: " << name << endl; cout << "Marks: "; for (int i = 0; i < 3; ++i) { cout << marks[i] << " "; } cout << endl; cout << "Percentage: " << percentage << "%" << endl; cout << "Grade: " << grade << endl; } }; int main() { vector<Student> students(20); for (int i = 0; i < 20; ++i) { cout << "Enter details for student " << i + 1 << ":\n"; students[i].inputDetails(); } cout << "\nStudent Results:\n"; for (int i = 0; i < 20; ++i) { cout << "\nDetails for student " << i + 1 << ":\n"; students[i].displayDetails(); } return 0; }


Comments

Popular posts from this blog

Multipath inheritance :There are 2 Ways to Avoid this Ambiguity:

Reading name, post and salary of 10 different employees and displaying those records whose salary is greater than 10000 using user defined function c++