CSCI 1301 – Lab 19

Clément Aubert

October 22, 2018

Checkpoint

The code we just studied in class, slightly expanded and with an application program, is available to download.

Practicing if and switch

Initialize a day string variable, a myVar int variable and a initial char variable. During this part, change and display on the screen the values of those variables to test that your statements behave as they are supposed to.

From switch to if-else

  1. Write a switch statement that sets a flag to true if the value of day if "Mon.", "Tue.", "Wed.", "Thu." or "Fri.", and to false otherwise.
  2. Rewrite the previous statement as an if-else statement.

From if-else to switch

  1. Write a if-else statement that doubles the value of myVar if myVar is 3, 5 or 7.
  2. Can you rewrite the previous statement as a switch statement?

Deciding

  1. Write a statement that doubles the value of myVar and sets initial to ‘M’ if day is equal to "Sat". What is the appropriate kind of statement to do this?
  2. Write a statement that displays “Hello” on the screen if the value of initial is 'E' or 'e', “Bonjour” if the value of initial is 'F' or 'f', “Guten Tag” if the value of inital is 'D' or 'd'. What is the appropriate kind of statement to do this?

Complex Conditions

  1. Write a statement that doubles the value of myVar if day is "Sun.", triples the value of myVar if day is not "Sun." and initial is 'a', and sets myVar to 0 otherwise.
  2. Write a statement that sets myVar to 0 if initial is an upper-case letter, and to 1 otherwise. You can either use the IsUpper method (https://msdn.microsoft.com/en-us/library/9s91f3by(v=vs.110).aspx), or look at the “pushing further” part of the previous lab to understand how to test if a character is an upper-case letter.