Homework #3


Copy the table into a Word document and fill in the answers.  For the program in question 18, include the source code & output.
Submit the .docx file on eCampus.


What do the following conditions evaluate to? (true or false)

short int A = 5, B = -8, C = 18, D = 0;

1. ________  (A > B) 7. ________  (D >= C || A == B)
2. ________  (B <= 0) 8. ________  ((C + 1) == (D + 19))
3. ________  (D != 0) 9. ________  (B == 0 || C == 0 || D == 0)
4. ________  (C = 17) 10. ________  (A == 0 && (B > 1 || C > 1))
5. ________  (A > B && C > D) 11. ________  (!(A == 5) || !(C = 0))
6. ________  (C != (B + 28)) 12. ________  (A > (B + C) && A < (D + B))

What will the following code output?

Num Code Output
13. float A = 20.5, B = -20.4;
if (A > (B + 40))
  cout << "Yes";
else
  cout << "No";
 
14. float Yoga = 2.5;
Yoga++; Yoga++;
if (!(Yoga < 5))
  Yoga--;
else
  Yoga++;
cout << Yoga;
 
15. bool Hungry = true;
bool Thirsty = false;
if (Hungry || Thirsty)
{
  cout << "I'm not happy";
}
else
{
  cout << "I'm very happy";
}
 
16. cout << "1";
int H = -50;
if (H < (H + 1))
  cout << "2";
else
  cout << "3";
 
17. short int X = 15, Y = 18;
if (X > 9 && Y < 18)
  cout << "passion";
else
  cout << "papaya";
 

18. Write a program (attach source code & output) that prompts the user to enter how many donuts they are going to eat.  The program should then output how many dozen and single donuts this is.  For example, if the user enters 29, the program will say, "This is 2 dozen plus 5 donuts."

Also, have the program output different comments (minimun 6) depending on how many donuts the user enters.  The ranges for the comments should be contiguous.  Look at the example below, but please use your own original comments.

If the user eats this many donuts The program will output this
0 "On a diet or something?"
1 - 2 "You don't seem very hungry today"
3 - 6 "Just an appetizer for you?"
7 - 9 "What's for dessert...cinnamon rolls?"
10 - 12 "You're a donut freak!"
> 12 "Mmmmmmm......donuts!"


 

Extra Credit
Write a program that prompts the user to enter a message (text string).  The program should then perfectly center the message on the screen (assume an 80-column width screen) and draw a box around the message.

---------------
| Hello World! |
---------------