Classes Objects C++ program to to convert a convert decimal number into binary
Write a program in C++ to convert a decimal number into binary without using OOP classes and objects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#include<iostream> using namespace std; class decimal2binaryconversion { public: long int i=0; char decnum[1000]; public: int decimal2binary() { cout<<"Enter any decimal number:\n"; cin>>decnum; cout<<endl; cout<<"binary value of "<<decnum<<" is "; while(decnum[i]) { switch(decnum[i]) { case'0':cout<<"000"; break; case'1':cout<<"001"; break; case'2':cout<<"010"; break; case'3':cout<<"011"; break
; case'4':cout<<"100"; break; case'5':cout<<"101"; break; case'6':cout<<"110"; break; case'7':cout<<"111"; break; case'8':cout<<"000"; break; case'9':cout<<"001"; break; default:cout<<"invalid decimal number"<<decnum[i]; break; } i++; cout<<endl<<endl<<endl; } } }; int main() { decimal2binaryconversion d; d.decimal2binary(); } |