Class And Object In C++ Example Program

Class And Object In C++ Example Program

Class And Object In C++ Example Program




Class And Object In C++ Example Program


Class And Object In C++ Example Program


It has two types
    scope resolution operator - symbol - ::
1. classes and object without scope resolution operator
2. classes and object with scope resolution operator

Scope resolution operator - symbol - ::

#include<iostream.h>
#include<conio.h>
int a=5000;
void main()
{
int a;
clrscr();
cout<<"Enter the value of a is:"<<endl;
cin>>a;
cout<<"The local variable of a is:"<<a<<endl;
cout<<"The global variable of ::a is:"<<::a<<endl;
getch();
}

Classes and Object without scope resolution operator

#include<iostream.h>
#include<conio.h>
class arun
{
public:
char name [20];
int age;
void getdata()
{
cout<<"Enter the name and age is:"<<endl;
cin>>name>>age;
}
void putdata()
{
cout<<"The given name is:"<<name<<endl;
cout<<"The given age is:"<<age<<endl;
}
}
void main()
{
arun a;
clrscr();
a.getdata();
a.putdata();
getch();
}

Classes and Object with scope resolution operator

#include<iostream.h>
#include<conio.h>
class arun
{
public:
char name [20];
int age;
void getdata();
void putdata();
};
void arun::getdata()
{
cout<<"Enter the name and age is:"<<endl;
cin>>name>>age;
}
void arun::putdata()
{
cout<<"The given name is:"<<name<<endl;
cout<<"The given age is:"<<age<<endl;
}
void main()
{
arun a;
clrscr();
a.getdata();
a.putdata();
getch();

}

Post a Comment

0 Comments