Homework Assignment #5

 

CS 161: Introduction to Computer Science 1

 

 

Submit your assignment to D2L’s Dropbox!

 

 

***Homework in CS161 consists of a C++ programg***

*** 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, echos, 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! Place the Algorithm in the Header comments of the program.

 

***Hint: Write the algorithm first!

 

In this assignment we will be developing a program to create a reciept. (For example, think of this as the next application developed for the iPhone). The user will type in what was ordered (such as a resturant or store). Since receipt printers are very small (such as maybe only 2 inches wide), the job of our program will be to display the appropriate description of the items purchased 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 display only 20 characters of an item’s description. If it is more than 20 characters make sure to:

 

a.       Remove all vowels

b.      Make sure there is only 1 space between words (not two or more)

c.       Remove all punctuation

 

If it is still too long, then the final things to be done are:

d.      Remove characters at the end of each word, starting from the last word and moving forward until there are only 20 characters left

 

You must use arrays of characters to achieve this. The result must be placed in a new array of characters before outputting. So, unlike the last program, we can’t just not display something. We want to create a new array that contains only 20 characters of the right stuff. Hint: Spend some time with the algorithm

 

 

 

 

 

1.      Algorithm: Write the algorithm for this project in the header comments of your program

2.      Think about Style. Make sure your program follows these style guidelines

(a)    write programs with 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. Remember that part of ethics is making sure that:

(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 Requirements:

a.       The main program must be smaller than 10 lines long (not including comments or variable definitions)…this means you need to use functions

b.      There must be at least 2 functions with arguments. Both pass by value and pass by reference must be used in this program.

c.       No GLOBAL variables are allowed

d.      Arrays of characters must be used.

e.       Make sure to display a welcome message

f.        Make sure to capitalize the first letter

g.       Make sure to remove the newline after every single time that you read!