Programming Assignment: P4 (Conditional Statements)

1. Read the following sample program to find out the output with the following input values, and then run the program on computer and compare the output you found manually with the output from computer.
Exercise #1: If the letter C and the value 100 are input, what is the output?
Exercise #2: If the letter F and the value 32 are input, what is the output?
Exercise #3: If the letter c and the value 0 are input, what is the output?

```// Program Convert converts a temperature from Fahrenheit to
// Celsius or a temperature from Celsius to Fahrenheit,
// depending on whether the user enters an F or a C.

#include <iostream>
using namespace std;

int main ()
{
char letter;          // Place to store input letter
double tempIn;        // Temperature to be converted
double tempOut;       // Converted temperature

cout << "Input Menu" << endl << endl;
cout << "F or f:  Convert from Fahrenheit to Celsius" << endl;
cout << "C or c:  Convert from Celsius to Fahrenheit" << endl;
cout << "Type a C (or c) or an F (or f), then press return." << endl;
cin  >> letter;

cout << "Type a temperature value, then press return." << endl;
cin  >> tempIn;

if (letter == 'C' || letter == 'c')
tempOut = (9.0 * tempIn / 5.0) + 32.0;
else if (letter == 'F' || letter == 'f')
tempOut = 5.0 * (tempIn - 32.0) / 9.0;
else
{
cout << "Invalid input letter!" << endl;
return 0;
}

cout << "Temperature to convert: " << tempIn << endl;
cout << "Converted temperature:  " << tempOut << endl;
return 0;
}
```
2. Examine the following pairs of expressions and determine if they are equivalent (≡). Just say Yes or No. Hint: Use DeMorgan's Law.
```
Assume that variables x, y and z are of type int.

Case#: Expression 1               ≡       Expression 2
#1: !(x == y)                     ≡       x != y
#2: !((x == y) || (x == z))       ≡      (x != y) && (x != z)
#3: !((x >=0) && (x <=100))       ≡      (x < 0) || (x > 100)
#4: !(x != 10)                    ≡      x == 10
#5  !(x = 10)                     ≡      false
```
3. Examine the following pairs of expressions and determine if they are equivalent. Just say Yes or No.
```Assume that variables A, B, and C are of type bool.

Case#: Expression 1    ≡      Expression 2
#1: !A && B            ≡      B && !A
#2: !A || B            ≡      B || !A
#3: !A                 ≡      A == false
#4: A && B || C        ≡      A && (B || C)
#5: (A && B || C)      ≡      !(A || B && C)
```
4. Write a program that prints the corresponding letter grade (A, B, C, D, or F) for a numeric grade (between 0 and 100) entered by the user using the grading policy: 90 or above: A; 80-89: B; 70-79: C; 60-69: D; below 60: F. Your program should have a prompt that reminds the user of entering a numeric grade (0..100) and then prints out the corresponding letter grade with appropriate message. For example:
```Enter a numeric grade:
87
Good job!

//If you run your program again
56
Need to work harder and repeat the class next semester!
```
5. Find Highest Score: Complete the program below so that it reads and prints three test scores, then prints the largest of the three. Run your program three times using the three sets of input values listed below:
```Three sets of input values you will use to test your program are:
#1: 100 80 70
#2: 70 80 100
#3: 80 100 60

The sample output from your program:

Enter three different scores:
80 100 60
The highest score is 100
```
```// The program reads and prints three test scores.
// The largest value of the three is printed with an
// appropriate message.
// Assumption:  The scores are unique.

#include <iostream>
using namespace std;

int main ()
{
int  test1Score;
int  test2Score;
int  test3Score;

cout << "Enter score for test 1; press return." << endl;
cin >> test1Score;
cout << "Enter score for test 2; press return." << endl;
cin >> test2Score;
cout << "Enter score for test 3; press return."  < endl;
cin >> test3Score;

cout << "The three test scores are: " << endl;
cout << test1Score << endl;
cout << test2Score << endl;
cout << test3Score << endl;

//Find out the highest score and print it out.
//More ...

return 0;
}
```
6. At the top section of your program you need to use C++ comments to include your name, class name, programming assignment name, and date the program was written.
7. Your programs should be properly formatted using indentation and empty lines (spaces). Use "camel" notation for variable naming.
8. Upon completion, save all programs and the required output into a single text file using notepad (or notepad++). The file should be named in this format: P4_YourName.txt, for example, P4_JohnDoe.txt. Then submit to the Blackboard (Bb) as attachment by the deadline. The submission link on the Bb will be closed automatically after the deadline. Assignments that fail to follow the instructions will NOT be graded.