Assignment #2
CS 162: Introduction to Computer Science
Submit your assignment to the D2L Dropbox
Email a backup copy to karlafgr@cs.pdx.edu
***Assignments
in CS162 consist of written homework and programming***
The written
portion MUST be turned in to get a grade on an assignment
LATE work
will be accepted – but ONLY within a week of the original due date.
We do not
accept late work beyond that
1. Create an Algorithm for the process that you go through to learn
new syntax (e.g., learning the “for” loop). What steps did you take to learn it
– and how would you train someone else to go through this process. Give your algorithm to a friend (someone who
doesn’t necessarily know C++!) and see if they can go through the steps!
2.
Terminology –
explain what the following terms mean and give an example of how it is
used in your own words.
·
Loop
invariant
·
Side
effects
·
Modular programming
3.
Ethics and
Security. Last
assignment you addressed issues of software usability and revisions and how
those errors cause ethical and legal implications. Computer ethics also involves
the security of data. When people use computer software, they may gain access
to sensitive or secure information, such as your bank account balance, account
number, or credit card number. Have you ever wondered how secure your credit
card information is when you shop (now with Target it may not be so secure!)
As a
software designer, what could be done to limit someone’s exposure to sensitive data - limiting the
risk of identify theft? Write 5 complete sentences with your thoughts.
C++
PROGRAMMING PORTION
·
Remember to
write an algorithm for the program and pay close attention to “style”!
·
Also, do your
work for your programming part on either of these systems:
1. linuxlab.cs.pdx.edu (linux)
2. cs.pdx.edu (unix)
4. Programming. The purpose of the second program is to continue refining
our programming skills in C++ and practice using arrays of characters, the subscript operator, functions
with arguments. Our goal is to create programs with small functions where
main delegates to a series of functions where the real work takes
place. In this programming assignment, you are not allowed to use global variables; this means that all variables
must be defined within your functions and then passed to other functions as needed.
Limit your functions to no more than 30 statements of code (for executable
statements, not counting variable
definitions, blank lines, lines with just curly brackets, or comments).
Program Assignment:
As I sit here at my computer,
surrounded by my grid of 7 monitors, I realize that I spend great quantity of
time typing and relying on “word processor” type of software to correct my
errors. Common errors that I make include not capitalizing at the right time, or capitalizing too often, spelling “the” wrong (my
fingers type at a rate that it always comes out “teh”).
But sometimes, like when I am on my iPad, I need a document correct without all
of the overhead of a word processor.
Your job, this time, will be
to create a program that will correct common errors in a paragraph entered by
the user. Allow the user to enter in a paragraph, with no more than 300
characters. Have the user type the ‘#’ when they are done entering in the
paragraph. Then, your program should correct the following and output the new
paragraph:
·
The
first letter of the paragraph should be capitalized
·
The
first letter of each sentence should be capitalized. A sentence is defined to
end with a period, exclamation point, or question mark.
·
Prompt
the user for a commonly misspelled word (e.g., “teh”)
and ask for the correct spelling (e.g., “the”). Replace all occurrences of the misspelled
word with the correct replacement.
·
Make
sure there are TWO SPACES after each period.
Once this is completed for the
paragraph, and the new paragraph displayed. Allow the user to do this again!
***You are always welcome
to do more! But, really focus on making general purpose functions that can be
re-used. Anytime you have code that has already existed elsewhere (such as to
error check input or give the user another chance), write a function instead!
Things
you should know...as part of your program:
1.
Make
sure to prompt the user for any input requested. Make sure it is clear from your
prompts what the user is expected to do.
2.
Use the cstring
library with strlen to determine the length of the words entered.
3.
Use
the subscript operator [] to work with individual characters in the paragraph
4.
Consider
having a SECOND array for the result. It will be easier than trying to move
around characters in the original array.
5. PRACTICE
USING both pass by value and pass by reference!
6. PRACTICE
having functions return a value
7. You
may not use any global variables in this program!
8. You
may not use the string class – instead use arrays of characters
9.
Make
sure to use C++’s I/O (iostream library) for your input and output.
10. After each input operation, make sure to
use cin.ignore to remove the delimiters!
11. FUNCTIONS are required for this
assignment, along with BOTH pass by value and pass by reference!
To
get full credit for the programming portion, you will need to:
1.
Turn in an algorithm written using full English
sentences (it may be provided in outline form, paragraph form, or graphical
(such as a data flow diagram)). It can be supplied as part of your header
comments or as a separate file.
2.
Program using a consistent style of indentation,
header comments for each function, inline comments for each major block of code
3.
Make sure to put your name in your program
4.
Submit an electronic copy of your .cpp file as
an attached file to the dropbox on D2L (go to:
http://d2l.pdx.edu/ to login). Make sure to
hit the submit button after uploading your files (otherwise they will be lost)
5.
As a backup, please also email your work (as
attached file(s)) to karlafgr@cs.pdx.edu