0% found this document useful (0 votes)
23 views

CPP 1

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)
23 views

CPP 1

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
You are on page 1/ 6

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

You might also like