Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please don't use IOStream. We are given the input with stdin (c program) Problem C: Integer Expressions ming language, and she needs a module Jane

image text in transcribedimage text in transcribed

Please don't use IOStream. We are given the input with stdin (c program)

Problem C: Integer Expressions ming language, and she needs a module Jane Coder is building a parser for a customized program to process some integer expressions. As a starting specification, she decided to implement the following operations 4, (addition),-(subtraction), *, (multiplication), and (exponent). To make parsing easier, she also decided to use parentheses around each operation with two operands Your task is to write a program to evaluate such expressions. The expressions that need to be evaluated can be described as follows: 1. First, any integer is an expression. 2. Second, if we have two expressions, let us call them a and b, then we can write a larger expres- sion in one of the following four ways: (a+b), (a-b), (a*b), or (a b) There could be some whitespace between parentheses, numbers, and operations. Evalation of expressions corresponds to the operation signs for addition, subtraction, multiplication, and expo- nent (power). For example, the expression (2+3) (5-3)) can be evaluated as 25, because 52 25 lut The standard input contains several expressions that need to be evaluated. Your program must read them and print results. You should print result as soon as you read each expression. You can assume that all expressions arev alid. Output For each expression, you must evaluate it and print the integer result on a line by itself. If during evaluation, it turns out that you need to make an exponent a b where b is less then zero, evaluate it to be 1, i.e., to be the same b was 0 Sample Input Sample Output Sample Output, with visualized whitespace 7 36 (1 2) (2 (3-5)) + ((5-3) (10-5)6 17 25 17 250 (23) (3*2)) Note: _ is a space, andis a newline character Some Hints A recommended approach is to use a recursive evaluation function. In this function, you can try to read an integer using scanf, and if it works (i.e., scanf returns 1) you return the integer. Otherwise Problem C: Integer Expressions ming language, and she needs a module Jane Coder is building a parser for a customized program to process some integer expressions. As a starting specification, she decided to implement the following operations 4, (addition),-(subtraction), *, (multiplication), and (exponent). To make parsing easier, she also decided to use parentheses around each operation with two operands Your task is to write a program to evaluate such expressions. The expressions that need to be evaluated can be described as follows: 1. First, any integer is an expression. 2. Second, if we have two expressions, let us call them a and b, then we can write a larger expres- sion in one of the following four ways: (a+b), (a-b), (a*b), or (a b) There could be some whitespace between parentheses, numbers, and operations. Evalation of expressions corresponds to the operation signs for addition, subtraction, multiplication, and expo- nent (power). For example, the expression (2+3) (5-3)) can be evaluated as 25, because 52 25 lut The standard input contains several expressions that need to be evaluated. Your program must read them and print results. You should print result as soon as you read each expression. You can assume that all expressions arev alid. Output For each expression, you must evaluate it and print the integer result on a line by itself. If during evaluation, it turns out that you need to make an exponent a b where b is less then zero, evaluate it to be 1, i.e., to be the same b was 0 Sample Input Sample Output Sample Output, with visualized whitespace 7 36 (1 2) (2 (3-5)) + ((5-3) (10-5)6 17 25 17 250 (23) (3*2)) Note: _ is a space, andis a newline character Some Hints A recommended approach is to use a recursive evaluation function. In this function, you can try to read an integer using scanf, and if it works (i.e., scanf returns 1) you return the integer. Otherwise

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions