The purpose of this programming project is to write a C++ program that uses
programmer-defined functions to validate user input, calculate some results, and
then print out a triangle shape to the screen based on input from the user.
• As with all homework programs in this course, your program’s output will
initially display the department and course number, your name, your EUID,
and your email address.
• You will first prompt the user to enter an even integer between 2 and 12,
inclusively. You will validate the user’s input by creating a programmerdefined function to ensure that the integer is an even integer in the range 2
to 12, inclusively.
The integer entered by the user should be passed as a
parameter to this function. If the number is not valid, you will display a
meaningful error message before re-prompting the user to enter the integer
The return type of this function should be a boolean data type and
you are to use this boolean result in determining whether or not the user
input is valid. You may assume that the user enters an integer, though it
may be out of range.
• Once validated, you will calculate and return the product of the integers
from 1 to the integer entered by the user using another programmerdefined function. Again, the integer entered by the user should be passed as
a parameter to this function.
The return type of this function should be an
integer data type and you are to use this integer result and print it to the
screen in a meaningful message.
• Finally, you will draw a right-justified right-angled triangle using a
programmer-defined function that accepts an integer as a parameter. The
integer entered by the user will specify the number of rows of integers that
will form the triangle.
In other words we may say that this integer entered
by the user represents the height of the triangle. Each row in the triangle
will be composed of a certain integer number (and space where needed)–
the topmost row will contain one 1, the second row will contain two 2’s, the
third will contain three 3’s and so on and so forth.
You may only use cout
statements that print a single integer, space, or a single new-line character
(such as ‘\n’ or endl). Maximize your use of repetition with nested for loops
and minimize the number of cout statements.
This function should be a void
function that does not return a value. It should print a right justified right-
angled triangle of the appropriate size entered by the user. See the sample
program runs for examples of what should be output.
• Your code should be well documented in terms of comments. For example,
good comments in general consist of a header (with your name, course
section, date, and brief description), comments for each variable, and
commented blocks of code.
• Your program source code should be named “ homework3.cpp ”, without the
• Your program will be graded based largely on whether it works correctly on
the CSE machines (e.g., cse01, cse02, …, cse06), so you should make sure
that your program compiles and runs on a CSE machine.
• This is an individual programming assignment that must be the
sole work of the individual student.
You may assume that all input will be of the appropriate data type, although
the range (e.g., a positive integer) may not be valid. Please pay attention to
the SAMPLE OUTPUT for specific details about the flow and input/output of
You shall use techniques and concepts discussed in class – you are not to
use global variables, goto statements, or other items specifically not
recommended in this class.
On a piece of paper (or word processor), write down the algorithm, or sequence of
steps, that you will use to solve the problem. You may think of this as a “recipe”
for someone else to follow.
Continue to refine your “recipe” until it is clear and
deterministically solves the problem. Be sure to include the steps for prompting
for input, performing calculations (i.e. product calculations), and displaying
You should attempt to solve the problem by hand first (using a calculator
as needed) to work out what the answer should be for a few inputs. Show the
hand calculations for the function that calculates the “product” and show a trace
of the variables involved in that function.
Type these steps and calculations into a document (i.e., Word, text, or PDF) that
will be submitted along with your source code. Note that if you do any work by
hand, images (such as pictures) may be used, but they must be clear and easily
This document shall contain both the algorithm and any supporting
hand-calculations you used in verifying your results.
Test your program to check that it operates as desired with a variety of inputs.
Then, compare the answers your code gives with the ones you get from hand
Your program will be graded based largely upon whether it works correctly on the
CSE machines, so you should make sure your program compiles and runs on the
CSE machines. Your program will also be graded based upon your program style.
This means that you should use comments (as directed), meaningful variable
names, and a consistent indentation style as recommended in the textbook and in
We will be using an electronic homework submission on Blackboard to make
sure that all students hand their programming projects on time. You will submit
both (1) the program source code file and (2) the algorithm design document to
the Homework 3 dropbox on Blackboard by the due date and time.
Note that this project must be done individually. Program submissions will be
checked using a code plagiarism tool against other solutions, so please ensure
that all work submitted is your own. Note that the dates on your electronic
submission will be used to verify that you met the due date and time above. All
homework up to 24 hours late will receive a 50% grade penalty. Later submissions
will receive zero credit, so hand in your best effort on the due date.
As a safety precaution, do not edit your program (using vi or pico) after you have
submitted your program where you might accidentally re-save the program,
causing the timestamp on your file to be later than the due date. If you want to
look (or work on it) after submitting, make a copy of your submission and work off
of that copy.
Should there be any issues with your submission, this timestamp on
your code on the CSE machines will be used to validate when the program was
Example program header:
• Add a header to each function. Example function header: