MTRX1702 - C Programming
Assignment 1
This assignment requires you to design and build a program to compute and display tables of
trigonometric values.
This assignment should take an average student 15 hours to complete.
Submission deadline: 11:59pm on Sunday 22nd of September. Do not miss the deadline; 20% of
the maximum possible mark will be deducted for each working day it is overdue. This assignment
is to represent individual work. You are not to collaborate with your peers, this is an individual
assignment. Similar code designs will be treated with suspicion.
1 Submission Format
The code submission must consist of the source (*.c) and header (*.h) les containing your program.
No other les are to be submitted. (Do not submit an executable le or Visual Studio project les
or the like.)
The code and statement of compliance is to be packaged in a single zip le
sid_1234.zip
where, in place of 1234, you shall put your own SID number. This zip le is to be emailed to
j.ward@acfr.usyd.edu.au
with the words \mtrx1702 assignment" in the subject eld. Please follow these submission instruc-
tions precisely. Failing to do so may lead to a lost entry, and deductions for lateness. [Be sure to
remember to attach the zip le to the email; it is all too easy to forget. A good idea is to cc the
email to yourself.]
The proportion of the overall marks allocated to each component of the assignment is indicated
after the title enclosed in square brackets.
2 Basic Speci cation [60%]
You are required to write a program that calculates and displays values of the trigonometric functions
sine, cosine, and tangent for user-supplied angular values. The basic program must comply with the
following speci cation.
1. When the program is run, it is to display a short welcome message.
TRIG: the trigonometric calculator
2. The program shall display a message prompting the user to enter input from the keyboard.
Please input request (h-help, q-quit):
3. The following help message shall be displayed whenever the user types the letter h at the input
prompt.
1
The input format is a single line of letters and numbers comprising
the following fields:
<types> <start-value> <final-value> <intermediate-rows>
These fields must be input in the order shown above, where <types>
is a set of letters, and the others are single numbers defining
the range of computation. The <types> field consists of zero or more
of the letters from the set <stcdr>, which indicate respectively,
(1) The desired trig functions: sin, tan, cos.
(2) Whether to use degrees or radians for input parameters.
Example input: scr 0 2.3 3
4. The program shall exit if the user types the letter q at the input prompt.
5. The user may enter a single line of input composed of four elds separated by whitespace,
<types> <start-value> <final-value> <intermediate-rows>
where the angle brackets < > indicate particular information elds as described below.
6. The eld <types> shall be zero or more of the letters stcdr, indicating sine (s), tangent (t),
cosine (c), degrees (d), or radians (r) to indicate trigonometric function types and input units.
7. The eld <types> shall be followed by three numerical values that indicate, in order, the
starting value for the calculations, the nal value for the calculations and the number of
intermediate rows in the table. The rst two values are
oating point, the latter is a positive
integer.
8. The following defaults shall be implemented when all or part of the <types> eld is missing:
(a) If no function type is speci ed, all 3 trigonometric functions shall be displayed.
(b) If no unit type is speci ed, units of entry shall default to degrees.
9. The program shall respond to all inputs in a case insensitive manner. i.e. any letters are valid
in both upper and lower case.
10. The program shall validate user input, and recover gracefully from illegal input. Since a user
might enter any arbitrary string of characters, many di erent errors are possible, including:
Specifying both d and r in the <types> eld.
Entering invalid letters in the <types> eld.
Entering letters or symbols instead of numbers in any of the last three elds.
Failing to enter exactly three numerical values after the <types> eld.
Entering a negative or non-integer value for the number of intermediate rows.
11. On detection of illegal input, the following error message shall be displayed:
Error: Illegal input!
2
12. The results shall be displayed in a tabular format, with the rst column containing the angle
values in degrees, the second column containing the angle values in radians and the next
columns containing the values of the requested trigonometric functions. The values in each
row shall be delimited by the comma character (ASCII 0x2C).
13. The rst row of the table shall display headings describing the contents of the columns.
Degrees,Radians,Sin,Cos,Tan
The headings for degrees and radians shall always be shown, but those for sin, cos and tan are
only displayed if the functions are selected.
14. After displaying the tabular output or an error message, the program shall return to the input
prompt (see Item 2 above).
15. The program shall be implemented consistent with the principles of modular designs. A multi-
le approach to modularity is highly recommend, as is a principled design approach prior to
the implementation of any source code.
3
Example Output
Please input request (h-help, q-quit): trs 0 -2.3 3
Degrees,Radians,Sin,Tan
0.000,0.000,0.000,0.000
-32.945,-0.575,-0.544,-0.648
-65.890,-1.150,-0.913,-2.234
-98.835,-1.725,-0.988,6.433
-131.780,-2.300,-0.746,1.119
Please input request (h-help, q-quit): q
3 Extensions [20%]
If the basic speci cation as described above is implemented, the maximum possible mark for the
assignment shall be 80%. In order to gain a mark of greater than 80%, one or more extensions must
be implemented. These extensions should extend the functionality of the above program in a useful
and appropriate way, given the speci ed goals of the program. Extensions are:
If a set of command-line arguments are provided, generate a table from those arguments
without asking for user input.
Provide the option to dump the output to a text le in addition to the screen output.
Provide the option to change the delimiter between elds in the output table.
Accept as a user input the format speci er used to produce each value in the table.
4 Documentation [20%]
The documentation for this assignment shall comprise two components. In-source documentation,
and a separate short report.
Appropriate commenting and descriptive variable names should be used in all source code to
maximise readability. This will be marked by the tutors based on their ability to understand the
operation of the code without reference to the accompanying report. This in-code documentation
should NOT discuss design decisions, but simply the implementation of the program. Each function
must have a comment header block describing the inputs, outputs and a one-sentence description of
the operation of the function.
You are also to submit a document of no more than one page stating your program's com-
pliance, which describes how well the implemented programme complies with the speci cation in the
assignment sheet. It must identify all points of non-compliance, and may provide a justi cation for
this non-compliance. This document must also clearly and brie
y describe the additional function-
ality provided by any extensions. Finally you must attach a completed usyd plagiarism statement
http://web.aeromech.usyd.edu.au/plagiarism/Compliance_Statement.doc to the report.
4
Hints
1 Standard Functions
You may use any standard library functions. The following are likely to be most useful.
Header <stdio.h> has input/output functions: fgets(), sscanf(), printf()
Header <math.h> has mathematical functions: sin(), cos(), tan()
Header <ctype.h> has character functions: isdigit(), isalpha(), isspace(), tolower()
Header <string.h> has string manipulation functions: strlen(), strcpy(), strcmp()
Header <assert.h> has the bug-catching macro assert()
For details on how to use printf() for formatted text output, such as generating a trig table,
see Section 13.1.1 of the course textbook. For information on any standard library functions, try
the following web resources:
http://www.cppreference.com/
http://www.cplusplus.com/reference/clibrary/
http://en.wikipedia.org/wiki/C_standard_library
2 Modular Coding
Your solution is to emulate the principles of modular software design. You are break the problem
into a number of functions, each with a speci c task, and each communicating data via well-de ned
interfaces. In particular, the main() function should be free from low-level implementation details,
relegating all tasks to subfunctions.
Your code will contain numerous functions, but you may choose whether or not to implement the
program using multiple les. If you choose a multi le structure, be sure to present only the public
interface in header- les.
3 Commenting
Appropriate commenting is an important aspect of good coding style. Each function should be ade-
quately commented to state its purpose and, if necessary, to describe the properties of its arguments
and return value. The code within each function should contain commenting as you deem necessary,
but keep in mind that excessive commenting is worse than none at all, so do not restate what is
obvious from the code. Be sure to use a neat and consistent formatting style throughout your code
to assist code readability.
5
相关文章
- 08-07c语言 关于存储一个大于该数值类型范围的数之后的输出结果
- 08-07结构体作业讲解(零基础学习C语言)
- 08-07简单的c语言数据结构的 合并两个表的数据;
- 08-07高级语言程序设计:综合程序设计实验
- 08-07C++程序设计入门 之常量学习
- 08-07C语言
- 08-07C语言 main
- 08-07【413】C 语言 Command line
- 08-07c语言之在main中获取命令行的参数
- 08-07C语言学习-day03