133,560 views
5 votes
5 votes
Write a programmimg code in c++ for school based grading system, the program should accept the subject in the number of students from a user and store their details in the array of type student(class) the student class you have:

1. number student name, index number remarks as variables of type string, marks as integer and grade as char.
2. avoid function called getData which is used to get student details
3. avoid function called calculate which will work on the marks and give the corresponding great and remarks as given below on
Marks 70-100 grade A remarks excellent Mark 60-69 Grade B remarks very good marks 50-59 grade C remarks pass maths 0-49 grade F remarks fail​

User Nitish Kumar
by
2.5k points

1 Answer

30 votes
30 votes

Answer:

The program is as follows:

#include <iostream>

#include <string>

using namespace std;

class Student{

string studName, indexNo, remarks; int marks; char grade;

public:

void getData(){

cin.ignore();

cout<<"ID: "; getline(cin,indexNo);

cout<<"Name:"; getline(cin,studName);

cout<<"Marks: ";cin>>marks; }

void calculate(){

if(marks>=70 && marks<=100){

remarks ="Excellent"; grade = 'A'; }

else if(marks>=60 && marks<=69){

remarks ="Very Good"; grade = 'B'; }

else if(marks>=50 && marks<=59){

remarks ="Pass"; grade = 'D'; }

else{

remarks ="Fail"; grade = 'F'; }

cout << "Grade : " << grade << endl;

cout << "Remark : " << remarks << endl; }

};

int main(){

int numStudents;

cout<<"Number of students: "; cin>>numStudents;

Student students[numStudents];

for( int i=0; i<numStudents; i++ ) {

cout << "Student " << i + 1 << endl;

students[i].getData();

students[i].calculate(); }

return 0;}

Step-by-step explanation:

This defines the student class

class Student{

This declares all variables

string studName, indexNo, remarks; int marks; char grade;

This declares function getData()

public:

void getData(){

cin.ignore();

Prompt and get input for indexNo

cout<<"ID: "; getline(cin,indexNo);

Prompt and get input for studName

cout<<"Name:"; getline(cin,studName);

Prompt and get input for marks

cout<<"Marks: ";cin>>marks; }

This declares funcion calculate()

void calculate(){

The following if conditions determine the remark and grade, respectively

if(marks>=70 && marks<=100){

remarks ="Excellent"; grade = 'A'; }

else if(marks>=60 && marks<=69){

remarks ="Very Good"; grade = 'B'; }

else if(marks>=50 && marks<=59){

remarks ="Pass"; grade = 'D'; }

else{

remarks ="Fail"; grade = 'F'; }

This prints the grade

cout << "Grade : " << grade << endl;

This prints the remark

cout << "Remark : " << remarks << endl; }

};

The main begins here

int main(){

This declares number of students as integer

int numStudents;

Prompt and get input for number of students

cout<<"Number of students: "; cin>>numStudents;

This calls the student object to declare array students

Student students[numStudents];

This is repeated for all students

for( int i=0; i<numStudents; i++ ) {

Print number

cout << "Student " << i + 1 << endl;

Call function to get data

students[i].getData();

Call function to calculate

students[i].calculate(); }

return 0;}

User Christian Lescuyer
by
2.9k points