Showing posts with label object class. Show all posts
Showing posts with label object class. Show all posts

Saturday, 19 November 2011

Classes and objects


In the following program S1 and S2 are 2 objects are class students. Objects are used for operations:


class student //class student
{
private:
int roll;
public:
void setdata(int r) //member function to setdata
{roll=r;}
void showdata(); //member function to display data
{cout<<roll no. is= "<<roll<<endl;} //use printf(""); in C instead of cout<<;
};

void main()\
{
clrscr();

student s1,s2;              //define two objects of class student

s1.setdata(9); //call member function to set data
s2.setdata(10);

s1.showdata(); //call member function to display data
s2.showdata();
getch();
}