Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to implement this option in my following code One ternary operation ?: The usual ternary expression a ? b : c in C will

How to implement this option in my following code

One ternary operation ?: The usual ternary expression a ? b : c in C will be written as c b a ?. If a is non-zero, the value of the expression is b, otherwise it is c.

#include #include #include #include "calc.h"

#define MAXOP 128

int main(int argc, char *argv[]) { int type; int op2; char s[MAXOP];

while ((type = getop(s)) != EOF) { switch(type) {

/*made the atoi change*/ case NUMBER: push(atoi(s)); break; case '+': push((int)pop() +(int)pop()); break; case '-': op2 = pop(); push((int)pop() - (int) op2); break; case '*': push((int)pop() *(int)pop()); break; case '/': op2 = pop(); if (op2 != 0.0) push((int)pop() / (int)op2); else { printf("error : zero divisor ");

case '&': push((int)pop() & (int) pop()); break;

case '|': push((int)pop() | (int) pop()); break;

case '^': push((int)pop() ^(int) pop()); break; /* Bitwise not operation */

case '~': { int a = pop(); a = ~a; push(a); break; } /*Returns 1 for true and 0 for false*/ case '>': push((int) pop() >(int) pop()); break;

case '=': push((int)(pop() == (int) pop())); break;

case '<': push((int)pop() < (int)pop()); break;

/*returns 1 if number is 0 otherwise 1*/ case '!': push((int)pop() == 0); break;

case ' ': printf(" The answer is %d ", pop()); break; default: printf("error: unknown command %s ", s); exit(1);

}

} } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago