C++ | Area conversion

Introduction

These program will convert area from one unit to another. The first one lets you convert meter sq. to centimeter sq. . The next one lets you convert Centimeter sq.  to Millimeter sq. . And the third one lets you convert Meter sq. to Acre. The fourth program will convert Meter sq.  to Hectare . So you can convert more units of area by just adding the conversion formula to it.Go enjoy the program. Lets begin……..

Program to convert Meter sq. to Centimeter sq.

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,b;
//Input the area in given unit save them in 'a'
cout<<"Enter the Area in Meter sq."<<endl;
cin>>a;
//convert and save it in 'b'
b=a*10000;
//show the output 'b'
cout<<"Area in Centimeter sq. is "<<b;
//get character
getch();
}

Output

Enter the Area in Meter sq.
2
Area in Centimeter sq. is 20000

Program for Conversion of Centimeter sq. to Millimeter sq.

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,b;
//Input the area in given unit save them in 'a'
cout<<"Enter the Area in Centimeter sq."<<endl;
cin>>a;
//convert and save it in 'b'
b=a*100;
//show the output 'b'
cout<<"Area in Millimeter sq. is "<<b;
//get character
getch();
}

Output

Enter the Area in Centimeter sq.
34
Area in Centimeter sq. is 3400

Program for Conversion of Meter sq. to Acre

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,b;
//Input the area in given unit save them in 'a'
cout<<"Enter the Area in Meter sq."<<endl;
cin>>a;
//convert and save it in 'b'
b=a/4046.873;
//show the output 'b'
cout<<"Area in Acre is "<<b;
//get character
getch();
}

Output

Enter the Area in Meter sq.
10000
Area in Acre is 2.471044

Program for Conversion of Meter sq. to Hectare.

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,b;
//Input the area in given unit save them in 'a'
cout<<"Enter the Area in Meter sq."<<endl;
cin>>a;
//convert and save it in 'b'
b=a/10000;
//show the output 'b'
cout<<"Area in Hectare is "<<b;
//get character
getch();
}

Output

Enter the Area in Meter sq.
1800
Area in Hectare is 0.18

How does it work

1. You enter the area in given unit and is saved in variable ‘a’.
2. The area is converted according to conversion formula and is saved in ‘b’.
3. Variable ‘b’ is shown by cout.

Extending it

The Program can be extended by adding more unit to conversion and by adding their Conversion formula for other unit and more variables can be added to program to convert multiple areas. Like wise you can also use following unit for conversion :-

• centimeter sq.
• meter sq.
• acre
• feet sq.
• hectare
• inch sq.
• mile sq.
• yard sq.
• are

Explanation

1. Include ‘iostream.h’ and ‘conio.h’ files.
2. Add void main.
3. Start program by first clearing the screen.
4. Declare the variables as float (name them as you want.)
5. Add cout and cin of variables you want to convert from.(as shown in program)
6. Convert the area from variable and save them in one variable.
7. Cout the converted area variable.

At the end

You learnt creating the c++ program of conversion of area from one unit to other unit. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Sharing options: