Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
Introduction
Student Conduct
This is an individual assignment. You should feel free to discuss general aspects of C programming andthe assignment specification with fellow students, including on the discussion forum. In general, questions like“How should the program behave if h this happensi ?” would be safe, if they are seeking clarification on the specification.
You must not actively help (or seek help from) other students or other people with the actual design, structure and/or coding of your assignment solution. It is cheating to look at another person’s assignment code and it is cheating to allow your code to be seen or shared in printed or electronic form by others. All submitted code will be subject to automated checks for plagiarism and collusion. If we detect plagiarism or collusion, formal misconduct actions will be initiated against you, and those you cheated with. That’s right, if you share your code with a friend, even inadvertently, then both of you are in trouble. Do not post your code to a public place such as the course discussion forum or a public code repository. (Code in private posts to the discussion forum is permitted.) You must assume that some students in the course may have very long extensions so do not post your code to any public repository until at least three months after the result release date for the course (or check with the course coordinator if you wish to post it sooner). Do not allow others to access your computer – you must keep your code secure. Never leave your work unattended.
You must follow the following code usage and referencing rules for all code committed to your SVN repository (not just the version that you submit):
|
Code Origin |
Usage/Referencing |
|
Code provided by teaching staff this semester
Code provided to you in writing this semester by CSSE7231 teaching staff (e.g., code hosted on Blackboard, found in /local/courses/csse2310/resources on moss, posted on the discussion forum by teaching staff, provided in Ed Lessons, or shown in class). |
Permitted
May be used freely without reference. (You must be able to point to the source if queried about it – so you may find it easier to reference the code.) |
|
Code you wrote this semester for this course
Code you have personally written this semester for CSSE7231 (e.g. code written for A1 reused in A3) – pro vided you have not shared or published it. |
Permitted
May be used freely without reference. (This assumes that no reference was required for the original use.)
|
|
Unpublished code you wrote earlier
Code you have personally written in a previous enrolment in this course or in another UQ course or for other reasonsand where that code has not been shared with any otherperson or published in any way. |
Conditions apply, references required
May be used provided you understand the code AND the source of the code is referenced in a commentadjacent to that code (in the required format – see the style guide). If such code is used without appropriate referencing then this will be considered misconduct. |
|
Code from man pages on moss
Code examples found in man pages on moss. (This does not apply to code from man pages found on other systems or websites unless that code is also in the moss man page.) |
|
|
Code and learning from AI tools
Code written by, modified by, debugged by, explained by, obtained from, or based on the output of, an artificial intelligence tool or other code generation tool that youalone personally have interacted with, without the assistance of another person. This includes code you wroteyourself but then modified or debugged because of yourinteraction with such a tool. It also includes code youwrote where you learned about the concepts or libraryfunctions etc. because of your interaction with such atool. It also includes where comments are written by sucha tool – comments are part of your code. |
Conditions apply, references & documentation req’d
May be used provided you understand the code AND the source of the code or learning is referenced in a com ment adjacent to that code (in the required format – see the style guide) AND an ASCII text file (named toolHistory.txt) is included in your repository and withyour submission that describes in detail how the tool wasused. (All of your interactions with the tool must be captured.) The file must be committed to the repository at the same time as any code derived from such a tool. If such code is used without appropriate referencing and without inclusion of the toolHistory.txt file then this will be considered misconduct. See the detailed AI tool use documentation requirements on Blackboard – this tells you what must be in the toolHistory.txt file.
|
|
Code copied from sources not mentioned above
Code, in any programming language:
|
Prohibited
May not be used. If the source of the code is referenced adjacent to the code then this will be considered code without academic merit (not misconduct) and will be re moved from your assignment prior to marking (which may cause compilation to fail and zero marks to be awarded). Copied code without adjacent referencing will be consid ered misconduct and action will be taken.
This prohibition includes code written in other program ming languages that has been converted to C. |
|
Code that you have learned from
Examples, websites, discussions, videos, code (in any pro gramming language), etc. that you have learned from or that you have taken inspiration from or based any part of your code on but have not copied or just converted from another programming language. This includes learningabout the existence of and behaviour of library functions and system calls that are not covered in class.
|
Conditions apply, references required
May be used provided you do not directly copy code ANDyou understand the code AND the source of the code or inspiration or learning is referenced in a comment adjacent to that code (in the required format – see the style guide). If such code is used without appropriate referencing then this will be considered misconduct. |
In short – Don’t risk it! If you’re having trouble, seek help early from a member of the teaching staff.Don’t be tempted to copy another student’s code or to use an online cheating service. Don’t help another relationship. You should read and understand the statements on student misconduct in the course profile and on the school website: https://eecs.uq.edu.au/current-students/guidelines-and-policies-students/ student-conduct.
Specification
Assignment Operations
Command Line Arguments
The square brackets ([]) indicate optional arguments. The italics indicate placeholders for user-supplied value arguments. uqexpr expects zero or more option arguments beginning with “--” to follow the command name (with an associated value argument after --def, --loopable and --significantfigures). Option arguments can be in any order. A single optional filename for the input file to be read will follow this – if it is absent then expressions and assignment operations will be read from stdin. It is acceptable to run uqexprwith no command line arguments. It is also possible to provide filename as an argument without any option arguments.
./uqexpr./uqexpr ./input_file.txt./uqexpr --significantfigures 5 toEvaluate.txt./uqexpr --def ThisIsAVariable=3.14 --loopable ThisIsALoopVariable,5,-1,-5./uqexpr --significantfigures 7 --loopable x,0,1,5 --def a=-1 --loopable \
loop,10,-1,-1 --def b=3.14 expr.txt
- --def – this argument specifies the initial value for a given variable. If this argument is present then it must be followed by a string containing a variable name and value pair. A variable name should have an equals sign (=) after it, followed by a number to initially set the variable to. For example, to initialise the variable hello to the value 1, then the string that follows --def should be hello=1. The --def argument can be specified multiple times on the command line to define multiple variables.
- --loopable – this argument specifies that the following variable can be looped through in expressions and assignment operations. Loop variables should have a name and range (i.e. start, increment and end values) separated by commas (,). For example, to set the variable x to loop from 10 to 5 in increments of -0.25, then the string that follows --loopable should be x,10,-0.25,5. The @loop command can be used to execute loops. The initial value of a newly defined loop variable should be its start value. The --loopable argument can be specified multiple times on the command line to define multiple loop variables. Refer to the Range Command and Advanced Functionality sections for more details about the use of loop variables.
- --significantfigures – this single digit argument specifies the maximum number of significant figures of numerical values printed to stdout. For example, if --significantfigures 5 is specified, then printed numbers will have at most five significant figures. If --significantfigures is not specified, then the default maximum number of significant figures (4) will be used. --significantfigures can only be specified once on the command line. You can print out a floating point number to a specified maximum number of significant figures using the printf() or fprintf() format specifier %.*g. The first argument is the maximum number of significant figures and the second argument is the value to print.
- filename – a filename specified at the end of the command line is the name of an input file containing expressions and assignment operations to be evaluated. If present, it is always specified last. If a filename is not specified, then expressions and assignment operations will be read from stdin. The filename string cannot begin with “--”. If the user wants to specify a file whose name does start with “--” then they should prefix the name with “./”.
Before doing anything else, your program must check the command line arguments for validity. If the program receives an invalid command line then it must print the following message:
to standard error (with a following newline), and exit with an exit status of 10.
Refer to the Command Line and Variable Checking section for information on how to determine the other rules of command line checking.
Checking whether an input file exists or can be opened is not part of the usage checking (other than checking that filename is not an empty string). Checking the contents/format of the strings following --loopable and/or --def is not part of the usage checking (other than checking that the strings are not empty). These are checked after command line validity as described below.
File Checking
uqexpr: unable to open input file "filename " for reading
to standard error (with a following newline) where filename is replaced by the name of the file from the command line. The double quotes must be present. Your program must then exit with an exit status of 14.
Variable Checking
- A string after --def must be in the form name=value, i.e. variable names and values should be separated by an equals sign (=). The value is treated as a double precision floating point number.
- A string after --loopable must be in the form name,start,increment,end, i.e. the start value, increment value and end value are specified after the loop variable name and are comma (,) separated. These values should be treated as numbers of type double. Refer to the Hints section for a function that can be used to convert a string to double. The increment value is used in each loop iteration to update the loop variable and therefore cannot be 0. The increment value should be positive if the start value is less than the end value. The increment value should be negative if the start value is greater than the end value. It is permissible for the start value to equal the end value, in which case the increment value can be any number other than 0.
- Variable names must contain only letters (a to z, A to Z) and must have a length between 1 and 25 letters inclusive.
- See the Command Line and Variable Checking section below for more information.
If any of the above requirements are found to be violated whilst checking variables, then your program must print the message:
to standard error (with a following newline). Your program must then exit with an exit status of 11.
Command Line and Variable Checking
- Are variable names case sensitive?
- What range of values is permitted to follow the --significantfigures option on the command line? (Hint: see the usage error message above.)
- What happens if the filename string begins with “--”?
- What happens if an empty string is given as a command line argument (in any position)?
- What happens if the --significantfigures argument is given more than once on the command line?
- What happens if an argument is given after any filename ?
- What happens if an option argument (--def, --loopable or --significantfigures) is not followed by an option value argument?
- What happens if an unexpected argument appears on the command line?
Program Behaviour
If the above checks are successful, your program must print the following message to standard output (stdout), with a newline at the end of each line:
Your program must then print the initialised variables that were identified and their value, each separated by a newline. The value should be formatted using the maximum number of significant figures specified by the --significantfigures option argument. If --significantfigures was not specified on the command line, then the default value (4) should be used. For example, if --def hello=1 --def world=2 is specified on the command line, this message must be printed:
Variables:
hello = 1
If no initialised variables were specified, then this message must be printed instead:
Your program must then print the loop variables that were identified, each separated by a newline. The current value, start, increment and end values should be formatted using the maximum number of significant figures specified by the --significantfigures option argument. If --significantfigures was not specified on the command line, then the default value (4) should be used. For example, if --loopable x,0,1,10 --loopable y,10,-0.123456789,5 --significantfigures 5 is specified on the command line, this message must be printed:
If no loop variables were specified, then this message must be printed instead:
After variables are reported, the following message must be printed if no input file was specified on the command line, i.e. lines are to be read from stdin:
Expression and Assignment Operation Validation and Evaluation
Your program must then repeatedly read lines from the input file (or stdin if no input file was specified). Each line is terminated by a newline character or pending EOF. Lines beginning with a hash symbol (#) are considered comments and ignored. The line (excluding any terminating newline) will then be evaluated for its validity. If the line entered is not a valid expression or assignment operation, your program must print the following message (terminated by a newline) to stderr and attempt to read another line from the input file or stdin :
Error in command, expression or assignment operation detected
The rules for valid expressions are:
- No equals sign (=) present in the line read.
- Able to be compiled by the tinyexpr library without error. See the Provided Libraries section below for more details about the tinyexpr library. The expression should be compiled using all validated loop and non-loop variables.
- One equals sign (=) present in the line read.
- he RHS of the assignment operation (i.e. the part after the equals sign) must be able to be compiled by the tinyexpr library without error.
- The LHS of the assignment operation should contain a single variable name and no other variable names, numbers or operators. Whitespace characters are permissible before and after the variable name. If a variable name is valid and is not an existing variable, then it is to be defined as a new non-loop variableand its value is to be set to the result after the RHS is evaluated by the tinyexpr library. Refer to the Hints section for more details.
to standard output (stdout) with a following newline, where value is replaced by the result after evaluating the expression and is formatted according to the --significantfigures option argument.
to standard output (stdout) with a following newline, where var is replaced by the variable name and value is replaced by the result after evaluating the expression and is formatted according to the --significantfigures option argument. Assignment operations entered by the user can assign values to variables that are dependent on the values of other variables, e.g. y = 2 + x and x = 2 * x are valid assignment operations.
Your program must then attempt to read another expression or assignment operation from the file or stdinand repeat the above process.
Exiting the Program
Print Command
./uqexpr --significantfigures 2 --loopable y,0,1,10 --loopable x,10,-0.25,5 \
If the @print command is specified by the user via stdin or the input file, the following lines should be printed to stdout :
Note that “No variables were specified.” and “No loop variables were identified.” lines should be printed instead of “Variables:” and “Loop variables:” if no non-loop or loop variables have been defined, respectively.
The @range var command allows the user to define additional loop variables or redefine the range of existing loop variables. There should be no leading or trailing characters (including whitespace) before or after the command, respectively. There should be a single space between @range and var . var is replaced by a string that follows the same format as the string that follows --loopable on the command line and should be subject to the same checks, e.g. variable names must be letters only. For example, to set the variable y to loop from 10 to 5 in increments of -0.25, then the command entered via stdin or within the input file should be:
Assuming that --significantfigures 2 was specified on the command line, the following line should be printed to stdout, containing the name and range of y :
Note that since the range of existing loop variables can be redefined, it is permissible for existing loop variable names to be specified in a @range var command. It is also valid to convert an existing non-loop variable to a loop variable3 . No loop variables are (re)defined if any errors are found in the vars argument. If the commandis valid, the value of the variable is set to be the start value of the range. If the command entered is invalid, your program must print the following message (terminated by a newline) to stderr and attempt to read another line from the input file or stdin :
Advanced Functionality
For assignment operations specified in the @loop command, your program must evaluate the expression on the RHS of the assignment operation and then store the result in the memory location of the variable on the LHS. For both expressions and assignment operations specified in the @loop command, your program must print their respective evaluation messages described previously with the following string appended to the end of each message before the newline:
where var is replaced by the loop variable name and value is replaced by its respective value for that iteration and is formatted according to the --significantfigures option argument.
If any errors are detected while evaluating the @loop command (e.g. non-existent loop variable or invalid expression or assignment operation), then the loop should not be executed and var must maintain the value it had before the @loop command was issued. Your program must print the following message (terminated by a newline) to stderr and attempt to read another line from the input file or stdin:
Other Requirements
(Your program does not have to free memory if it exits due to a signal, e.g. the interrupt signal generated by pressing Ctrl-C.)
For any aspects of behaviour not described in this specification, your program must behave in the same manner as demo-uqexpr. If you’re unsure about some aspect, then you can run the demo program to check theexpected behaviour.
We will not test for unexpected system call or library failures in an otherwise correctly implemented program (e.g. if malloc() fails due to insufficient available resources). We will not test your program by defining variables that have the same name as tinyexpr functions or constants, e.g. sin, cos, tan, sqrt, e and pi. Your program can behave however it likes in these cases, including crashing.
Example Sessions
Example 1: Example uqexpr session with only --significantfigures specified on the command line and demonstrating the use of the @print command. Note that the user presses Ctrl-D (to terminate input – detectedby the program as EOF) just before the line “Thanks for using uqexpr.” is printed.
Example 3: Example uqexpr session with --loopable, --def and --significantfigures arguments specified on the command line and the use of @range, @print and @loop commands. A loop variable is used to perform integration. The factorial of n can be calculated using R 0 1 (− ln x) n dx. This integral will be evaluated to find the factorial of 5, which we expect to be 120. Note that x is set to 1 initially and the @range command changes its value to 0.000001 (1e-06). After the loop, the value of x is 0.999999 instead of 1 due to a floating point rounding issue. During the loop, each iteration uses and updates the current value of sum.
Provided Libraries
The tinyexpr library has been pre-compiled into a shared library for you, providing all of the functions and data types required.
These functions are declared in /local/courses/csse2310/include/tinyexpr.h on moss. To use them, you will need to add #include
You will also need to link with the library containing these functions. To do this, use the compiler arguments
Using the tinyexpr library
Example 4: tinyexpr usage example using argv to dynamically define arbitrary variables and evaluate an arbitrary expression.
- te_variable variables must be bound to a memory location that can hold a double precision floating point number.
- After variable binding, te_compile is used to compile the expression string for later evaluation.
- If compilation fails, te_compile will return NULL and the errPos variable will be updated to the character number in the string where the parse error occurred.
- After parsing and compilation, updates to the original variables (x, y and z in this example) will be reflected on each call to te_eval().
- After you are finished with an expression, release the memory by calling te_free().
Style
Your program must follow version 3 of the CSSE2310/CSSE7231 C programming style guide available on the course Blackboard site. Your submission must also comply with the Documentation required for the use of AI tools (if applicable).