CS 111 Assignment 2
- Files to print out and bring to lecture and recitation
- Preparations before you begin your homework
- Assigned programming problems
- Preparing to hand in your homework
This assigment is due Monday, February 27, on which date there will also be a quiz.
- Files to print out and bring to lecture and recitation
Below is a tutorial and example programs. Please make printouts of these and bring them with you to both lecture and recitation. However, please do NOT print them out in an on-campus lab. (On-campus printers are to be used only for your homework, i.e. for files YOU wrote.) If you do not have a computer at home, with a printer, ask a friend or classmate to print out copies of the following files for you.
- Tutorial:
- Examples to accompany the Tutorial on characters and strings - brief intro
- Preparations before you begin your homework
On forbin, create a directory named hw02 inside your homework directory. Change your present working directory to hw02 and then copy into it the example files for this homework assignment, by typing, at the "[username@venus hw02]$" prompt:
cp ~nixon/cs111/hw02/* .Please do NOT copy these files into your home directory, to avoid cluttering your home directory. If you inadvertantly copied them into your home directory, move them out using the mv command. Be very careful about deleting anything in your home directory, to avoid inadvertantly deleting your hidden files (.login, .cshrc, .profile, etc.).
Play with the example programs when reading the tutorials. Then, when you are ready to begin work on the homework assignment itself, it is recommended that you delete the example files, or at least most of them, in order to save disk space.
In the assigned problems, pay careful attention to readability issues, such as indentation. You may lose up to 5 points (out of 10) for bad indentation, depending on how bad it is.
ANSWER NO MORE THAN ONE PROBLEM PER SHEET OF PAPER. At the top of each sheet, put (1) your for name (as known to the Registrar's office), (2) the last 4 digits of your student ID number, (3) "CS 111 Spring 2002 Assignment 2," and (4) your lab section.
- Assigned programming problems
- Programming exercises with strings.
(6 points) Write two versions of a program which prompts the user to enter one's first name, then prompts the user to enter one's last name, then outputs the user's initials. Your first program, initialsCString.cpp, should use C-strings to store the first and last names, assuming that the first name will always be no more than 15 characters long and that the last name will always be no more than 30 characters long. Your second program, initialsString.cpp, should use string class objects to store the first and last names.
- Escape sequences.
(4 points) Write a program practiceEscape.cpp which displays EXACTLY the following output:Below is a typical Unix pathname: /home/sp06/111//myaccount/somedirectory/mytext.txt Below is a typical DOS pathname: C:\Windows\Desktop\somedir\mytext.txt Both are pathnames of files named "mytext.txt".You will need to use some escape sequences, as discussed in the Tutorial on characters, strings, and debugging.
Your program should not do any input.
- Preparing to hand in your homework
the following files should be emailed to your instructor (all attached, together, to one email message):
- initialsCString.cpp,
- initialsString.cpp,
- practiceEscape.cpp
To recitation/lab on the due date, bring a stapled-together bundle of printouts of the above-listed source code files. Your printouts must be stapled together in exactly the order listed above.
Back to: