Question: need coding help on this, make sure test cases work. / / do not include any additional libraries #include / / do not change these

need coding help on this, make sure test cases work.
// do not include any additional libraries
#include
// do not change these constants
#define MAXLINE 80
#define MAXOPER 13
// named constants and strings
enum operations {NOOP, ADD, MUL, DIV, POW};
const char *operation_str[]={"Invalid","+","*","/","^"};
// function prototypes
int process_input(const char *input, char *op_left, char *op_right);
void calc_output(const char *op_l, int op, const char *op_r, char *result);
// do not change any code in main. We are grading based on the format
// of the output as given in the printfs in main.
int main(){
char input_line[MAXLINE];
char left_operand[MAXOPER];
char right_operand[MAXOPER];
char answer[MAXOPER];
int operator;
printf("
PP3: Arithmetic on GF(47) with +*/^ using letters
");
printf("Commands:
\tabc+bbc
\tturtle/frog
\ttiger^one");
printf("\tOperands are no more than 12 letters and no spaces
");
printf("\tCtrl-d to quit
");
printf(">");
// each call to fgets collects one line of input and stores in input_line
// BEWARE: fgets includes the end-of-line character '
' in input_line
while (fgets(input_line, sizeof input_line, stdin)!= NULL){
// clear for next round
left_operand[0]= right_operand[0]= answer[0]='\0';
// check for valid grammar
operator = process_input(input_line, left_operand, right_operand);
if (operator == ADD || operator == MUL
|| operator == DIV || operator == POW){
// print parsed input
printf("'%s'", left_operand);
printf("%s ", operation_str[operator]);
printf("'%s'=>", right_operand);
// perform pseudo arithmetic
calc_output(left_operand, operator, right_operand, answer);
// print result
printf("'%s'
", answer);
} else {
printf("# %s", input_line);
}
printf(">");
}
printf("
Goodbye
");
return 0;
}
/* Parse input of the form SOS where S is a string (i.e., the operand)
* and O (i.e., the operator) is a character.
*
* A string S must consist of up to 12 valid symbols a-z and A-U.
* The operator O must be one character from: +*/^
* Any other characters found in the input, including spaces, are
* grammatically incorrect and invalidate the input.
*
* There must be NO spaces anywhere in the input, including between
* either SO, OS, or leading or trailing spaces.
*
* Input: The input string is collected using fgets. Recall the end-of-line
* character is included in the input string and marks the end of
* the input. This string must not be changed.
*
* Output: There are three outputs from this function.
*
* The return value is one of NOOP, ADD, MUL, DIV, POW which are
* named constants. If the input is invalid for any reason
* then the output must be NOOP. Otherwise the return value
* corresponds to operand O.
*
* If the input is grammatically correct, then two strings are also
* returned, one for each of the left and right operands. If the input
* in invalid the two output strings are undefined.
*/
int process_input(const char *input, char *op_left, char *op_right){
// replace the following with your code
op_left[0]='A';
op_left[1]='\0';
op_right[0]='A';
op_right[1]='\0';
return ADD;
}
/* Pseudo mathematical opertions on the two operands work as follows.
*
* Each character is converted to an integer in the range 1...46, where a is 0,
* b is 1, c is 2,..., z is 25. The operation is then performed using
* math on a finite field with no carries.
*
* If the two input strings are not the same length, then each output character
* beyond the length of the shorter string should be a copy of the character
* from the longer string but with the opposite case.
*
* Input: The two operand strings and the operator are assumed to be valid (and
* are verified as valid in the parse_input function).
*
* Output: The final string generated by the above rules is stored in the
* output string named result. The input strings must not be
* changed.
*/
void calc_output(const char *l_op, int op, const char *r_op, char *result){
// replace the following with your code
result[0]='!';
result[1]='\0';
}
need coding help on this, make sure test cases

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 Programming Questions!