50% found this document useful (14 votes)
34K views3 pages

Write a C++ Program to display Names, Roll No., and grades of 3 students who have appeared in the examination. Declare the class of name, Roll No. and grade. Create an array of class objects. Read and display the contents of the array.

The C++ program declares a class called "student" with data members for name, roll number, and total marks. It defines member functions to read student details, calculate grade based on percentage, and print student details. The main function creates an array of student objects, reads details for n students using a for loop, and then prints details and grade for each student using another for loop.

Uploaded by

Vasuda Gurram
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
50% found this document useful (14 votes)
34K views3 pages

Write a C++ Program to display Names, Roll No., and grades of 3 students who have appeared in the examination. Declare the class of name, Roll No. and grade. Create an array of class objects. Read and display the contents of the array.

The C++ program declares a class called "student" with data members for name, roll number, and total marks. It defines member functions to read student details, calculate grade based on percentage, and print student details. The main function creates an array of student objects, reads details for n students using a for loop, and then prints details and grade for each student using another for loop.

Uploaded by

Vasuda Gurram
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
You are on page 1/ 3

1) Write a C++ program to display Names, Rollno and Grades of 3 students who have

appeared in the examination. Declare the class of name, rollno and Grade. Create an array
of class objects. Read and Display the contents of the Array.

#include <iostream>

using namespace std;

class student

char name[50];

int rollno;

int total;

public:

void readDetails(void); //member function to get student details

void gradeCal(void); //member function to display Grade

void printDetails(void); // member function to print student details

};

//member function definition outside the class

void student::readDetails(void)

cout<<"Enter Name: ";

cin>>name;

cout<<"\n Enter Roll no: ";

cin>>rollno;

cout<<"\n Enter total marks out of 500: ";

cin>>total;
}

void student::gradeCal(void)

float percentage;

percentage=(float)total/500.00*100.00;

cout<<percentage<<"%\n";

if(percentage>=75.00)

{cout<<"Grade: A \n";}

else{ if((percentage>=60.00)&&(percentage<75.00))

{cout<<"Grade: B \n";}

else{ if((percentage>=40.00)&&(percentage<60.00))

{cout<<"Grade: C \n";}

else

{cout<<"Grade: D \n";}

}}

//member function definition outside the class

void student::printDetails(void)

cout<<"Student Details: \n";

cout<<"Name: "<<name<<endl;

cout<<"Rollnumber "<<rollno<<endl;

cout<<"Total: "<<total<<endl;

}
int main()

student std[10]; //array of objects creation

int n, i;

cout<<"Enter total number of students:";

cin>>n;

for(i=0; i<n; i++)

cout<<"Enter details of student "<<i+1<<"\n";

std[i].readDetails();

for(i=0; i<n; i++)

cout<<"Details of student "<<i+1<<"\n";

std[i].printDetails();

std[i].gradeCal();

return 0;

You might also like