Monday, February 18, 2013

OOCP (CPP) : Example # 02 : How to Set Precision in C++

OOCP (CPP)  :  Example # 02 : How to Set Precision in C++

* Lets start learning CPP (C++) Using Example.
* Program is about how to set precision in c++

//Written by Latest Technology Guide    
//Title : OOCP (CPP)  :  Example # 
02 : How to Set Precision in 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:

* By writing setprecision(4) precision will be set to 4.
--------------------------------------------------------------------------------
OOCP (CPP)  :  Example # 02 : How to Set Precision in C++.

* Simply change precision as per your requirement and run again
.

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. 

1 comment: