Activities and Exercises

Lesson 3 Comparisons

To avoid issues arising with special characters or incorrect real numbers stored in a computer equivalent to the character, skilled promrammers often pair an equal sign with one of the two boolean operators — greater than or less than. Describe two situations where you would use one over the other.

Fill in the correct boolean operator:

Lesson 4 Comparing Strings:

What is the exact output of the following program fragment?

if "apple" > "apple " then 
	put "I am right!"
	else
	put "I am left!"
end if
			

Which is the exact output of the following program fragment?

if "touringtouring" =< "touringTuring" then 
	put "The latter is greater."
	else
	put "The former is greater."
end if
			

Lesson 5 Sentinel Values:

Create a program which gathers user-supplied words. Provide the sum of all the ASCII codes of the characters processed.

Create a program which displays the absolute value of user-supplied non-zero integers.

Create a program which outputs the average of user-supplied ages for an arbitrary number of times.

What are suitable sentinel values for the following programs:

  1. The class average for a geography quiz
  2. The average payroll for the Toronto Four Seasons Hotel staff
  3. Random die rolls

Lesson 6 Counters & Accumulators

Code a program which gathers strings of characters from the user. After the user is finished inputting the data, he or she should be provided with the count of the strings inputted as well as the number of characters provided.

Project Two

Your task is to create a program that gathers marks from a teacher. After each mark, you must display the average of all the marks and the number of marks inputted. The program must include a loop statement, within which you must exit when the user has inputted either 30 numbers, or typed in 1000. Clearly indicate the sentinal values at the beginning of the program so that the user is informed. Hint: 1000 is the sentinel value.

Valid XHTML 1.0 Strict Valid CSS! Valid CSS!