A3-Strings and Conditions

Table of Contents


Objectives

  • Work with sequences of variables
  • Work with different types of data
  • Start declaring and using string variables
  • Start calling (invoking) string member functions
  • Start using if-statements.
  • Explore pair programming.

Academic Honesty

Read the Scholastic Honesty Policy and Assignment Integrity policies of the syllabus. Here are some clarifications for this particular assignment:

  • You are encouraged to work with one other student of this class following the rules of Pair Programming for Homework Assignments. If you choose to pair program, there is a bonus applied.
  • You may not give a copy of your code to your designated pair-programming partner if you did not develop the code together.
  • You may not show your completed code to another person or look at another person's code until you complete and submit this assignment, except for code you develop together with your pair-programming partner.
  • You may get help from people other than your pair-programming partner if you get stuck, but only if they do not show or tell you the code to type.
  • Remember that the instructor performs similarity tests on programming project submissions, and copied or plagiarized code is usually very easy to detect.

Preparation

  1. Make sure you have completed the exercises from lesson 3.
  2. Complete the Review Exercises in CodeLab 3. These exercises will help prepare you for the problem-solving programs and should be completed first.

Project Specifications

Your solutions to these project must only use techniques we have covered so far.

Programming Style

For all programs, remember to follow all the style rules we covered including:

  1. File block comments.
  2. Placement of curly braces and indentation within curly braces, including if-else-if-else Formatting.
  3. Limiting line length to about 80 characters.

    TextPad, and most other text editors, tell you both the line and column location, which lets you check the line length.

  4. No tab characters in your code.

    You can remove tab characters by either setting up TextPad correctly (see here) or by running a program named astyle (see here).

  5. Spaces before and after operators.
  6. Meaningful variable names and consistent naming style (caps vs. underbars).

Image
Image source

Project 1: Paycheck Calculator

Those of us who work for a living look forward to -- payday! Payday is a specified day when one is paid, usually workers collecting wages from their employers. On payday we get our paycheck.

In this project we calculate a paycheck based on the number of hours worked minus deductions. In addition, we calculate a pay stub showing the pay and deductions.

Project Specifications
  1. Write a program that calculates the pay for an hourly worker.
  2. Name the source code file paycheck.cpp and include all your code in this single file.

    Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.

  3. Ask the user for the following inputs (and no other input) in this order and each on their own line, as shown in the Example Run below:
    1. first name and last name
    2. hourly rate
    3. hours worked last week

    Hint: Be sure to declare two string variables, one for the first name and one for the last name. Make sure to input both of the variables using code like:

    cin >> first >> last;
    
  4. Calculate both the regular pay and overtime pay, assuming any number of hours over 40 is paid at time-and-a-half.

    Hint: We can calculate the number of hours of overtime by subtracting 40 from the total hours worked.

  5. After calculating the gross pay (money before taxes), calculate Social Security Insurance (SSI) at 6.2% and Medicare at 1.45%.
  6. Subtract both SSI and Medicare from the gross pay to calculate net pay.
  7. Display both a Pay Stub and a Paycheck exactly as shown in the Example Run below.

    However, you may choose anyone to sign the check - even yourself!

  8. Numbers may not display with exactly two decimal places, which is fine. Display the output using the default formatting and precision for the numbers - do NOT add any formatting statements to the code.
  9. Example Run: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and wording of the output. For the input shown you must get the same output, except possibly who signed. However, the output must change properly if the inputs are different.
    Enter your first name and last name: Ed Parrish
    Enter your hourly rate: 23.45
    Enter the number of hours you worked last week: 42
    +----------------------------------------+
    
     Pay Stub
     Regular pay  $938
     Overtime pay $70.35
     Gross pay    $1008.35
     Social Sec.  $62.5177
     Medicare     $14.6211
     Net pay      $931.211
    
    +----------------------------------------+
    
     Pay to:  Ed Parrish
     Amount of:  $931.211
                     Signed: Mega Corp
    
    +----------------------------------------+
    

    In the above example run, the user entered the values shown in italics (for emphasis) to produce the output. Your program does NOT print the characters in italics, nor does the user input appear in italics.

  10. After displaying the output, exit the program.
  11. Submit the source code file paycheck.cpp with the rest of the assignment as described in Deliverables.
Hints:
  • Use a different string variable for first name and last name.
  • To align the $ in the output, use either tab characters (see lesson 3.2.4) or just print the correct number of spaces like:
    cout << " Net pay      $" << netpay << endl;
    

