Program for class and object in C++
#include <iostream.h>
#include<conio.h> // Header files
class Student // Class declaration and definition
{
public:
char name[30], clas[10];
int roll, age;
void enter()
{
cout<<"Enter Student Name: "; cin>>name;
cout<<"Enter Student Age: "; cin>>age;
cout<<"Enter Student Roll number: "; cin>>roll;
cout<<"Enter Student Class: "; cin>>clas;
}
void display()
{
cout<<"\n Age\tName\tR.No.\tClass";
cout<<"\n"<<age<<"\t"<<name<<"\t"<<roll<<"\t"<<clas;
}
};
void main() // Main function
{
clrscr();
class Student s; // Object created
s.enter();
s.display();
cin.get();
getch();
}
OUTPUT:-
0 Comments
Have any query? Want any type of module?
Please comment it down and let me know.