Write a C++ program of binary to octal conversion with Constructor with constructor.
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 |
/* binary to octal conversion with Constructor.*/ #include<iostream> using namespace std; class T4Tutorials { private : int i,j,dn; int temp,T4Tutorials_Octal; public : //for constrtcor function name is same as class name T4Tutorials() { cout<<"Program for decimal to octal "<<endl; cout<<"conversion with Constructor.."<<endl; cout<<"Enter the Decimal Number : "<<endl; cin>>dn; temp=dn; i=1; for(j=dn ; j>0 ; j=j/8) { T4Tutorials_Octal=T4Tutorials_Octal+(j%8)*i; i=i*10; } cout<<"Your Input Decimal is :"<<temp; cout<<"Octal Value After conversion is : "<<T4Tutorials_Octal<<endl; } }; int main() { T4Tutorials a; } |
Write a C++ program of binary to octal conversion with Constructor Overloading.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
/* binary to octal conversion with Constructor overloading*/ #include<iostream> using namespace std; class construct { protected : int i,j; int temp, T4Tutorials_Octal; int temp1, T4Tutorials_Octal1; int temp2, T4Tutorials_Octal2; public : construct(int one) { temp=one; i=1; for(j=one ; j>0 ; j=j/8) { T4Tutorials_Octal=T4Tutorials_Octal+(j%8)*i; i=i*10; } cout<<"Your Input Decimal is :"<<temp; cout<<"Octal Value After conversion is : "<<T4Tutorials_Octal<<endl; } construct(int T4Tutorials2,int T4Tutorials3) { temp1=T4Tutorials2; temp2=T4Tutorials3; i=1; for(j=T4Tutorials2 ; j>0 ; j=j/8) { T4Tutorials_Octal1=T4Tutorials_Octal1+(j%8)*i; i=i*10; } cout<<"Your first Input Decimal is :"<<temp1; cout<<"Octal Value After conversion is : "<<T4Tutorials_Octal1<<endl; i=1; for(j=T4Tutorials3 ; j>0 ; j=j/8) { T4Tutorials_Octal2=T4Tutorials_Octal2+(j%8)*i; i=i*10; } cout<<"Your Second Input Decimal is :"<<temp2; cout<<"Octal Value After conversion is : "<<T4Tutorials_Octal2<<endl; } }; int main() { cout<<"This Program Demonstrate The Single and"; cout<<"multiple paramter Constructor"; int option; Abc : cout<<"Enter 1 of Single parameter constructor "; cout<<"Enter 2 For Multiple Paramter constucor "; cout<<"Enter 1 or 2 : "; cin>>option; system("cls"); //this function is to clear the screen if(option ==1) { cout<<"-You Have Slected Single Paramater"; cout<<"Constructor-"; int one; cout<<"Enter a Decimal Number to conver to into octal : "; cin>>one; construct a(one); } else if(option==2) { cout<<"-You Have slected Multiple Paramater "; cout<<"Constructor-"; int T4Tutorials2,T4Tutorials3; cout<<"Enter First Decimal Number to conver to into octal : "; cin>>T4Tutorials2; cout<<"Enter Second Decimal Number to conver to into octal : "; cin>>T4Tutorials3; construct a(T4Tutorials2, T4Tutorials3); } else { cout<<"Your Input in Wrong try Agin "; goto Abc; } } |
Write a C++ program of binary to octal conversion with destructor.
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 |
/* binary to octal conversion with destructor*/ #include<iostream> using namespace std; class T4Tutorials { private : int i,j,dn; int temp,T4Tutorials_Octal; public : //for destructor function name is same as class name with ~sign ~T4Tutorials() { cout<<"Program for decimal to octal "<<endl; cout<<"conversion with destructor.."<<endl; cout<<"Enter the Decimal Number : "<<endl; cin>>dn; temp=dn; i=1; for(j=dn ; j>0 ; j=j/8) { T4Tutorials_Octal=T4Tutorials_Octal+(j%8)*i; i=i*10; } cout<<"Your Input Decimal is :"<<temp; cout<<"Octal Value After conversion is : "<<T4Tutorials_Octal<<endl; } }; int main() { T4Tutorials a; } |