What Part of
Pseudopseudohypoparathyroidism
Don't You Understand? ☺

Project 2: The Longest Word

According to the Oxford English Dictionary, the longest word used in the English language is pseudopseudohypoparathyroidism [1].

Most of the time, "longest" words are merely made up and not really used in the English language (except as examples of the longest word). The longest word currently listed in Oxford dictionaries is like this and is not actually used in English: the supposed lung-disease pneumonoultramicroscopicsilicovolcanoconiosis (45 letters). [2]

The formal names of DNA and chemical compounds are almost unlimited in length. Dictionary writers tend to regard such names as "verbal formulae", rather than as English words. [2] [3]

Project Specifications
  1. Start by downloading the worksheet: longestword.cpp.

    Add to the existing code to complete the project. Leave the existing code unchanged, except for comments.

  2. You must name the source code file longestword.cpp and include all your code in this single file.

    Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.

  3. Add your name and the date to the file comment block at the top of the file where shown in the comments.
  4. Do NOT add any user input (cin) to this project. If you have a cin statement in your code, you will get a low score.
  5. Using the length() function, print the length of the word where indicated in the comments. See the Example Run to verify correctness.
  6. Print the first and last indices of the word where indicated in the comments. See the Example Run to verify correctness.
  7. Using the substr(index, numChars) function, print the first and last letters (characters) of the word where indicated in the comments. See the Example Run to verify correctness.
  8. Using the substr(index, numChars) function, print at least 4 different but valid dictionary words you find as a single substring (same order as in the word and without skipping letters) of the word pseudopseudohypoparathyroidism, each on their own line. For example, write a cout statement like this:
    cout << longWord.substr(20,7) << endl; // should print thyroid
    

    Include a comment, as shown above, that states what word you are trying to spell. Verify your words are valid by looking them up in the Oxford English Dictionary. Valid words cannot be informal (slang), proper nouns (names of things), or non-English words.

  9. Example Run: The outputs of the program must look like the following for full credit, including the same order of words in the output.
    ***Long Words Worksheet***
    The length of pseudopseudohypoparathyroidism is 30
    The first letter index is 0 and the last letter index is 29
    The first character is p
    The last character is m
    Four or more words contained inside pseudopseudohypoparathyroidism are:
    thyroid
    (4 or more words listed here, each on their own line like the one above)
    

    You may print the example word thyroid but must add at least 3 more.

  10. After displaying the output, exit the program.
  11. Submit this project with the rest of the assignment as described in Deliverables.
References and More Information
  1. pseudopseudohypoparathyroidism: Oxford English Dictionary
  2. What is the longest English word?: Oxford English Dictionary
  3. What's 30 letters long and rhymes with nothing (literally)?: from Computer Science Canada
  4. The Long Word Song: song with pronunciation from YouTube

Image
Image source

Project 3: Your "Rock" Star Name

If you were a rock idol, what would your stage name be?

Performers often adopt a stage name - something that is memorable and conveys a particular image, their public persona. This seems to be particularly noticeable with music artists.

How do "Rock" Stars choose a stage name? Write this program to find out! [1]

