Write a C++ program of binary to octal conversion with Constructor with constructor.
/* 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.
/* 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.
/* 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;
}