Assignment 1
Assignment 1
Assignment 1
Assignment #1
OBJECTIVE:
Through three assignments, we will learn how to apply the concepts learned in this course to
develop a simple command-line calculator using programming language C.
In the first assignment, we are going to kick off the initial step of developing the calculator. How?
Yes, first write informal pseudocode for this program and then convert it to a flowchart. You
should also prepare the skeleton of the C program that includes some initial tasks along with the
simplest operations. Then in the following assignments, you will gradually complete the program
step by step, based on what we learn in class.
Part A: Brief introduction to the Command-line Calculator:
This assignment aims to design a straightforward command-line calculator. With this calculator,
users can easily select basic operations: addition, subtraction, multiplication, and division. To start
the program, a menu of five options appears. It is worth noting that for this initial assignment, only
options B and E are functional. Selecting any another should result in an error message. Option E
ends the session with a simple goodbye, while option B guides users through inputting two
numbers and an operation. The result of the calculation is then promptly displayed, then it is back
to the main menu for the next menu selection. For clarity, a sample program output will be
provided, with user interactions clearly marked in bold-italic.
Welcome to my Command-Line Calculator (CLC)
Developer: Print your name here
Version: Assignment 1
Date: Print revision date here
1
Please enter the operation ( + , - , * , / ):
*
Please enter the second number:
3
The result is 54
Please select your option ( B , U , A , V , E )
B
Please enter the first number:
9
Please enter the operation ( + , - , * , / ):
-
Please enter the second number:
13
The result is -4
Please select your option ( B , U , A , V , E )
E
Thanks for using my Simple Calculator. Hope to see you soon again, Goodbye!
1. In-line comment: type // and then write the comment. The rest of the line after // will be
considered as comments and not the actual program code
Example:
#include <stdio.h> // C Standard Library for input/output functions
2. Multi-line comment: type /* and start writing your comment in one or more lines. In the
end, finish the comments by typing */
Example:
Save the file in the format of a C source file as clc.c in your working directory, i.e.,
/home/yourUserName/fall/comp1400 (or other base directories). Note that ~ (also known
as the home directory) is equivalent to the /home/yourUserName directory.
While in your working directory (~/fall/comp1400), you can now compile the C program
with the following command to produce an executable.
gcc -Wall clc.c -o clc.out
You can run the executable file with the following command.
./clc.out
Submission Instruction:
You have to submit your solutions as A SINGLE ZIP FILE into Brightspace before the deadline. The zip
file name is your student id (for instance, if your student id is 1234567, the zip file name would be
1234567.zip) that includes one or two pdf files for non-programming questions, and one c file (a text
file with extension c) for the c program.
PLEASE DO NOT submit any other types of files, such as compiled files (ex. clc.out), files associated with
specific software, etc. Therefore, for assignment one, your zip file should contain the following files:
- One text file (.txt) for the pseudocode (or word exported as pdf) (part B)
- One pdf or screenshot (.png or .jpg) for the flowchart (Part C) If you create your flowchart in Raptor,
please also include the .rap file. You can have one pdf document containing both part B and C if needed.
- One C file, named "clc.c", which should be a simple text file, containing your c program (Part D). Please
check the extension and make sure it is a C file format (.c).
Submission of other file types will make problems for grading your assignments, and you will lose a partial
or complete mark. The C program should be tested and working prior to submission, we recommend
testing it on nomachine with gcc -Wall.