代写ECE 3331 Computer Problem 5

- 首页 >> Algorithm 算法

cp5 p1of2
ECE 3331 Computer Problem 5 Spring 2023
(due 11:59pm 5/22/2023)
An assignment statement consists of four parts:
(a) The left hand side which must be a variable
(b) The assignment operator, =
(c) The right hand side which can be any legal expression
(d) A semicolon, which terminates the statement.
The most complicated part is the RHS, for C allows expressions of various sorts (e.g. function calls, variables,
constants, expressions involving arithmetic operators). But, we will limit the RHS to the one of the following:
(a) A constant
(b) A variable
(c) One function call, with only constants or variables as arguments
(d) An expression with one binary arithmetic operator (+, -, *, /, %) in which the operands must be constants or
variables.
The following are examples of legal RHS of assignment operators under our rules:
X = 12;
x = y;
x = fun( 12 );
X = y + z ;
Y = x+12;
The following are examples of illegal RHS of assignment operators under our rules:
X = fun1(fun2(x)); /* illegal-nested function call */
X = y + z + 10; /* illegal – two operators */
X = fun1(x) + z; /* illegal operand */
X = fun(a1, a2) /* two operands */
X = ‘c’; /*illegal as RHS is not variable or constant, which can only be a number */
X = fun(1c); /* illegal variable name on RHS */
We allow any amount of white space to separate parts of the assignment statement. You may assume that no
assignment statement consists of more than 50 characters including white space (a tab, blank, and newline
counts as a single character).
Write a program that reads in assignment statements one at a time from a file cp5in.txt and then tests whether it
is legal under our restricted syntax bfore moving on to the next statement. If the assignment is legal, output
“This statement is legal”, else if it is not illegal, output “This statement is illegal” without stating what exactly is
wrong with the statement, e.g.
X = 12;
You echo:
X = 12;
This statement is legal
X = y + z + 10;
You echo:
X = y + z + 10;
This statement is illegal
Note, while you do not have to use pointers for this assignment, it is highly recommended.
Follow the C rules for identifiers, under which, for example, a variable’s name may not begin with a number.
Also, you will have to check for variables on the LHS or the RHS of the expression and also as an argument to a
function. The program echoes each statement (there will be multiple statements) as it is read and then prints out
a message about its legality. The function main does only input, output. Use may read in the entire string at
once. Check out function fgets(). The rest of the work must be done by other function(s).
cp5in.txt is an example input file. cp5out.txt is the output corresponding to the input. Your output must be to the
keyboard, however.
Hint: The program needs to remember the previous character read so that the two can be compared. For
example, the assignment statement’s LHS may not consist of a letter, a white space, and another letter.
cp5 p2of2
You will not be given points for documenting your code, but points will be docked if you do not, with a
maximum penalty of -20 points. Again, you must document what each function does and what the different
parameters are for, and critical sections of the code, including how you convert decimal to binary for both decimal
integers and floating point numbers.
******************************************************************************
You may develop your program in Visual Studio or any other IDE of your choice but you must use
standard C.
Some of the more common errors when you move from a C++ system to standard C are:
(1) using C++ style comments (//this is not standard C89)
(2) placing variable declarations AFTER executable statements (works in C++ but not standard C89)
(3) using .C or .cpp as the file extension for the source file rather than .c
Remember that your grade will depend not only on getting the right answers but also on program
documentation (comments). Be sure you include the specified initial comments, describe each variable, and in the
body describe each logical block.
Your entire source program must be in a single file, of type .c, which you must begin with your cougarnet username
followed by the letters cp5 (no spaces, all lowercase). Turn it in to Engineering Blackboard e.g. my cougarnet name
is brsheth and so the file I will turn in is: brshethcp5.c