Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 2433 C/C++ Programming Programming assignment 4 Due date and time: 11:59 PM, February 15, 2020 Much of this program is exactly as for the

image text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

CS 2433 C/C++ Programming Programming assignment 4 Due date and time: 11:59 PM, February 15, 2020 Much of this program is exactly as for the previous programming assignment, but there are also significant changes. One is the use of stderr as the output stream for all error message. The second is the way the operand stack is to be handled. The third is the addition of two operands: swap and copy. Problem: Write a program, named p4.c, that behaves in the manner describe in the "usage" message listed below, either printing the usage message when the first command-line argument is "--help", or upon identifying the -rpn command-line argument accepting input from stdin. You must write appropriate error messages to stderr if an error arises, whether an unrecognized command line argument, a stack underflow or overflow, unrecognized input or any other error condition that may arise in your code. Naming: Your submitted file is to be named p4.c. This will be the last pure C program of the semester. Output: Your program's normal output must be to stdout and of one of the formats following, assuming argc and argv are the usual parameters for main() and where is argv[O] If argv[1] is "--help", display the following. Usage: " --help" display this usage material. " -postfix" The program accepts input from standard input as a sequence of numbers and operators. The numbers (operands, as integers or floating point numbers) read are pushed on a stack until needed. When an operator is read, the required operands are popped from the stack and used to perform the calculation, with the result placed on the stack. Valid operators are +, -, * and 7, are interpreted as addition, subtraction, multiplication and division, respectively, as described below. An additional operator is =, which indicates that the value at the top of the stack is popped from the stack and displayed along with the number of values remaining on the stack, whereupon the program terminates. Stack underflows generate an error message and halt the program, as do a stack overflows. Unrecognized input tokens produce error messages and result in program termination, as do unrecognized command line arguments. The size of the stack is 10. Stack operations are performed so as to produce results identically as indicated here. + : push(pop() + pop(); -: temp = pop(); push(pop() - temp; *: push (pop() * pop(); /: temp = pop(); push (pop() / temp; swap : t1 = pop(); t2 = pop(); push(t1); push(t2); copy : temp = pop(); push(temp); push(temp); = : pop stack top and display it as the result with the number of stack elements remaining. The above describes the majority of the behavior of the program you are to write. To reiterate and expand important points: If the first command-line argument is "--help", subsequent command-line arguments are ignored, the usage message is displayed and the program terminates. If the first command-line argument is "-postfix", subsequent command line arguments are ignored and the program proceeds with reading from standard input. Invalid/unrecognized command-line arguments produce a suitable error message, display the usage information above, and terminate the program. If an unrecognized token is read from standard input, a suitable error message for the type of error is to be displayed with the usage text and the program terminated. If all inputs are recognized and no errors arise, print the following to stdout. CS 2433 C/C++ Programming Programming assignment 4 Due date and time: 11:59 PM, February 15, 2020 Much of this program is exactly as for the previous programming assignment, but there are also significant changes. One is the use of stderr as the output stream for all error message. The second is the way the operand stack is to be handled. The third is the addition of two operands: swap and copy. Problem: Write a program, named p4.c, that behaves in the manner describe in the "usage" message listed below, either printing the usage message when the first command-line argument is "--help", or upon identifying the -rpn command-line argument accepting input from stdin. You must write appropriate error messages to stderr if an error arises, whether an unrecognized command line argument, a stack underflow or overflow, unrecognized input or any other error condition that may arise in your code. Naming: Your submitted file is to be named p4.c. This will be the last pure C program of the semester. Output: Your program's normal output must be to stdout and of one of the formats following, assuming argc and argv are the usual parameters for main() and where is argv[O] If argv[1] is "--help", display the following. Usage: " --help" display this usage material. " -postfix" The program accepts input from standard input as a sequence of numbers and operators. The numbers (operands, as integers or floating point numbers) read are pushed on a stack until needed. When an operator is read, the required operands are popped from the stack and used to perform the calculation, with the result placed on the stack. Valid operators are +, -, * and 7, are interpreted as addition, subtraction, multiplication and division, respectively, as described below. An additional operator is =, which indicates that the value at the top of the stack is popped from the stack and displayed along with the number of values remaining on the stack, whereupon the program terminates. Stack underflows generate an error message and halt the program, as do a stack overflows. Unrecognized input tokens produce error messages and result in program termination, as do unrecognized command line arguments. The size of the stack is 10. Stack operations are performed so as to produce results identically as indicated here. + : push(pop() + pop(); -: temp = pop(); push(pop() - temp; *: push (pop() * pop(); /: temp = pop(); push (pop() / temp; swap : t1 = pop(); t2 = pop(); push(t1); push(t2); copy : temp = pop(); push(temp); push(temp); = : pop stack top and display it as the result with the number of stack elements remaining. The above describes the majority of the behavior of the program you are to write. To reiterate and expand important points: If the first command-line argument is "--help", subsequent command-line arguments are ignored, the usage message is displayed and the program terminates. If the first command-line argument is "-postfix", subsequent command line arguments are ignored and the program proceeds with reading from standard input. Invalid/unrecognized command-line arguments produce a suitable error message, display the usage information above, and terminate the program. If an unrecognized token is read from standard input, a suitable error message for the type of error is to be displayed with the usage text and the program terminated. If all inputs are recognized and no errors arise, print the following to stdout

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

Students also viewed these Databases questions

Question

e. What do you know about your ethnic background?

Answered: 1 week ago

Question

b. Why were these values considered important?

Answered: 1 week ago