Create a simple class in C++ for representing student and add attributes like name, rollno, address, marks and create a method to calculate the grade and display the details of student. - WAY2IT

Latest Post :

Create a simple class in C++ for representing student and add attributes like name, rollno, address, marks and create a method to calculate the grade and display the details of student.



Code :-

#include<conio.h>
#include<iostream.h>
#include<string.h>
class Student
{
private:
int Rollno;
char name[10];
char Grade;
public:
char div;
int std;

Student()
{
Rollno=1;
strcpy(name,"Ajay");
Grade='B';
div='C';
std=11;
}
Student(int r,char n[10])
{
Rollno=r;
strcpy(name,n);
Grade='B';
div='C';
std=11;
}
Student(int r,char n[10],char g,char d,int s)
{
Rollno=r;
strcpy(name,n);
Grade=g;
div=d;
std=s;
}
void display()
{
cout<<"\nRoll Number:"<<Rollno<<endl;
cout<<"name:"<<name<<endl;
cout<<"Grade:"<<Grade<<endl;
cout<<"Division:"<<div<<endl;
cout<<"Standard:"<<std<<endl;
}
};
void main()
{
Student std1(1,"prachi",'A','A',14),std2(2,"raju"),std3;
clrscr();
std1.display();
std2.display();
std3.display();
getch();
}


Output :-