Assignment 8
Due Monday, February 12 at 9:20am on Canvas

Complete the Midterm Review

Additionally, you will have one week to complete the below assignments. Note that assignment 8.4 cannot be completed until after you learn the material from Lesson 9 on Wednesday's class.

Assignment 8.1: Jokes (10 pts)
Image of Mae West
Write a program to ask a user whether (s)he wants to hear a bad joke.
If the user indicates no, the program should quote Mae West, a classic Hollywood actress, who was famous for her amusing one-liners.

“I never worry about diets. The only carrots that interest me are the number you get in a diamond.”

-Mae West

If the user indicates yes, the program should print out the computer joke:


"Q: Why did the computer get cold?
A: Because it forgot to close Windows."


Your program should work identically to the example output below.

Note that your output should display the "" around the jokes.

Note that you are required to use exactly one if statement and one else statement to receive full credit on this assignment. (No else if needed!)

Submit joke.cpp to Canvas when you are finished.

Example Output:


Want to hear a bad joke (yes/no)? no
Okay. I will tell you a good one:

“I never worry about diets. The only carrots that interest me are the number you get in a diamond.”
- Mae West

Alternately,

Want to hear a bad joke (yes/no)? yes

"Q: Why did the computer get cold?
A: Because it forgot to close Windows."


Assignment 8.2: Student ID Numbers (10 pts)

  • Write a program in a C++ file called studentID.cpp
  • Your program should prompt a user to enter a student ID number as a series of numbers.
  • However, your program should read the input as a string, not as an int.
  • Your program should check whether the user entered a valid 8-digit de Anza student ID number and report an error message if the ID number entered is too short or too long (no other error checking is required).
  • It will then display the ID number in the format XXX-XXX-XX
  • Your program should work identically to these examples (except user input will vary):

Please enter your 8 digit student ID number: 203456
Sorry! That ID is invalid.
Please run the program again.
  • Alternately:

Please enter your 8 digit student ID number: 1034566330
Sorry! That ID is invalid.
Please run the program again.

  • Alternately,
Please enter your 8 digit student ID number: 20456855
You entered: 204-568-55
  • Important: Again, use a string, not an int to store the user input.
  • Also, make use of the string functions we discussed in class under Lesson 7.
  • Finally, you are required to write this program with exactly one if statement and one else statement for full credit (no else if needed!).
  • Submit studentID.cpp to Canvas when you are finished.


Assignment 8.3 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, else if and else 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.

  • Submit your program to Canvas when you are finished.



Assignment 8.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".
  • Note that you should make use of logical operators (will you need to use && or ||?).
  • The name of the source code file for this program must be monthdays.cpp and all your code must be in this file.
  • Submit your program to Canvas 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

Alternately:

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


Alternately:

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

Hint: Thirty days hath September