Write a C++ program to declare a class student with members as roll no, name and department. Declare a parameterized constructor with default value for department as ‘CO’ to initialize members of object. Initialize and display data for two students.
#include<iostream.h>
#include<conio.h>
#include<string.h>
class student
{
int roll_no;
char name[20],department[40];
public:
student(int rno,char *n,char *d="CO")
{
roll_no=rno;
strcpy(name,n);
strcpy(department,d);
}
void display()
{
cout<<"\n Roll No:"<<roll_no;
cout<<"\n Name:"<<name;
cout<<"\n Department:"<<department;
}
};
void main()
{
student s1(112," Chitrakshi"),s2(114,"Anjali");
clrscr();
s1.display();
s2.display();
getch();
}