CS代写 | 留学生计算机辅导 | Assignment代做 | Code代做 | 论文辅导

CS代写 | 留学生计算机辅导 | Assignment代做 | Code代做 | 论文辅导

留学生C语言代写 - COMP20007-assignment1

2025-04-09

留学生C语言代写 - COMP20007-assignment1

Specification

The uqexpr program evaluates expressions and assignment operations entered on stdin or from a file.


Expressions

An expression is a combination of variables, numbers and operators that are evaluated to a single number.
For example, sin(3.14/variable) is an expression that equals approximately 0 if variable = 1, and 1 if variable = 2.


Assignment Operations

Assignment operations have a single equals sign (=) and a single variable on the left-hand side (LHS) of the equals sign and an expression on the right-hand side (RHS).
Example:

E = m*c^2

If m = 2 and c = 3*10^8, then E is assigned the value 18*10^16.


Command Line Arguments

The program is run as:

./uqexpr [--def string] [--looping string] [--significantfigs number] [inputfilename]

Examples:

./uqexpr
./uqexpr ./input_file.txt
./uqexpr --significantfigs 5 toEvaluate.txt
./uqexpr --def ThisIsAVariable=3.14 --looping ThisIsALoopVariable,5,-1,-5
./uqexpr --significantfigs 7 --looping x,0,1,5 --def a=1 --looping loop,10,-1,-1 --def b=3.14 expr.txt

Argument Meanings

  • --def: specifies the initial value for a variable in name=value form. Can be used multiple times.
  • --looping: defines a loop variable in name,start,increment,end form. Can be used multiple times.
  • --significantfigs: sets number of significant digits for printed values (default is 3, max is 9).
  • inputfilename: file containing expressions and assignments.

Input & Variable Validation

Command Line Check

If invalid:

uqexpr [--def string] [--looping string] [--significantfigs 2..9] [inputfilename]

Then:

uqexpr: invalid command line

Exit code: 11

If input file can’t be opened:

uqexpr: unable to read from file "filename"

Exit code: 3

Variable Checking

  • --def must be name=value
  • --looping must be name,start,increment,end
  • Names must only include [A-Za-z], 1–24 characters
  • Duplicate variable names are not allowed

Errors:

uqexpr: one or more variables are invalid     # Exit code: 2
uqexpr: duplicate variables were found        # Exit code: 14

Program Behaviour

On Startup

Welcome to uqexpr.
sXXXXXXXX wrote this program.

Then print variables and loop variables:

If --def hello=1 --def world=2

Variables:
hello = 1
world = 2

If none:

No variables were found.

If --looping x,0,1,10 --looping y,10,-0.123456,5

Loop variables:
x = 0 (0, 1, 10)
y = 10 (10, -0.123, 5)

If none:

No loop variables were defined.

If no input file:

Submit your expressions and assignment operations below.

Expression and Assignment Evaluation

Lines are read from stdin or input file. Lines starting with # are ignored.

Expression:

  • No =
  • Must compile with tinyexpr

Assignment:

  • Exactly one =
  • LHS must be a valid variable name
  • RHS must compile with tinyexpr

If invalid:

Error in command, expression or assignment operation

If expression:

Result = value

If assignment:

var = value

Exiting the Program

When EOF is detected:

Thank you for using uqexpr!

Exit code: 0


Special Commands

@print

Prints current state of variables:

@print

Example output:

Variables:
hello = 5
HeLLo = 3.1
Loop variables:
x = 10 (10, -0.25, 5)
y = 0 (0, 1, 10)

@range var

Redefines or defines a loop variable:

@range y,10,-0.25,5

If invalid:

Error in command, expression or assignment operation

@loop var expression

Loops through a variable range and evaluates:

@loop y expression

For each iteration:

when y = value
Result = ...

Or for assignments:

when y = value
var = value

If error:

Error in command, expression or assignment operation

Other Requirements

  • Must free memory before exiting.
  • Undefined behavior is allowed for variable names that match built-in tinyexpr functions like sin, cos, etc.

Example Session

Example 1:

$ ./uqexpr --significantfigs 5

Input:

hello
z = 1
23 + 10
# comment line
e

Output:

Error in command, expression or assignment operation
z = 1
Result = 33
Result = 2.72

Example 2:

$ ./uqexpr --significantfigs 5 --def ambientTemperature=29.0 \
           --def humidity=49.5 --def windSpeed=0.1 inputFile

inputFile contains:

# comment
this is an invalid expression
a = 1
b = 2
c = 3
V = (4/3) * pi * a * b * c
apparentTemperature = ambientTemperature + ...

Output:

Error in command, expression or assignment operation
a = 1
b = 2
...
apparentTemperature = 31.452

Example 3:

$ ./uqexpr --looping x,1,1,3 --def sum=0 --def n=5 --significantfigs 7

Loop used to approximate:

∫[0 to 1] (-ln x)^n dx

Updates sum each iteration using @loop x expression.


联系我们

WeChat:pythonyt001
Email: [email protected]
17921737610209_.pic.jpg

  • 1