Program4.2is prepared for eveluating a given postfixexpression. When you run this program postfixexpression must be given as input string and program will generate an output asnumeric real number that is called as evaluated value.Hint : postfix expression consist of one digit numeric operands and operators and only.Example data for the program could be as followsa)If you give input string as 9 1 4 2/ + -2 3 * /Program will generate evaluated outputas 1.eb) If you give input string as3 9 2 3$ -* 6 +and evaluated value as value"/#include #include#include #define MAXCOLS 80struct stack{int top;double items[MAXCOLS];};double eval(char[]);double pop(struct stack *); void push(struct stack *,double);int empty(struct stack *);int isdigit(char);double oper(int, double, double);void main(void){char expr[MAXCOLS];int pos =0;while((expr[pos++] = getchar()) != '\n') ;expr[-- pos] = '\o';printf("%s%s", " the original postfix expression is ",expr);getchar();printf("\n %f ", eval(expr)); getchar();}double pop(struct stack "ps){ double x;if (ps->top==-1){printf("%s","stack underflow");exit(1);}else{x-ps->items[ps->top];ps->top-ps->top -1;}return x;}void push(struct stack "ps, double x){if (ps->top == MAXCOLS-1) {printf("%s","stack overflow ");exit(1);}else{ps->top=ps->top + 1;ps->items[ps->top]=x;}}double eval(char expr[]){int c , pos;double opnd1, opnd2, value ;struct stack s;s.top=-1;for(pos =0; (c=expr[position])!='\0'; pos++)if (isdigit(c))push(&s, (double)(c-'0'));else {opnd2=pop(&s);opnd1=pop(&s);value=oper(c ,opnd1 ,opnd2); push (&s, value);}return(pop(&s));} int isdigit(char symb){return ( symb >= '0' && symb <= '9');}double oper(int symb , double op1 , double op2){switch (symb){case '+' :return (op1 + op2);case '-' :return (op1 -op2);case ** :return (opi * op2);case '/' :return (op1 / op2);case '$' :return (pow(op1 , op2));default : printf("%s", "illegal operation ");exit(1);}} 9.00/* Program4.2PostfixBEvaluated
Program4.2is prepared for eveluating a given postfixexpression. When you run this program postfixexpression must be given as input string and program will generate an output asnumeric real number that is called as evaluated value.Hint : postfix expression consist of one digit numeric operands and operators and only.Example data for the program could be as followsa)If you give input string as 9 1 4 2/ + -2 3 * /Program will generate evaluated outputas 1.eb) If you give input string as3 9 2 3$ -* 6 +and evaluated value as value"/#include #include#include #define MAXCOLS 80struct stack{int top;double items[MAXCOLS];};double eval(char[]);double pop(struct stack *); void push(struct stack *,double);int empty(struct stack *);int isdigit(char);double oper(int, double, double);void main(void){char expr[MAXCOLS];int pos =0;while((expr[pos++] = getchar()) != '\n') ;expr[-- pos] = '\o';printf("%s%s", " the original postfix expression is ",expr);getchar();printf("\n %f ", eval(expr)); getchar();}double pop(struct stack "ps){ double x;if (ps->top==-1){printf("%s","stack underflow");exit(1);}else{x-ps->items[ps->top];ps->top-ps->top -1;}return x;}void push(struct stack "ps, double x){if (ps->top == MAXCOLS-1) {printf("%s","stack overflow ");exit(1);}else{ps->top=ps->top + 1;ps->items[ps->top]=x;}}double eval(char expr[]){int c , pos;double opnd1, opnd2, value ;struct stack s;s.top=-1;for(pos =0; (c=expr[position])!='\0'; pos++)if (isdigit(c))push(&s, (double)(c-'0'));else {opnd2=pop(&s);opnd1=pop(&s);value=oper(c ,opnd1 ,opnd2); push (&s, value);}return(pop(&s));} int isdigit(char symb){return ( symb >= '0' && symb <= '9');}double oper(int symb , double op1 , double op2){switch (symb){case '+' :return (op1 + op2);case '-' :return (op1 -op2);case ** :return (opi * op2);case '/' :return (op1 / op2);case '$' :return (pow(op1 , op2));default : printf("%s", "illegal operation ");exit(1);}} 9.00/* Program4.2PostfixBEvaluated
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 2 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY