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.

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

Project 1: Suggesting Blog Titles

A blog is a website for commentary, discussion or information that is more or less regularly updated. To attract attention, blog entries often have sensational or provocative headlines. For this project, we will write a program to produce suggested blog titles on a topic selected by the user.

Project Specifications
  1. Write a program that produces the following five (5) blog titles based on user input of a topic and number:
    1. [number] Secrets That Experts Of [topic] Want You To Know!
    2. [number] Reasons [topic] Will Change The Way You Think About Everything!
    3. You Will Never Believe This Awesome Truth Behind [topic]
    4. Here's What No One Tells You About [topic]
    5. [number] Ways [topic] Can Help You Live To 100!
  2. The name of the source code file for this program must be blogtitles.cpp and all your code must be in this 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. Single word topic
    2. Integer number between 3 and 20

    Assume the user only enters correct data.

  4. The words [topic] and [number] (shown in square brackets above for emphasis) must be replaced by the user input.
  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 correctly if the inputs are different.
    Enter a single-word topic: C++
    Enter an integer number between 3 and 20: 10
    
    Suggested blog titles:
    10 Secrets That Experts Of C++ Want You To Know!
    10 Reasons C++ Will Change The Way You Think About Everything!
    You Will Never Believe This Awesome Truth Behind C++
    Here's What No One Tells You About C++
    10 Ways C++ Can Help You Live To 100!
    

    Correct spelling of titles is expected. 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. You may add additional blog title suggestions after the above 5, but must print the above 5 blog titles at a minimum.
  7. After printing the blog title suggestions, exit the program.
  8. Submit this project with the rest of the assignment as described in Deliverables.

Example Name Tag

Project 2: Coding Student Names

A personal name, or full name, refers to the set of names by which an individual is known and that can be recited as a word-group, with the understanding that, taken together, they all relate to that one individual [1].

For this project, you will generate and print your personal name derived from a starting alphabet string. You will need to use string functions to extract each character from the alphabet and arrange the characters in the correct order.

Project Specifications
  1. Write a program that prints your personal name by extracting characters from the alphabet string in the starter code: namemaker.cpp
  2. You must name the source code file namemaker.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. Do NOT ask the user for any input in this project.
  4. Do NOT directly print your name or any literal characters or strings; instead, use substr() to extract the characters needed from the ALPHABET string and then concatenate the characters together as described in lesson 3.2.5 and lesson 3.2.6.

    For example, to extract the letters "E" and "D" from alphabet, use code like the following:

    string name = alphabet.substr(4, 1);
    name = name + alphabet.substr(3, 1);
    
  5. Notice that the alphabet string includes a space character, a single quote and a dash. Use the substr() function to extract these character from the string as needed to provide spaces, apostrophes and dashes between parts of your name.
  6. Do NOT change the original ALPHABET string in any way. Your code must use the ALPHABET string and variable provided in the starter code.
  7. Example Run: The outputs of the program must look like the following for full credit. Your program must display the set of names by which you are known to the instructor (like in your README.txt) and include your first and last names at a minimum.
    ED PARRISH
    

    In the above example run, the programmer's name is Ed Parrish.

  8. After displaying the output, exit the program.
  9. Submit this project with the rest of the assignment as described in Deliverables.
References and More Information
  1. Personal name: Wikipedia

Image

Project 3: Calculating Grade Values

Academic grades in the US are traditionally given as letter grades: A, B, C, D, and F. In this project we translate letter grades into their numerical value like we would to calclulate a grade point average (GPA).

Project Specifications
  1. Write a program that converts a letter grade into it's numerical value using the following conversion table.
    Letter Grade GPA
    A 4.00
    A- 3.67
    B+ 3.33
    B 3.00
    B- 2.67
    C+ 2.33
    C 2.00
    C- 1.67
    D+ 1.33
    D 1.00
    D- 0.67
    F 0.00
  2. You must name the source code file gradevalue.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 a letter grade of A, B, C, D, or F, possibly followed by a + or -, and no other input as shown in the Example Run.

    Assume the user only enters correct data.

  4. Convert the letter grade into the numerical equivalent shown in the table in specification 1.

    Notice that the highest number in the table is 4.0 and that there are no F+ or F- grades. Make sure that the highest grade number is 4 and that F+, F and F- are assigned values of 0.

  5. Display the output using the default formatting and precision for the numbers -- do NOT add any numerical formatting statements to the code.
  6. Example Runs: 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.
    Enter a letter grade: B-
    The numeric value is 2.67
    
    Enter a letter grade: A+
    The numeric value is 4
    
    Enter a letter grade: F-
    The numeric value is 0
    

    In the above three example runs, the user entered "B-", "A+" and "F-" (without the quotes) as the letter grades to convert. The input values are 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.

  7. After displaying the output, exit the program.
  8. Submit this project with the rest of the assignment as described in Deliverables.

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)

    For the namemaker.cpp file, include first and last names for both students.

  2. Complete the gradevalue.cpp program with 8 or fewer relational expressions and without using techniques we have not covered. (2 points)

    The program must work correctly to get this extra credit.

  3. Complete the following extra credit project. (2 points)

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

Best price

Project 4: Price is Right

Floating point numbers are approximations of real numbers and are not always exact. When working with money, we sometimes want exact dollars and cents. One way to make dollars and cents exact is to convert a floating-point number to two integers, one integer for dollars and one for cents. In this project we will make sure we store an exact price.

Project Specifications
  1. Write a program that converts the dollars and cents of a price, given as a floating-point number, into two integer numbers.
  2. You must name the source code file price.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 a price as a floating-point number, and no other input, as shown in the Example Run.

    Assume the user only enters correct data.

  4. 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.
    Enter the price: 2.95
    2 dollars and 95 cents.
    
    Enter the price: 4.35
    4 dollars and 35 cents.
    

    In the above two example runs, the user entered "2.95" and "4.35" (without the quotes) as the floating-point numbers to convert.

  5. Convert the floating-point number to two integer numbers by following this algorithm exactly:
    1. Get price from the user and store in a floating-point variable.
    2. Assign price to an integer variable for dollars.
    3. Subtract price - dollars, multiply by 100 and then add 0.5.
    4. Assign the result of step c to an integer variable for cents.
    5. Print the dollars and cents values as shown below in Example Run
  6. Use the default formatting and precision for the output numbers -- do NOT add any numerical formatting statements to the code.
  7. After displaying the output, exit the program.
  8. Run your programs with and without adding 0.5 in step c of the algorithm while using these test values as input:
    1. 2.95
    2. 4.35
  9. Add a comment at the bottom of the price.cpp file stating what difference you saw with and without adding 0.5 and your explanation of why there was a difference. See textbook p.45-46 if not sure why.

    Make sure to turn in the correct code with the 0.5 added in step c of the algorithm.

  10. Submit this project with the rest of the assignment as described in Deliverables and list it in the Extra Credit section of the README.txt file.

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
  3. blogtitles.cpp
  4. namemaker.cpp
  5. gradevalue.cpp
  6. Optionally price.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 problems, 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, but must resubmit all your assignment files.

Last Updated: March 11 2017 @14:51:19