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).

What Part of
Floccinaucinihilipilification
Don't You Understand? ☺

Project 1: Working with a Long Word

According to the Oxford English Dictionary, one of the longest words used in the English language is floccinaucinihilipilification [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) or are technical words. However, floccinaucinihilipilification, at 29 letters, is a non-technical words that is found in many dictionaries and is occasionally used in certain activities such as politics. [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. [3]

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

    Add to the existing code to complete the project. Leave the existing code unchanged, except where indicated in the comments.

  2. Name the source code file longword.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 floccinaucinihilipilification, each on their own line. For example, write a cout statement like this:
    cout << longWord.substr(7, 1) << endl; // a
    

    Include a comment, as shown above, that states what word you are trying to print. Verify your words are valid by looking them up in the Oxford English Dictionary. Valid words may not be abbreviations, acronyms, initialisms, 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 floccinaucinihilipilification is 29
    The first letter index is 0 and the last letter index is 28
    The first character is f
    The last character is n
    Four or more words contained inside floccinaucinihilipilification are:
    a
    (4 or more words listed here, each on their own line like the one above)
    

    You may print the example word a 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. floccinaucinihilipilification: Oxford English Dictionary
  2. Floccinaucinihilipilification: being spoken in parliment
  3. What is the longest English word?: Oxford English Dictionary
  4. Floccinaucinihilipilification - original song: song with pronunciation from YouTube

Image
Image source: Wikipedia

Project 2: Pirate Name Generator

Pirates are a frequent topic in fiction and movies, and often have "colorful" names and certain stereotypical ways of speaking. Just in time for Halloween, we write a program that will create pirate names for you and your friends.

Then on Halloween, start plunderin' the high seas with yer new pirate name. Y'arrr!

Project Specifications
  1. Write a program that outputs a pirate name given a users first and last name.
  2. Name the source code file pirate.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, as shown in the Example Run below:
    1. first name
    2. last name

    Assume the user enters only valid data.

  4. Use the following algorithm to generate the "pirate name":
    input firstName of user
    input lastName of user
    firstLen = length of firstName
    if firstLen > 6 then firstLen = firstLen - 6
    lastLen = length of lastName
    if lastLen > 7 then lastLen = lastLen - 7
    choose title from "Length of First Name" table based on firstLen
    choose newLastName from "Length of Last Name" table based on lastLen
    pirateName = title + firstName + "the" + newLastName
    output pirateName
    

    Length of First Name
    Length Title
    1 Crafty
    2 Capt'n
    3 Crusty
    4 Legend
    5 Shrewd
    6 Stormy
    Length of Last Name
    Length New Last Name
    1 Black
    2 Crimson
    3 Gold
    4 Gray
    5 Red
    6 Scarlet
    7 Silver

  5. Example Run: The input prompts and outputs of the program must look exactly like the following for full credit, including the same order of input and exact wording and spacing of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different.
    Y'arrr! Git yer pirate name or ye be walkin' the plank!
    Enter your first name: Ed
    Enter your last name: Parrish
    Pirate name: Capt'n Ed the Silver
    
    Y'arrr! Git yer pirate name or ye be walkin' the plank!
    Enter your first name: Joe
    Enter your last name: Schmoe
    Pirate name: Crusty Joe the Scarlet
    

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

  6. After displaying the output, exit the program.
  7. Submit the source code file pirate.cpp with the rest of the assignment as described in Deliverables.

Image
Image source

Project 3: Phone Chatbot

For this programming assignment, we write a basic chatbot program. For fun, try having a conversation with an online chatbot here or here. Some sources estimate that 25% of customer services will be handled by Chatbots in 2020, vs. 2% in 2017 (1).

The chatbot we are designing must ask you the following questions:

  1. What is your name?
  2. What is your phone number?
  3. What is your phone plan?
  4. How many GB of data this month?

Just don't give the chatbot your credit card number! 😉

Project Specifications
  1. Write a chatbot program that interacts with the user as described in the Interaction section below to calculate a phone bill.
  2. Name the source code file phonebot.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. Interaction: Interact with the user with the following inputs in the order given (and no other input) and responses as follows:
    1. Name: open the conversation with a welcome and find out the user's name (string). Reply with a greeting that displays the user's name, like "Thanks for calling RobuCast <user's name>!".
    2. Phone: find out the user's phone number (string). Reply with a statement like "Looking up phone number <phone number>...".
    3. Plan: ask the user for their plan type entered as a single character of either 'b', 'g', or 'u' (char). Reply by spelling out the full plan name, like "Ah, the Basic package.
    4. Data: request user's data usage in Gigabytes (double). Reply with a comment that restates the amount of data, like "Wow, <amount> is a lot of data! You should upgrade."
    5. Total: display the total bill and say goodbye to <user's name>.

    The parenthesis show the required data types for the input. Make sure to restate the input where indicated by the word "reply" or angle brackets.

  4. Assume the user enters only valid data.
  5. The phone bill is based on the phone plan and the number of Gigabytes (GB) of data used per month. Here are the different plans:
    1. Basic plan: the $24.95 per month plan provides 2 GB of data. Additional data are $7.00 per Gigabyte.
    2. Gold plan: the $39.95 per month plan provides 5 GB of data. Additional data are $5.00 per Gigabyte.
    3. Unlimited plan: the $59.95 per month plan provides unlimited data.
  6. Example Runs: The following shows example runs. Your program prompts and output does not have to exactly match mine. Your program does need to reply to all input as stated in Interactions above, but you are free to give your chatbot a personality. Make sure the inputs are in the correct order and that you restate the data entered by the user. Otherwise, have fun with it!
    Welcome to RobuCast.
    What is your name? Ed
    Thanks for calling RobuCast Ed.
    What is your phone number? 555-2368
    Looking up phone number 555-2368...
    What is your phone plan? (b/g/u) b
    Ah, the Basic plan.
    How many GB of data this month? 5
    Wow, 5 GB is a lot of data! Maybe you should upgrade.
    Your total bill is: $45.95.
    Thanks for calling RobuCast Ed!
    
    Welcome to RobuCast.
    What is your name? Polly
    Thanks for calling RobuCast Polly.
    What is your phone number? 669-221-6251
    Looking up phone number 669-221-6251...
    What is your phone plan? (b/g/u) g
    Ah, the Gold plan. How many GB of data this month? 7
    Wow, 7 GB is a lot of data! You should upgrade.
    Your total bill is: $49.95.
    Thanks for calling RobuCast Polly!
    
    Welcome to RobuCast.
    What is your name? Richie$Rich
    Thanks for calling RobuCast Richie$Rich.
    What is your phone number? 555-0144
    Looking up phone number 202-555-0144...
    What is your phone plan? (b/g/u) u
    Ah, the Unlimited plan. How many GB of data this month? 10
    Wow, 10 GB is a lot of data!
    Good thing you have the unlimited plan.
    Your total bill is: $59.95.
    Thanks for calling RobuCast Richie$Rich!
    

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

  7. After displaying the output, exit the program.
  8. Submit the source code file phonebot.cpp with the rest of the assignment as described in Deliverables.
References and More Information
  1. PYMNTS.com
  2. Chatbots Life

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 longword.cpp program and list seven (7) or more valid words contained within floccinaucinihilipilification. (1 point)
  3. Complete the pirate.cpp program with no if statements or test conditions and without using techniques we have not covered. (2 points)

    Hint: make two very long strings containing the titles and new last names, like "Black CrimsonGold ...", in which you add spaces as needed such that each title or last name has the same length with the spaces added. Then use the substr() function to extract the needed title of name from the respective strings.

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

Projects (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

Project's 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 including:
    • nameapp.cpp
    • selection.cpp
    • students.txt
  3. longword.cpp
  4. pirate.cpp
  5. phonebot.cpp

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: September 17 2018 @15:50:15