Submit: Turn in your basecalc.c
source file
using the turnin command
on morbius.mscsnet.mu.edu or one of the
other Systems
Lab machines.
Work is to be completed individually. Be certain to include
your name in the file. You may submit multiple times, but only the
last turnin will be kept. The automatic submission system will not
accept work after the deadline. (See turnin instructional
video HERE. Note that the
video is for a different course number, and that Morbius's domain
name has changed since the video was
made: morbius.mscs.mu.edu
-> morbius.mscsnet.mu.edu)
Include a comment block at the very top of each file that
contains the following:
/**
* COSC 3250 - Project 1
* Explain briefly the functionality of the program.
* @author [your name]
* Instructor [your instructor]
* TA-BOT:MAILTO [your email address]
*/
All Your Base Are Belong To Us*
Write a calculator program that reads in expressions consisting of
integers and the operators +, -, *, /, %, ^ (exponentiation), & (bitwise
AND), | (bitwise OR), << (left shift), and >>
(right shift), and prints the results when evaluated in simple left-to-right
order.
Your calculator should understand positive integers in binary, octal,
decimal, and hexadecimal, but all results will be decimal (base-10)
integers. Binary operands will begin with "0b", followed by a string of
0s and 1s; operands in all other bases will follow the traditional C
language notation.
You should use the getchar library function to read console
input one character at a time. The use of any other library functions for
input is not recommended at this time.
We have provided an example program for your reference, executable on
Morbius as ~brylow/os/Projects/basecalc.
Notes
- The Systems Lab (CU 310) is the primary development environment
for COSC 3250. It is expected that you will learn
to use the required tools for developing, testing, and submitting
your projects on Linux either in person or connected remotely.
The Systems
Lab machines are available locally in Cudahy 310, and can be
accessed remotely via ssh using your CS Department credentials.
(See D2L Laboratory Instructions for instructions for learning
your credentials.) Free secure shell (ssh) clients are readily
available for other platforms, including Windows machines at home
or in the dorms. We
recommend PuTTY for Windows,
and the built-in ssh client in Terminal for MacOS users.
-
The Systems
Lab machines run the Linux operating system. If you need a
refresher on using the UNIX environment, please see
the
UNIX Tutorial.
- This project can seem deceptively complex, but is quite tractable
if you first take the time to design suitable helper functions,
and test those function thoroughly before moving on to the
overall calculator. We encourage the disciplined practice of
test-driven development.
- The internal data representation of the calculator values can be
assumed to be a signed int. You are not required to deal with
overflow and underflow issues.
- Parsing input is always tedious, particularly when the input is
not rigidly constrained with rules like, "all operators must be
surrounded by space on both sides," (which is NOT a constraint for
this assignment). Powerful tools for parsing are covered in COSC 4400
Compiler Construction and to a much lesser extent, COSC 3410
Programming Languages. In lieu of a parser-generator, consider
drawing simple state diagrams for how to recognize an integer in octal,
or how to recognize an integer in hexadecimal. In many cases
with input of this type, it is useful to be able to put back a
character of input once you realize you have read too far. Useful C
routines for implementing this kind of buffering are presented in
Section 4.3 of K&R, (getch() and ungetch()).
- Consider various operational and parsing errors that can take place.
See the reference implementation for appropriate error messages.
- The reference implementation is considered an integral part of the
specifications for this assignment. Project grades will be based in
significant part upon an automated comparison of behavior against the
reference implementation. Devise test cases to discover the expected
behavior, and do your best to match it precisely. Creativity will be
valued in later assignments, but first one must master the tools.
- Use the electronic turnin system to submit your work.
The command is "turnin", followed by the name(s) of files(s) you
wish to submit. The command "turnin -v" will print a listing
verifying the contents of your submission. See "turnin -h" for
a list of other relevant options. The system does not accept work
after the deadline, and neither does the professor.
* - Early Internet meme reference, circa 2001, (en.wikipedia.org/wiki/All_your_base_are_belong_to_us)
[back]
[Revised 2020 Aug 26 00:10 DWB]