1 - Convert from DEC to BIN (using STACK) & save a result in QUEUE
2 - Convert from BIN to DEC
3 - Calculate OR-Binary A.B (extracting the binary numbers from the QUEUE (1) )
3 - Calculate AND-Binary A.B (extracting the binary numbers from the QUEUE (1) )
I want to use classes , i want to creat a function.h contains all the functions + stach.h + queue.h
This is how the program look like :
cout<<endl<<"Application operation binaire implementant des piles et des files"<<endl;
cout<<endl<<"----------------------------"<<endl;
cout<<endl<<"enter your option"<<endl;
cout<<endl<<"(Tapez 1, 2, 3, 4, 5 ou 6)"<<endl;
cout<<endl<<"----------------------------"<<endl;
cout<<"1. Convert DEC to BIN ..."<<endl;
cout<<"2. Convert BIN to DEC ..."<<endl;
cout<<"3. Calcul de X OU Y ..."<<endl;
cout<<"4. Calcul de X ET Y ..."<<endl;
cout<<"5. Display ..."<<endl;
cout<<"6. Quitter l'application ..."<<endl;
cout<<endl<<"----------------------------"<<endl;
cout<<"Enter your choice : ";
cin>>choice;
switch ( choice )
{
case 1:
cout<<"Enterer le le nombre DEC : ";
break;
case 2:
cout<<"Enter le nombre BIN: ";
break;
case 3:
cout<<"Calculer X OU Y";
cout<<"Enter X : ";
cout<<"Enter Y : ";
break;
case 4:
cout<<"Calculer X ET Y";
cout<<"Enter X : ";
cout<<"Enter Y : ";
break;
case 5:
cout<<"Les resultats sont : \n";
break;
case 6:
exit(1);
default:
cout<<"Choix invalide !!"<<endl;
}
Stack.h + main program of the converter from DEC TO BIN
#include<stdio.h>
#include<conio.h>
#include<process.h>
#define MAX 10
typedef struct stack
{
int data[MAX];
int top;
}stack;
//---------------------
int empty(stack *s)
{
if(s->top==-1)
return(1);
return(0);
}
//----------------------
int full(stack *s)
{
if(s->top==MAX-1)
return(1);
return(0);
}
//-----------------------
void push(stack *s,int x)
{
s->top=s->top+1;
s->data[s->top]=x;
}
//-----------------------
int pop(stack *s)
{
int x;
x=s->data[s->top];
s->top=s->top-1;
return(x);
}
//------------------------
void main()
{
stack s;
int num;
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
string bin;
cin >> bin;
int dec = 0;
reverse(bin.begin(), bin.end());
for (int i = 0; i < bin.size(); ++i) {
dec += (int(bin[i]) - 48)*pow(2, i);
}
cout << dec;
return 0;
}
Binary ADD
#include <stdio.h>
#include <iostream>
using namespace std;
int main() {
long a, b;
int i = 0, r = 0, sum[20];
cout << "Enter the the 1st one : ";
cin >> a;
cout << "Enter the 2nd one: ";
cin >> b;
while (a != 0 || b != 0)
{
sum[i++] = (a % 10 + b % 10 + r) % 2;
r = (a % 10 + b % 10 + r) / 2;
a = a / 10;
b = b / 10;
}
if (r != 0)
sum[i++] = r;
--i;
cout << "result is: ";
while (i >= 0)
cout << sum[i--];
cout << ". ";
system("pause");
return 0;
}
Binary OR
#include <stdio.h>
#include <iostream>
using namespace std;
int main() {
long a, b;
int i = 0, r = 0, sum[20];
cout << "Enter the the 1st one : ";
cin >> a;
cout << "Enter the 2nd one: ";
cin >> b;
while (a != 0 || b != 0)
{
int i = 0, r = 0, prod[20];
prod[i++] = (a % 10 * b % 10 + r) % 2;
r = (a % 10 * b % 10 + r) / 2;
a = a / 10;
b = b / 10;
if (r != 0)
prod[i++] = r;
--i;
cout << "The product is : ";
while (i >= 0)
cout << prod[i--];
cout << ". ";
system("pause");
return 0;
}
}
I want to orginise my work , can you please help me to do it ?