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 consists of written homework and programming***
***All
parts are required to get a grade on this homework ***
WRITTEN
HOMEWORK QUESTIONS
1. Create an Algorithm for the process of sending a message to a
friend (text, email, voice mail, other? – which ever you use most). Give your algorithm to a friend and see if
they are actually able to send a message based on your step by step description
and without any prior knowledge of how the phone works! Write in outline
form in complete sentences.
2. Ethics and Security. You received a message from a friend.
They were talking about some issues at their job and co-workers. You thought
there were some things in the message you wanted another to know about so you
forwarded it. They did the same. And so on until it got back to one of the
co-workers. When we send information to someone, what is our expectation of the
security or “ownership” of that message? What is the ethical responsibility of
someone receiving such a message? Discuss.
3. Modularity. What does the term “modularity” mean and what does good modularity in an algorithm do for us? Define (in your own
words) modularity and then give three examples of how it can be used as a
powerful tool for our algorithms and ultimately our programs.
C++
PROGRAMMING PORTION
The
purpose of this first program is get you familiar with
arrays, the subscript operator in C++, and begin using functions. Break down
the problem into small functions with no function exceeding 20 lines of code
(not including blank lines, variable definitions or comments). In this
programming assignment, you are not
allowed to use global variables. Create
main as a manager delegating responsibility to other functions to do the actual
work.
To get full credit for the programming
portion, you will need to:
1.
Turn in an algorithm written using full English sentences
(the algorithm will be pass/no-pass for the first assignment). It should be
supplied as part of your header comments. This is NOT the same algorithm as the
homework portion previously described. This is about the algorithm for solving
the programming part of this assignment. This is worth 20% of the assignment’s
grade
2.
Make sure to put your name in your program
3.
Program using a consistent style of indentation,
header comments for each function, inline comments for
each major block of code. This is also worth 20% of the assignment’s grade.
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
Program Assignment:
Background:
Have you ever written a paper where the teacher asked for specific length (in
words) or a particular format (e.g., two spaces after each period). I often
submit work to websites where they limit the number of characters I enter.
Luckily WORD provides a character counter! In fact, this type of functionality
is standard with most word processing software.
Your job for program #2 is to create a simple word
processor that will allow the user to enter in a paragraph and our program will
analyze what was provided and make some necessary modifications.
Specification:
1.
Allow
the user to enter in a paragraph, ending with a # <return>
2.
Analyze
the paragraph and display:
a.
The
number of alphabetic (A-Z, a-z) characters
b.
The
number of non-white space characters (we will assume that whitespace is a
space, newline, and tab)
c.
The
number of words (separated by whitespace). Realize the last word may not end in
whitespace!
d.
The
number of times the word “the” was used.
3.
Alter
the paragraph and display it with:
a.
Two
spaces after each period
b.
No
space between a word and a comma
c.
Each
sentence has the first word capitalized (we will assume that a sentence ends in
a period, exclamation point, or question mark).
4.
Continue
until the user wants to quit
You may add more to this program!
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. You should read in the paragraph
using the 3 argument version of cin.get.
2.
EVERY
SINGLE TIME you do ANY input operation, make sure to
do a cin.ignore afterward!
3.
The
program should continue until the user wants to quit. Allow them to continue
until they are done.
4. You
may not use any global variables in this program!
5. You
may not use the string class – instead use arrays of characters. You are allowed
to use the cstring library with strcpy,
strlen, and strcmp.
6.
Make
sure to use C++’s I/O (iostream library) for I/O
On the due date, turn in:
1.
Submit
your assignment to the D2L
Dropbox (sign on via http://d2l.pdx.edu/)
2.
Email
a backup copy to karlafgr@cs.pdx.edu
3.
Remember
to turn in an algorithm with your
programming portion (in the header comments). It is worth 20% of your program
grade.
4.
And, don’t forget to add comments and to work on your program’s readability;
this is another 20%!!