#include <iostream.h>
#include <conio.h>
#define namespace std;
const int STACK_SIZE = 100;
class stack {
private:
int count;
int data[STACK_SIZE];
public:
stack();
~stack();
void push(const int item);
int pop(void);
};
stack::stack()
{
count = 0;
}
stack::~stack() {}
void stack::push(const int item)
{
if (count < STACK_SIZE)
{
data[count] = item;
++count;
}
else cout << "Overflow!\n";
}
int stack::pop(void)
{
if (count >0)
{
--count;
return (data[count]);
}
else
{
cout << "Underflow!\n";
return 0;
}
}
int menu();
class number
{
public:
number() {x=0;}
number (int num){x=num;}
virtual ~number() {}
virtual void print_it()=0;
int num;
private:
int x;
};
//Program tentang konversi bilangan ke biner
class toBinary:public number
{
public:
void print_it()
{
int num;
int total = 0;
stack reverse;
int ctr=0;
cout << "Masukkan angka desimal : ";
cin >> num;
cout << "Angka yg anda masukkan : " << num <<endl;
cout << "Angka biner dari "<< num <<" adalah : ";
while(num > 0)
{
total = num % 2;
num /= 2;
reverse.push(total);
ctr++;
}
while (ctr > 0)
{
cout << reverse.pop() << " ";
ctr--;
}
}
};
//ini adalah konversi dari desimal ke oktal
class toOctal: public number
{
void print_it()
{
int num;
int total = 0;
stack reverse;
int ctr=0;
cout << "Masukkan angka desimal : ";
cin >> num;
cout << "Angka yg anda masukkan : " << num <<endl;
cout << "Angka Oktal dari "<<num <<" adalah : ";
while(num > 0)
{
total = num % 8;
num /= 8;
reverse.push(total);
ctr++;
}
while (ctr > 0)
{
cout << reverse.pop() << " ";
ctr--;
}
}
};
//ini adalah program bagian konversi dari desimal ke heksa
class toHex:public number
{
void print_it()
{
int num,counter,x,a,hex[100];
cout<<"Masukkan angka desimal : ";
cin>>num;
cout<<"Angka yg anda masukkan : " << num <<endl;
cout << "Angka Oktal dari "<<num <<" adalah : ";
for(counter=0;num!=0;counter++)
{
a=num%16;
hex[counter]=a;
num=num/16;
}
for(x=counter-1;x>=0;x--)
{
if (hex[x] > 9)
cout << char('A'+hex[x]-10);
else
cout << hex[x];
}
cout << endl;
}
};
//ini adalah void utama untuk program tersebut
void main(){
number * Show;
int choice = menu();
switch(choice){
case (1):
Show = new toBinary();
Show->print_it();
delete Show;
break;
case (2):
Show = new toOctal();
Show->print_it();
delete Show;
break;
case(3):
Show = new toHex();
Show->print_it();
delete Show;
break;
}
getch();
}
int menu(){
int choice;
cout << "Konversi desimal ke biner, oktal dan heksa : " << endl;
cout << "1. Binary" << endl;
cout << "2. Octal" << endl;
cout << "3. Hexadecimal" << endl;
cout << "Pilihan anda : ";cin >> choice;
return c
#include <conio.h>
#define namespace std;
const int STACK_SIZE = 100;
class stack {
private:
int count;
int data[STACK_SIZE];
public:
stack();
~stack();
void push(const int item);
int pop(void);
};
stack::stack()
{
count = 0;
}
stack::~stack() {}
void stack::push(const int item)
{
if (count < STACK_SIZE)
{
data[count] = item;
++count;
}
else cout << "Overflow!\n";
}
int stack::pop(void)
{
if (count >0)
{
--count;
return (data[count]);
}
else
{
cout << "Underflow!\n";
return 0;
}
}
int menu();
class number
{
public:
number() {x=0;}
number (int num){x=num;}
virtual ~number() {}
virtual void print_it()=0;
int num;
private:
int x;
};
//Program tentang konversi bilangan ke biner
class toBinary:public number
{
public:
void print_it()
{
int num;
int total = 0;
stack reverse;
int ctr=0;
cout << "Masukkan angka desimal : ";
cin >> num;
cout << "Angka yg anda masukkan : " << num <<endl;
cout << "Angka biner dari "<< num <<" adalah : ";
while(num > 0)
{
total = num % 2;
num /= 2;
reverse.push(total);
ctr++;
}
while (ctr > 0)
{
cout << reverse.pop() << " ";
ctr--;
}
}
};
//ini adalah konversi dari desimal ke oktal
class toOctal: public number
{
void print_it()
{
int num;
int total = 0;
stack reverse;
int ctr=0;
cout << "Masukkan angka desimal : ";
cin >> num;
cout << "Angka yg anda masukkan : " << num <<endl;
cout << "Angka Oktal dari "<<num <<" adalah : ";
while(num > 0)
{
total = num % 8;
num /= 8;
reverse.push(total);
ctr++;
}
while (ctr > 0)
{
cout << reverse.pop() << " ";
ctr--;
}
}
};
//ini adalah program bagian konversi dari desimal ke heksa
class toHex:public number
{
void print_it()
{
int num,counter,x,a,hex[100];
cout<<"Masukkan angka desimal : ";
cin>>num;
cout<<"Angka yg anda masukkan : " << num <<endl;
cout << "Angka Oktal dari "<<num <<" adalah : ";
for(counter=0;num!=0;counter++)
{
a=num%16;
hex[counter]=a;
num=num/16;
}
for(x=counter-1;x>=0;x--)
{
if (hex[x] > 9)
cout << char('A'+hex[x]-10);
else
cout << hex[x];
}
cout << endl;
}
};
//ini adalah void utama untuk program tersebut
void main(){
number * Show;
int choice = menu();
switch(choice){
case (1):
Show = new toBinary();
Show->print_it();
delete Show;
break;
case (2):
Show = new toOctal();
Show->print_it();
delete Show;
break;
case(3):
Show = new toHex();
Show->print_it();
delete Show;
break;
}
getch();
}
int menu(){
int choice;
cout << "Konversi desimal ke biner, oktal dan heksa : " << endl;
cout << "1. Binary" << endl;
cout << "2. Octal" << endl;
cout << "3. Hexadecimal" << endl;
cout << "Pilihan anda : ";cin >> choice;
return c