Project Specifications
  1. Write a program that gives the user a "rock" star name.
  2. Name the source code file rockstar.cpp and include all your code in this single file.

    Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.

  3. Ask the user for the following inputs (and no other input) in this order and on their own line, as shown in the Example Run below:
    1. first name
    2. favorite color
    3. birth month (1-12)
  4. Use a series of if-statements to generate a birthstone from the birth month.

    Refer to the American Gem Society page [2] to identify the birthstones. If a month has more than one birthstone, choose any one of them for your if-statement.

  5. Example Run: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and wording of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different.
    Welcome! This program will tell you your "Rock" Star Name
    Please enter your first name: Edward
    Please enter your favorite color: Red
    Please enter your birth month (1-12): 7
    Your "Rock" Star Name is: Edward the Red Ruby
    

    In the above example run, the user entered the values shown in italics (for emphasis) to produce the output. Your program does NOT print the characters in italics, nor does the user input appear in italics.

  6. Your program must include the complete output message shown, including the double-quote marks ("), for full credit.
  7. After displaying the output, exit the program.
  8. Submit the source code file rockstar.cpp with the rest of the assignment as described in Deliverables.
Hints:
  • Use an escape character \" to print double quote marks.
References and More Information
  1. At least its one way to generate a "Rock" Star name. 😉
  2. Birthstones by Month: American Gem Society
  3. Birthstone: Wikipedia article

Extra Credit

The following are worth extra credit points:

  1. Complete the assignment using pair programming with the same person for all three projects. (2 points)
  2. Complete the longestword.cpp program and list 7 or more words contained within pseudopseudohypoparathyroidism. (1 point)

    The words must be in the Oxford Engish Dictionary and not be informal (slang) words or proper nouns (names of things).

  3. Create a second file named rockstarxc.cpp. Complete this "Rock" Star program with no if-statements or relational expressions, and without using techniques we have not covered. Submit rockstarxc.cpp with the rest of the assignment as described in Deliverables. (2 points)

    Hint: Make a very long string "Garnet Amethyst Aquamarine..." in which you add spaces such that each birthstone name has the same length with the spaces added. Then use the substr() function to extract the needed name from the string.

    Hint: To not exceed 80 characters code width, break your long string into shorter strings and then reassemble them using the concatenation operator "+" or the append operator "+=".

Make certain that your README.txt file describes any extra credit completed.

Tutorial Lab

In preparation for next weeks lessons, complete the following:

  1. Read the assigned reading in the textbook
  2. Complete the Tutorial Exercises in CodeLab 3 before the specified due date.

    Refer to the assigned reading for the next lesson to help you understand the problems. Also, you can use the online lecture notes for more information as the notes become available. You can look at solutions if you miss your first few attempts and are stuck by clicking the "Solution" tab.

Grading Criteria

The instructor will evaluate your assignment using the following criteria. Thus you should check your assignment against these criteria to maximize your score.

Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive. Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.

For information on grading policies, including interpretation of scores, see the syllabus.

Lesson Exercises

  • 2: All lesson exercises attempted and turned in
  • 1: Some lesson exercises completed and turned in
  • 0: No lesson exercises completed or turned in

Problem Solving Programs (x3)

  • 5: Demonstrates mastery of the program
    • Applies concepts from the lessons appropriately
    • Meets all specifications (see above)
    • Runs to completion with no abnormal error conditions
    • Generates correct output given correct input
    • Correct file name
  • 4: Has most of the functionality expected of the program
    • Demonstrates some techniques from the lesson
    • Attempts to meet all but one of the specifications (see above)
    • Implementation seems more complicated than necessary.
    • May have one minor error
  • 3: Has some of the functionality expected of the program
    • Demonstrates some techniques from the lesson
    • Attempts to meet at least 1/2 of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have 2-3 minor errors
  • 2: Serious functional problems but shows some effort and understanding
    • Attempts to meet less than 1/2 of the of the specifications (see above)
    • Has a major error or many minor errors
    • Implementation seems very convoluted
    • Demonstrates few techniques from the lesson
  • 1: Does not compile or wrong file turned in
  • 0: Not turned in or uses techniques not covered

Problem Solving Programs Style

  • 3: Code is well-documented including:
  • 2: Code has a minor documentation error
  • 1: Code has some documentation errors
  • 0: No apparent attempt to follow documentation standards or write documentation comments

CodeLab Exercises

  • Number CodeLab completed correctly / number exercises * 8 and rounded up to the nearest integer.

README.txt File

  • 2: README.txt file submitted following the instructions
  • 1: README.txt file submitted but some information was missing
  • 0: No README.txt file submitted

Total possible: 30, plus extra credit

Deliverables

Students submit some homework as they work on it like CodeLab. However, students must submit other homework in Canvas following the link to A3-Strings and Conditions. Include the following items when submitting to Canvas:

  1. README.txt file prepared by following the instructions for submitting homework.
  2. All the exercise files from Lesson 3
    • nameapp.cpp
    • selection.cpp
    • students.txt
  3. paycheck.cpp
  4. longestword.cpp
  5. rockstar.cpp
  6. Optionally rockstarxc.cpp (extra credit)

Note: Make certain your programs compile before you turn them in. When a program does not compile then it does not function either. For all programming projects, you should expect little or no credit if your program does not compile and run. For more information see the Grading Criteria.

You must submit all the files needed to complete your assignment. Your assignment must work as submitted. Remember to test and double check your files before submitting them. If you make a mistake, you can resubmit up to the deadline. If you resubmit, you must include all your assignment files in the last submission as Canvas hides prior submissions.

Last Updated: November 06 2017 @01:03:55