In this assignment you are to prepare a C/Objective-C program that will act as a simple
calculator. The calculator will be run from the command line and will only work with integer
numbers and the following arithmetic operators + - x / %. The % operator is the
modulus operator, not the percentage.
For example, if the C/Objective-C program is compiled to calc, the following demonstrates
how it will work
./calc 3 + 5 - 7
In the command line, the arguments are a repeated sequence in the form
and ending in a
Hitting the enter key will cause the program to evaluate the arguments and print the result.
In this case 1.
The program must follow the usual laws of arithmetic which says
1. The x / and % operators must all be evaluated before the + and – operators.
2. Operators must be evaluated from left to right.
For example, using Rule 1
2 + 4 x 3 – 6
2 + 12 – 6
which results in
Assignment 1 – Autumn 2016 Page 2 of 6
If we did not use Rule 1 then 2 + 4 x 3 – 6 would become 6 x 3 – 6 and then 18 – 6 and finally
12. This is an incorrect result.
If we do not use Rule 2 then the following illustrates how it can go wrong
4 x 5 % 2
Going from left to right we evaluate the x first, which reduces the expression to 20 % 2
which becomes 0. If we evaluated the % first then the expression would reduce to 4 x 1
which becomes 4. This is an incorrect result.
Remember, we are using integer mathematics when doing our calculations, so we get
integer results when doing division. For example
./calc 20 / 3
Also note that we can use the unary + and – operators. For example
./calc -5 / +2
./calc +2 - -2
Your program must also check to make sure the command line arguments are correct. If not
your program must generate an appropriate error message and then terminate.
You should also check for division by zero errors and print an appropriate error message.
As part of your program design, it is expected you will create a calculator class that will
handle the evaluation of the command line arguments.
PROGRAM HINTS1. Getting your program to solve expressions that only use the + and – operators is fairly easy. I would suggest you get your program working at this level before attempting to get it to work with the other operators.2. While this problem can be solved using iteration, it is easier to solve using recursion.
In order to clarify how the program works I have placed an executable version of it on
UTSOnline. Your implementation should work in exactly the same manner.
Once you have downloaded it to an Apple machine you will have to make it executable.
Open a terminal to the directory the benchmark is in. Enter the following command
chmod 700 benchmark_name
benchmark_name will be the actual name of the benchmark file.
PLEASE NOTE. When you run the benchmark it says my name. Do NOT include that. Include
yours if you want. If your program includes my name then it will be assumed you are trying
to use the benchmark in the lab demonstration. See assessment below.
Assignment 1 – Autumn 2016 Page 3 of 6
ASSIGNMENT OBJECTIVESThe purpose of this assignment is to demonstrate competence in the following skills.
q Program design
q Array and string manipulation
q Command line arguments
q Creating methods and classes in Objective-C
q Exception handling
q Program testing
These tasks reflect all the subject objectives.
The solution I have for this assignment takes about 200 lines of code, including white space
(blank lines) comments, etc. As part of your subject workload assessment, it is estimated this
assignment will take 22.5 hours to complete.
If you have a question, please contact the subject coordinator as soon as possible.
However, for frequently asked questions a FAQ file will be put up on UTSOnline. Please
check this before emailing the coordinator with a question.
PLEASE NOTE 1: If the answer to your questions can be found directly in any of the following
• subject outline
• assignment specification
• UTS Online discussion board
You will be directed to these locations rather than given a direct answer.
PLEASE NOTE 2: Please do not send email in HTML format or with attachments. They will not
be read or opened. Only emails sent in plain text format will be read. Emails without subject
lines will be automatically deleted by the junk mail filters I have in place.
It is quite possible that errors or ambiguities may be found in the assignment specification or
the benchmark. If so, updates will be placed on UTSOnline and announcements made
regarding the amendment. It is your responsibility to keep up to date on such amendments
and ensure you are using the latest version of the Assignment Specification and Benchmark.
You must upload a zip file of your entire Xcode solution to UTSOnline. Uploading can be
done from the Submit Assign section of UTSOnline. The URL for UTSOnline is as follows.
You should all have an account on UTSOnline. If not, please check with your lab assistant
before emailing me. I will not accept submissions from any other source.
Assignment 1 – Autumn 2016 Page 4 of 6
You may submit as many times as you like until the final due date. The final submission you
make is the one that will be marked.
ACCEPTABLE PRACTICE VS ACADEMIC MALPRACTICE
• Students should be aware that there is no group work within this subject. All work must
be individual. However, it is considered acceptable practice to adapt code examples
found in the lecture notes, labs and the text book for the assignment. Code adapted
from any other source, particularly the Internet and other student assignments, will be
considered academic malpractice. The point of the assignment is to demonstrate your
understanding of the subject material covered. It's not about being able to find solutions
on the Internet.
You should also note that assignment submissions will be checked using software that
detects similarities between students programs.
• Participants are reminded of the principles laid down in the “Statement of Good Practice
and Ethics in Informal Assessment” in the Faculty Handbook. Assignments in this subject
should be your own original work. Any collaboration with another participant should be
limited to those matters described in the “Acceptable Behaviour” section. Any
infringement by a participant will be considered a breach of discipline and will be dealt
with in accordance with the Rules and By-Laws the University. The Faculty penalty for
proven misconduct of this nature is zero marks for the subject. For more information,
Marks will be awarded out of 20 using the following scheme.
• Testing: Between 0 and 10 marks will be awarded from demonstrating your assignment
in the week 10 laboratory. To prepare yourself for the demonstration please take note
of the following pages in UTSOnline.
o Demo Assign. Gives a full description of how the demonstration will be conducted.
In particular, pay attention to the Demonstration Checklist. Failure to have done all
the items in the checklist can lead to zero marks.
o Assign Testing. Gives detailed description of the things you need to test in order to
ensure your program is thoroughly tested before the demonstration.
PLEASE NOTE 1: It is your responsibility to thoroughly test your code to ensure it is
working correctly. That it conforms to every aspect of the specification, makes no false
assumptions and doesn’t generate any unhandled exceptions.
PLEASE NOTE 2: Your final submission to UTSOnline is the one that is marked. It does not
matter if earlier submissions were working; they will be ignored. Download your
submission from UTSOnline and test it thoroughly in your assigned lab.
PLEASE NOTE 3: Your final submission will be tested against the latest version of the
Assignment. It is your responsibility to ensure you keep up-to-date with any
amendments that may occur to the assignment specification.
PLEASE NOTE 4: You must demonstrate your assignment in your assigned laboratory.
You will not be allowed to demonstrate your assignment in a different one. This means
zero for the assignment if you miss your demonstration laboratory time.
Assignment 1 – Autumn 2016 Page 5 of 6
• Design: Between 0 and 6 marks will be awarded on the quality of your code design and
the algorithms used. This includes splitting your code up into well designed classes and
methods, using enumerations and exceptions where appropriate, etc.
• Style: Between 0 and 3 marks will be awarded on the presentation style of the program.
This includes proper indenting and white spacing, helpful comments and meaningful
Your final assignment mark will be out of 20 and will be calculated as follows.
1. Add 4 to your design mark and 7 to your style mark. After this scaling, your test mark will
be in the range of 0 to 10, design in the range 4 to 10 and style in the range 7 to 10.
2. Let L = the lowest of the 3 marks.
Let S = the second lowest of the 3 marks.
Assignment Mark =
In this assignment you are to prepare a C/Objective-C program that will act as a simple