Monday, February 18, 2013

OOCP (CPP) : Example # 03 : Class Example using C++

OOCP (CPP)  :  Example # 03 : Class Example using C++

* Lets start learning CPP (C++) Using Example.

* Simple class creation using C++

//Written by Latest Technology Guide    
//Title : OOCP (CPP)  :  Example # 
03 : Class Example using C++


#include <iostream.h>
#include <iomanip.h>
#include <conio.h>

#define PI 3.1415

class area
{
private :
int r;
public :
void getdata()
{
cout << "Enter Value of R : ";
cin >> r;
cal_display();
}
private :
void cal_display()
{
float area;
area = PI * r * r;
cout << "Area of the Circle is : " << setprecision(4) << area;
}
};

void main()
{
clrscr();
area obj;
obj.getdata();
getch();
}

Output:

* you will find output as : Area of Circle is : ??? 


--------------------------------------------------------------------------------
OOCP (CPP)  :  Example # 03 : Class Example using C++.

* Example shows how to create class and methods in C++.
* Here we have created object of class area. 
* we have called method of the class using object..


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

No comments:

Post a Comment