Homework Assignment #5
CS 161:
Introduction to Computer Science 1
Submit your assignment to D2L’s
Dropbox!
*** Our objective with
homework #5 is to write a complete C++ program using
arrays of
characters and functions! ***
In
homework #5, you will be writing a program from scratch that has (a) an
algorithm, follows (b) style guidelines, considers (c) ethical issues in the
creation of useful prompts, echoes, and data handling, and (d) implements the
problem in C++. The code that you write must be uniquely yours. Everything will be included in
your .cpp file!
***Hint: Write the algorithm first!
1. Create
an Algorithm, in English, create an outline of the steps the program in Part 4 will
have to go through to solve this problem.
2.
Think about Style. Examine the program in Part 4 and justify
how it meets these guidelines:
(a)
header comments with your name, class, purpose of
the program,
(b)
indent consistently, where all code within {}
blocks is indented the same and that all curly brackets line up,
(c)
have “inline” comments throughout, describing the
purpose of the code that follows
(d)
using meaningful variable names, and
(e)
replace the use of
numbers within a program with variables or constants – using meaningful names
to self document the software.
3. Ethics.
Explain how your program
in Part 4 meets the standards of computer ethics:
(a)
The user knows how to respond to prompts
(b)
Integrity of data is kept intact and secure
(c)
Error messages are clear, and
(d)
Erroneous data or garbage data is not allowed
4. Programming.
In this assignment we will be developing a program
to create a CD Label. The user will
type in what they would like on the CD Label in terms of text. Some of the information that should be on the
label could include(you can add more fields if you want):
·
Title (50
characters maximum)
·
Author of the Material (30 characters maximum)
·
Contents (80 characters maximum)
·
Date Written
(e.g., 2/23/2011 stored as an
array of characters)
Since CD labels are
relatively small, the job of our program will be to display the appropriate information
without going over. And, we want it to be reasonably user friendly, so we don’t
want to just chop off the end of the words. Therefore your program will need to
read in one of the items (such as the title) and decide if the user has typed
in too many characters. If they have, then for the last 10 characters in the
field, remove all vowels and continue reading or copying until there is either
no more information or the array is filled.
Hint: Spend some time with the algorithm. Also,
begin small – first make sure you can read in an array of characters. Don’t forget
to remove the newline after EVERY single time you read. This is vital!
Also, on D2L we will discuss strategies for the
algorithm. Make sure to participate.
Programming
Requirements:
(a)
You must use
arrays of characters to achieve this. On approach is to use one larger array to read in the title,
for example, and then decide how much at the end of the array to copy over to the title array.
(b)
The main program must be smaller than 10 lines long
(not including comments or variable
definitions)…this means you need to use functions
(c)
There must be at least 2 functions with arguments.
Both pass by value and pass by reference must be used in this program.
(d)
No GLOBAL variables are allowed
(e)
Arrays of characters must be used. (You may not use
the “string class” in C++)
(f)
Experiment using string copy (strcpy) from the cstring library
(g)
Capitalize the first letter of each of the fields.
You may use toupper from the cctype
library
(h)
Make sure to
remove the newline after every single time that you read!