Assignment 9
Due Tuesday, October 31 at 3:20pm on Canvas

***Don't forget to complete Activity 9.2: Prices, as well!***

Assignment 9.1 Grade Values

  • Academic grades in the US are traditionally given as letter grades: A, B, C, D, and F. We need to translate these letter grades into number to calclulate a grade point average (GPA).
  • 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
  • In a file named letterGrade.cpp, prompt 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.
  • Convert the letter grade into the numerical equivalent shown above using a series of if statements.

    Notice that the highest number is 4.0 and that there are no F+ or F- grades. Make sure that the highest grade number is 4.0 and that F+, F and F- are assigned 0.0 values.

  • Display the output using the default formatting and precision for the numbers -- do NOT add any numerical formatting statements to the code.
  • Sample Output: 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.0
    Enter a letter grade: F-
    The numeric value is 0.0

    In the above three example runs, the user entered "B-", "A+" and "F-" (without the quotes) as the letter grades to convert.

  • After displaying the output, exit the program.
  • Submit your program to Canvas when you are finished.

Assignment 9.2: Making a Receipt (10 pts)
  • Let's write a program to create a receipt.
  • Open up your pastries.cpp from Assignment 5.
  • Your output should look identical the following (except the user input will vary).
  • Notice the blank lines. These are important, so don't forget to include them!
  • The program should follow the exact formatting shown below, including spacing and indentation.
    • Hint: Remember "\t"?
  • Note that you will need to print out exactly 2 decimal places for the dollar values.
  • When you are finished, submit your program.

    Welcome to C++ Pastries!
    Allow me to assist you with your order.

    Please enter the number of eclairs: 3
    Please enter the number of bear claws: 2
    Please enter the number of croissants: 5
    Please enter the number of cupcakes: 1

    You Ordered the Following:
    Eclairs: 3 @ $1.95 each...                  $5.85
    Bear Claws: 2 @ $2.15 each...               $4.30
    Croissants: 5 @ $2.05 each...               $10.25
    Cupcakes: 1 @ $1.85 each...                 $1.85

    Total:                                      $22.25

    Thank you for your order! Please come again!

Assignment 9.3: Playing Cards (10 pts)
  • This will be one of the most challenging assignments you will do in this class, so get started early!
  • Open up a new C++ file in CodeBlocks and name it cards.cpp.
  • Add the necessary structure to your C++ program (block comments, iostream library, standard namespace, and a main() function)
  • Make sure you have correct indentation.
  • The goal of this program is to take in user input describing a playing card in the following shorthand notation:
A                    Ace
2....10            Card Values
J                    Jack
Q                   Queen
K                    King
D                    Diamonds
H                    Hearts
S                    Spades
C                    Clubs
  • Your program will take in as user input a shorthand notation for a single card.
  • Your program will then output the full description for that card.
  • See the sample output below:
Enter the Card Notation: QS
You Entered: Queen of Spades
  • Here is another sample output:
Enter the Card Notation: 4H
You Entered: 4 of Hearts
  • To accomplish the goals of this program, you will need to use if statements, else if statements and an else clause.
  • There are two approaches to the program
    • Complete the program using 52 if statements (one for each of the possible value and suit combinations of the playing cards). For example, your 52 if statements will include the one below:
if (input == "QS") {
   cout << "You entered: Queen of Spades\n";
} else if (input == "QH")
    cout << "You entered: Queen of Hearts\n";
    • OR, Complete the program with fewer if statements, making use of the substr(i,n) and length() functions
  • Both approaches work, and you may choose whichever option makes better sense to you.
  • Important note: The tricky part will be to handle the 10 correctly.
  • When you are finished, upload your cards.cpp program to Canvas.

Example set of 52 playing cards; 13 of each suit clubs, diamonds, hearts, and spades

Ace 2 3 4 5 6 7 8 9 10 Jack Queen King
Clubs Ace of clubs 2 of clubs 3 of clubs 4 of clubs 5 of clubs 6 of clubs 7 of clubs 8 of clubs 9 of clubs 10 of clubs Jack of clubs Queen of clubs King of clubs
Diamonds Ace of diamonds 2 of diamonds 3 of diamonds 4 of diamonds 5 of diamonds 6 of diamonds 7 of diamonds 8 of diamonds 9 of diamonds 10 of diamonds Jack of diamonds Queen of diamonds King of diamonds
Hearts Ace of hearts 2 of hearts 3 of hearts 4 of hearts 5 of hearts 6 of hearts 7 of hearts 8 of hearts 9 of hearts 10 of hearts Jack of hearts Queen of hearts King of hearts
Spades Ace of spades 2 of spades 3 of spades 4 of spades 5 of spades 6 of spades 7 of spades 8 of spades 9 of spades 10 of spades Jack of spades Queen of spades King of spades

image source

Assignment 9.4: Days in a Month (10 pts)
  • Develop a program that first asks the user to enter a month (1 for January, 2 for February, and so on) and then prints the number of days in the month followed by the word "days". For February, print the phrase "28 or 29 days".
  • The name of the source code file for this program must be monthdays.cpp and all your code must be in this file.
  • Submit to Catalyst when finished.
  • Your program must operate like this, such that the same sequence of inputs produces the same output:

I will print the number of days in a month.
Enter the month (1-12): 9
30 days


I will print the number of days in a month.
Enter the month (1-12): 2
28 or 29 days


I will print the number of days in a month.
Enter the month: 1
31 days

Hint: Thirty days hath September