Assignment 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

COMP-1400 Fall 2023

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

Select one of the following items:


B) - Binary Mathematical Operations, such as addition and subtraction.
U) - Unary Mathematical Operations, such as square root, and log.
A) - Advances Mathematical Operations, using variables, arrays.
V) – Define variables and assign them values.
E) - Exit
B
Please enter the first number:
12
Please enter the operation ( + , - , * , / ):
+
Please enter the second number:
3
The result is 15
Please select your option ( B , U , A , V, E )
U
Sorry, at this time I don't have enough knowledge to serve you in this category.
Please select your option ( B , U , A , V , E )
A
Sorry, at this time I don't have enough knowledge to serve you in this category.
Please select your option ( B , U , A , V , E )
V
Sorry, at this time I don't have enough knowledge to serve you in this category.
Please select your option ( B , U , A , V , E )
B
Please enter the first number:
18

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!

Part B: Pseudocode: (40 marks)


Using the above explanation and sample program execution, write the pseudocode for the
Command-Line Calculator program. As a hint, some basic structure is suggested which can be
modified and improved. When using while and if, please use indents for their bodies.
1. Start
2. Display welcome message and version information
3. Option = NULL
4. While Option != ‘E’
a) Display menu for user selection
b) Read(Option)
.
.
5. End of loop
6. Display goodbye message
7. End
Part C: Flowchart (40 marks)
Using the pseudocode you wrote in the previous part, draw a flowchart for it. You can use any
flowchart software, like Raptor, Flogorithm, draw.io, or draw it on any software with graphical
capabilities, like Dia (available on the School UNIX server), Word, PowerPoint, or Paintbrush.

Part D: C program (20 marks)


Based on the flowchart and pseudocode you’ve designed on the previous steps, now you are going
to provide the skeleton of the C program for the calculator (meaning all core functionality will be
comments aside from the skeleton of the program).
Your task in this part is to start writing a C program with the following parts completed:
• Include required standard libraries
• Create the main function
• Using C commands display welcome and version messages to the user
• Similarly, display the menu of options and prompt the user to select an option.
• For the other parts, write COMMENTS for each step of the code. Comments are not
executable but will help the reader to understand the code, and can be placed in any part of
the program. The functionality of this section is not required for the first assignment, we
only need comments outlining each step
2
Hint: There are two ways to write comments inside a C program:

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:

/* This program implements a simple command-line calculator, in


which a user can . . .
. . .
*/

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.

You might also like