Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m having a ton of trouble figuring out these two programms.... 1. Write a pro

ID: 3539940 • Letter: I

Question

I'm having a ton of trouble figuring out these two programms....


1. Write a program that uses a stack to convert a decimal number into an equivalent binary number?


2. Write a program that uses a stack to convert a binary number into an equivalent decimal number?

Explanation / Answer

//PART 2 #include #include #define MAX 10 using namespace std; struct stack { int data[MAX]; int top; }; //--------------------- 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); } //------------------------ int main() { stack s; int num; int pow=1; s.top=-1; coutnum; while((num!=0)) { if(!full(&s)) { push(&s,(num%10) * pow); num=num/10; pow=pow*2; } else { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote