Description
This week’s assignment will have you write a few basic programs that deal with input, output, strings
and variables. Feel free to work in pairs and ask for help early.
Using the Terminal command line, create a folder (using the mkdir command) called lab01 and cd
into that folder. Over the course of this assignment, you’ll will end up adding three c++ source code
files (the filenames will end in ‘.cpp’) inside the lab01 folder. I have added examples of what should
happen when each program is run to the end of this document. Each source code file must have a
preamble at the top (see the programming rules and guidelines document in Blackboard for more on the
preamble).
a) Write a program (lab01a.cpp) to output a tree like this:
*
***
*****
*******
*********
b) Write a program (lab01b.cpp) to output the following expression and result:
1+3+5+7+9=25
You’ll use the expression ”1+3+5+7+9” twice in different ways: once as a string, and once as an
arithmetic expression. The number 25 should not appear anywhere in your source code.
c) Write a program (lab01c.cpp) that asks the user to supply two whole numbers and outputs the
result of multiplying them together. You will need to use variables, for this program, to store and
manipulate the supplied values.
Submitting your work
You should have three source code files in your lab01 folder. Make sure you are in that folder (use the
pwd command) and then run the following to create a zip archive of them:
$ mkdir lastname_firstname_lab01
$ cp lab01a.cpp lastname_firstname_lab01/lab01a.cpp
$ cp lab02a.cpp lastname_firstname_lab01/lab02a.cpp
$ cp lab03a.cpp lastname_firstname_lab01/lab03a.cpp
$ zip –r lastname_firstname_lab01.zip lastname_firstname_lab01/
CSCI 136 Supervised Programming Lab
Lab Assignment #1
Obviously, you’ll need to change lastname and firstname to your actual last and first names in the
steps above. Once you have your zipfile, you can use that file as your submission for the assignment in
Blackboard.
If you are working in pairs, then you should have both of your names included as comments in the
source code file’s preamble (see the programming rules and guidelines document in Blackboard for
more on the preamble). Also, write both your names to the notes section in the submission form when
submitting to Blackboard.
Sample output
a)
$ ./lab01a
*
***
*****
*******
*********
$
b)
$ ./lab01b
1+3+5+7+9=25
$
c)
$ ./lab01c
Enter a number: 3
Enter a second number: 8
The result of multiplying the numbers together is: 24