Conversion Class in c++ language in hindi , what is Conversion Class examples , BinaryOctal ()

इससे पहले के article मे string को class के साथ discuss किया था अब आगे के article मे looping को class के साथ उदाहरनो को discuss करेगे | जिससे looping के साथ साथ class के concept भी मजबूत होगा
उदहारण 1 :
Write a program number conversion system.
Explanation
इस प्रोग्राम मे class convert को declare किया जाता है |जिसमे 10 function को define किया गया है |
1.BinaryOctal () : इस function का use binary number को octal number मे convert किया जाता  है |
2.BinaryDecimal() :इस function का use binary number को  decimal number मे convert किया जाता  है |
3.BinaryHexadecimal() : इस function का use binary number को hexadecimal number मे convert किया जाता  है |
4.OctalBinary() : इस function का use octal number को binary number मे convert किया जाता  है |
5.Octalhexadecimal() :  इस function का use octal number को  hexadecimal number मे convert किया जाता  है |
6.OctalDecimal() :  इस function का use octal number को decimal number मे convert किया जाता  है |
7.decimalbinary () :  इस function का use decimal number को binary number मे convert किया जाता  है |
8.decimaloctal() :  इस function का use decimal number को  octal number मे convert किया जाता  है |
9.decimalhexadecimal() :  इस function का use decimal number को hexadecimal number मे convert किया जाता  है |
10.hexadecimalbinary() : इस function का use hexadecimal number को  binary number मे convert किया जाता  है |
11.hexadecimdecimal() : इस function का use hexadecimal number को  decimal number मे convert किया जाता  है |
12.hexadecimaloctal() : इस function का use hexadecimal number को  octal number मे convert किया जाता  है |
BinaryOctal ()  मे ,
इस function मे , binary number को pass किया जाता है |
उसके बाद variable o को ‘0’ से initail किया जाता है |
last के तीन डिजिट को find किया जाता है | इसके लिए number को 100 से डिवाइड किया जाता है उसके remainder को variable d मे assign करते है |
उसके बाद octal लिस्ट मे से डिजिट के अनुसार octal डिजिट को find करते है |
इसके बाद last के तीन डिजिट को हटा देते है इसके लिए number को 1000 से divind करते है |
उसके बाद प की value को 10 से multiply करते है |
upper दी गयी steps को repeat करते है जब तक binary number की value ‘0’ से बड़ी है |
BinaryDecimal() मे ,
सबसे पहले binary number से last डिजिट को find करता है | इसके लिए number को 10 से multiply करते है |
अगर डिजिट की value ‘1’ होती है तब
इसके बाद decimal मे digit * pow(2,n); से update करते है |
यहा पर n की value binary bits की position होती है |
BinaryHexadecimal()
इस function मे , binary number को pass किया जाता है |
उसके बाद variable h को ‘0’ से initail किया जाता है |
last के चार डिजिट को find किया जाता है | इसके लिए number को 10000 से डिवाइड किया जाता है उसके remainder को variable d मे assign करते है |
उसके बाद hexadecimal लिस्ट मे से डिजिट के अनुसार hexadecimal डिजिट को find करते है |
इसके बाद last के char डिजिट को हटा देते है इसके लिए number को 10000 से divind करते है |
उसके बाद d की value को 10 से multiply करते है |
upper दी गयी steps को repeat करते है जब तक binary number की value ‘0’ से बड़ी है |
OctalBinary() मे ,
सबसे पहले last डिजिट को exact किया जाता है | इसे remainder variable मे assign कर दिया जाता है |
उसके बाद  remainder की binary value को binary variable मे assign कर दते है |
इसके बाद number के last डिजिट को eliminate कर दिया जाता है |
इसके बाद octal number को print किया जाता है |
इसके बाद binary number को print किया जाता है |
Octalhexadecimal()
सबसे पहले octal number को binary number मे convert किया जाता है उसके बाद
binary number से चार digits को अलग अलग किया जाता है उसके बाद इसके अनुसार string hex मे hexadecimal code को assign कर दिया जाता है |
इअके लिए strcat () function को use किया जाता है |
decimalbinary () मे
सबसे पहले decimal number को 2 से डिवाइड करते है | इसके remainder को binary variable मे assign कर देते है |
इसके बाद binary variable मे position को set करता है |
फिर से number को 2 से डिवाइड करके remainder को binary variable मे add कर देते है |
ये process तब तक चलता है जब तक decimal number की value ‘0’ से बड़ी होती है |
decimaloctal() मे
सबसे पहले decimal number को 8 से डिवाइड करते है | इसके remainder को binary variable मे assign कर देते है |
इसके बाद binary variable मे position को set करता है |
फिर से number को 8 से डिवाइड करके remainder को binary variable मे add कर देते है |
ये process तब तक चलता है जब तक decimal number की value ‘0’ से बड़ी होती है |
Source Code
#include<iostream>
#include<conio.h>
using namespce std;
class conversion
{
int decimal , remainder , octal , place ;
public :
void decimaloctal(int decimal )
{
while(decimal > 0)
{
rem = decimal % 8;
octal = (rem * place) + octal;
decimal /= 8;
place *= 10;
}
printf(“\nDecimal number = %lld\n”, decimal);
printf(“Octal number = %lld”, octal);
return 0;
}
}
void decimalbinary(int decimal )
{
while(decimal > 0)
{
rem = decimal % 2;
binary = (rem * place) + binary;
decimal /= 2;
place *= 10;
}
printf(“Decimal number = %lld\n”, decimal);
printf(“Binary number = %lld”, binary);
return 0;
}
}
void octalhexadecimal( int octal )
{
while(binary > 0)
{
rem = binary % 10000;
switch(rem)
{
case 0:
strcat(hexadecimal, “0”);
break;
case 1:
strcat(hexadecimal, “1”);
break;
case 10:
strcat(hexadecimal, “2”);
break;
case 11:
strcat(hexadecimal, “3”);
break;
case 100:
strcat(hexadecimal, “4”);
break;
case 101:
strcat(hexadecimal, “5”);
break;
case 110:
strcat(hexadecimal, “6”);
break;
case 111:
strcat(hexadecimal, “7”);
break;
case 1000:
strcat(hexadecimal, “8”);
break;
case 1001:
strcat(hexadecimal, “9”);
break;
case 1010:
strcat(hexadecimal, “A”);
break;
case 1011:
strcat(hexadecimal, “B”);
break;
case 1100:
strcat(hexadecimal, “C”);
break;
case 1101:
strcat(hexadecimal, “D”);
break;
case 1110:
strcat(hexadecimal, “E”);
break;
case 1111:
strcat(hexadecimal, “F”);
break;
}
binary /= 10000;
}
strrev(hexadecimal);
printf(“Octal number: %lld\n”, octal);
printf(“hexadecimaladecimal number: %s”, hexadecimal);
return 0;
}
}
void octaldecimal(int octal )
{
/* Convert octal to binary */
while(octal > 0)
{
/* Extract the last digit of octal */
rem = octal % 10;
/*
* Get the binary equivalent of octal digit
* add it to the binary variable
*/
binary = (OCTALVALUES[rem] * place) + binary;
/* Remove the last octal digit */
octal /= 10;
/* Increase the place value */
place *= 1000;
}
printf(“Octal number = %lld\n”, octal);
printf(“Binary number = %lld”, binary);
return 0;
}
void binaryhexadecimal(int binary )
{
while(binary !=0)
{
/* Group binary to last four digits */
digit = binary  % 10000;
/* Find hexadecimaladecimal equivalent of last four digit */
for(i=0; i<16; i++)
{
if(hexadecimalConstant[i] == digit)
{
if(i<10)
{
/* 0-9 integer constant */
hexadecimal[index] = (char)(i + 48);
}
else
{
/* A-F character constant */
hexadecimal[index] = (char)((i-10) + 65);
}
index++;
break;
}
}
/* Remove the last 4 digits as it is processed */
binary  /= 10000;
}
hexadecimal[index] = ‘\0’;
/* Reverse the hexadecimal digits */
strrev(hexadecimal);
printf(“Binary number = %lld\n”, binary);
printf(“hexadecimal number = %s”, hexadecimal);
return 0;
}
}
void binarydecimal (int binary)
{
while(binary !=0)
{
/* If current binary digit is 1 */
if(binary  % 10 == 1)
{
decimal += pow(BASE, N);
}
N++;
binary  /= 10;
}
printf(“Binary number = %lld\n”, binary);
printf(“Decimal number= %lld”, decimal);
return 0;
}
void binaryoctal(int binary )
{
while(binary  != 0)
{
/* Extract last three digit of binary */
digit = binary  % 1000;
/* Find octal equivalent of 3 digit binary */
for(i=0; i<8; i++)
{
if(o[i] == digit)
{
/*
* Increase the p value of octal
* and add the previous octal value
*/
octal = (i * p) + octal;
break;
}
}
/* Remove the last three digit of binary */
binary  /= 1000;
/* Increase the p value */
p *= 10;
}
printf(“Original binary number = %lld\n”, binary);
printf(“Octal number = %lld”, octal);
return 0;
}
}
void main()
{
conversion c;
cout<<“Binary Number “;
cin>>binary ;
c.BinaryOctal(binary);
c.Binaryhexadecimal(binary);
c.binarydecimal(binary);
cout<<“octal Number : “<<endl;
cin>>octal;
c.OctalBinary(octal);
c.Octalhexadecimal(octal);
cout<<“Decimal Number :”<<endl;
cin>>decimal;
c.decimalbinary(decimal);
c.decimaloctal(decimal);
getch();
}