C++ : Example , Write a program to convert a height value in feet into feet value , BMI( body mass index )

इससे पहले C++ : Basic Examples (Part-1) ,मे c++ langue मे लिखे कुछ उदाह्रानो को discuss किया है | अब इस article मे हम कुछ और उदाहरानो को discuss करेगे | जिससे आपके C++ के सभी basic concept जैसे data type , arithmetic operator और syntax को अच्छी तरह समज सके |
उदाहरण- 1
Write a program to convert a height value in feet into feet value.
Explanation
सबसे पहले  दो variables को declare करते है | जिसमे एक का type integer और दूसरा का type float है |
उसके बाद यूजर से height value ( जो inch मे होगी ) को input करा लेगे | इसे variable name ‘h’
मे assign किया जाता है |
इसके बाद यूजर द्वारा input किये गये height value को feet मे convert करके variable h1 मे assign किया जाता है |
इसके बाद इन converted  value को cout statement से display करा लेते है |
Source Code
#include<iostream.h>
#include<conio.h>
void mian ()
{
using namespace std;
int h;
float h1;
cout<<“Enter height value (in Inch )  :”<<endl;
cin>>h;
h1=h*0.0833;
cout<<“Height value (in Foot )  : “<<h1<<endl;
getch();
}
इसका आउटपुट होगा :
Enter height value (in Inch )  : 6
Height value (in Foot )  : 0.50उदाहरण- 2
Write a program to calculate BMI( body mass index ).
Explanation
BMI( body mass index ) एक ration होता है जोकि weight in kilogram और height in foot से calculate किया जाता है | इस उदाहरण मे , यूजर से height को inch मे और weight को pound मे लिया जाता है | और बाद मे BMI को calculate किया जाता है |
सबसे पहले  दो variables को declare करते है | जिसमे height को inch मे और weight को pound की value को assign किया जाता है |
उसके बाद यूजर से height value ( जो inch मे होगी ) को input करा लेगे | इसे variable name ‘h’
मे assign किया जाता है और यूजर से weight value ( जो pound मे होगी ) को input करा लेगे | इसे variable name ‘w’ मे assign किया जाता है  |
इसके बाद यूजर द्वारा input किये गये height value को feet मे convert करके variable h1 मे assign किया जाता है | और यूजर द्वारा input किये गये weight value को kilogram  मे convert करके variable w1 मे assign किया जाता है |
उइसके बाद body mass index = weight value / height value  ; से BMI को calclaute किया जाता है |
इसके बाद इन BMI  value को cout statement से display करा लेते है |
Source Code
#include<iostream.h>
#include<conio.h>
void mian ()
{
using namespace std;
int h,w;
float h1,w1;
cout<<“Enter height value (in Inch )  :”<<endl;
cin>>h;
h1=h*0.0833;
cout<<“Height value (in Foot )  : “<<h1<<endl;
cout<<“Enter weight value (in Pound)  :”<<endl;
cin>>w;
w1=w/2.2;
cout<<“Weight value (in Kilogram )  : “<<w1<<endl;
float i= w1/hValue ;
cout<<“BMI Value “<<i;
getch();
}
इसका आउटपुट होगा :
Enter height value (in Inch )  : 6
Height value (in Foot )  : 0.50
Enter height value (in Pound )  : 6
Weight value (in Kilogram )  : 3.3
BMI Value =

उदाहरण-
Write a program to calculate car efficiency in miles per gallons. and convert it into Indian style ( kilogram per liter).
Explanation
car efficiency in miles per gallons एक ration होता है जोकि distance in miles  और oli capacity in gallon  से calculate किया जाता है | इस उदाहरण मे , यूजर से distance को  mile  मे और oil capacity को gallons मे लिया जाता है | और बाद मे miles per gallons को calculate किया जाता है |
सबसे पहले  दो variables को declare करते है | जिसमे distance value को mile मे और oil capacity को gallon  की value को assign किया जाता है |
उसके बाद यूजर से distance value ( जो mile मे होगी ) को input करा लेगे | इसे variable name ‘d’
मे assign किया जाता है और यूजर से oil capacity  value ( जो gallon मे होगी ) को input करा लेगे | इसे variable name ‘c’ मे assign किया जाता है  |
इसके बाद यूजर द्वारा input किये गये height value को kilogram  मे convert करके variable d1 मे assign किया जाता है | और यूजर द्वारा input किये गये oil capacity value को litres  मे convert करके variable c1 मे assign किया जाता है |
उइसके बाद से efficiency = distance value /oil capacity  value ;  को calculate किया जाता है |
इसके बाद इन efficiency value को cout statement से display करा लेते है |
Source Code
#include<iostream.h>
#include<conio.h>
void mian ()
{
using namespace std;
int d,c;
float d1,c1;
cout<<“Enter distance value (In Mile )  :”<<endl;
cin>>d;
d1=(d*100)/62.14;
cout<<“Distance value  (in Kilometer )  : “<<d1<<endl;
cout<<“Enter oil capacity  value (In gallon )  :”<<endl;
cin>c;
c1=c*3.875;
cout<<“oil capacity value (In Litres) : “<<w1<<endl;
float i= d1/c1 ;
cout<<” Efficiency Value “<<i;
getch();
}

उदाहरण- 4
Write a program to calculate square of a number .
Explanation
सबसे पहले  दो variables को declare करते है | जिसमे एक का type integer और दूसरा का type float है |
उसके बाद यूजर से  value  को input करा लेगे | इसे variable name ‘a’ मे assign किया जाता है |
इसके बाद यूजर द्वारा input किये गये value से square को calculate करके variable s मे assign किया जाता है |
इसके बाद इन square value को cout statement से display करा लेते है |
Source Code
#include<iostream.h>
#include<conio.h>
void main ()
{
using namespace std;
int a;
float s;
cout<<“Enter value  :”<<endl;
cin>>a;
s=a*a;
cout<<“Square value  : “<<s<<endl;
getch();
}
इसका आउटपुट होगा :
Enter value  : 3
Square value  : 9

उदाहरण- 5
Write a program to calculate cube of a number .
Explanation
सबसे पहले  दो variables को declare करते है | जिसमे एक का type integer और दूसरा का type float है |
उसके बाद यूजर से  value  को input करा लेगे | इसे variable name ‘a’ मे assign किया जाता है |
इसके बाद यूजर द्वारा input किये गये value से cube को calculate करके variable q मे assign किया जाता है |
इसके बाद इन cube value को cout statement से display करा लेते है |
Source Code
#include<iostream.h>
#include<conio.h>
void main ()
{
using namespace std;
int a;
float s;
cout<<“Enter value  :”<<endl;
cin>>a;
s=a*a*a;
cout<<“Cube value  : “<<s<<endl;
getch();
}
इसका आउटपुट होगा :
Enter value  : 3
Cube value  : 27