Question: Write the file infix.c with the the following functions. Include infix.h as the header In this part you will write a calculator for arithmetic expressions

Write the file infix.c with the the following functions. Include infix.h as the header In this part you will write a calculator for arithmetic expressions with binary operations. We will assume that there are only binary operations, there are parentheses for each operation (including the outermost parentheses), and all tokens are separated by single spaces, 6) Write a function that gets an array of tokens representing an arithmetic expression and returns the index of the operator for the outermost operation. int find_operator( char* * expression, int n_tokens) Examples: On input [ "(", "8", "+", "(", "41", "-", "12", ")", ")" ] the function will return 2. This is because the expression is : ( 8 + ( 41 - 12 ) ) and the outermost operation is +. 7) Write a (recursive) function that gets an array of tokens representing an arithmetic expression and evaluates the corresponding expression. int infix_eval_tokens( char* * str, int n_tokens) * You may assume that all intermediate values in the computation are between 0 and 99 ** You may assume that the results of all division operations are integers. 8) Use the functions in part 1 and eval_tokens to write a function that gets a string representing an arithmetic expression and evaluates the corresponding expression. int infix_eval( char * expression) * You may assume that all intermediate values in the computation are between 0 and 99 ** You may assume that the results of all division operations are integers. *** You may assume that all expression are formatted correctly. Examples: "( 25 / 5 )" "( 5 + ( 7 - 2 ) )" "( ( 10 + 6 ) / ( (3 + 7 ) - ( 2 + 4 ) ) )"

infix.c

#include #include #include

#include "infix.h"

int find_operator(char** expression, int n_tokens) { // implement me return 0; }

int infix_eval_tokens(char** expression, int n_tokens) { // implement me return 0; }

int infix_eval(char* expression) { // implement me return 0; }

infix.h

#ifndef INFIX_H #define INFIX_H

int find_operator(char** expression, int n_tokens);

// gets an array of tokens representing an arithmetic expression in infix notation // outputs the value of the expression. int infix_eval_tokens(char** str, int n_tokens);

// gets a string representing an arithmetic expression in infix notation // outputs the value of the expression. int infix_eval(char* arith_expr);

#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!