Exercise 1

Get two integers from the user and multiply them without using the * operator.

Example:

Enter two numbers: 5 6
5 * 6 = 30

Bonus:

Consider the input cases 10000 2 and 2 10000. Modify your code so you loop as few times as possible in both cases.

Exercise 2

Write a program that prints a collatz conjecture sequence. The collatz conjecture is defined as follows:

Take any positive integer n
If n is even, divide it by two.
If n is odd, multiply it by 3 and add 1
Repeat this until n == 1

The collatz conjecture states that no matter what n you choose, you will always end up at 1. No one has found a number that does not satisfy this conjecture. No one has proven that all numbers eventually lead to 1.

Example:

Enter an integer: 3
10
5
16
8
4
2
1

Take a look at the collatz conjecture on wikipedia if you would like to read more about it.

Exercise 3

Get a word from the user. Repeat the word, removing one letter at a time (see example below). Stop printing when there are no more characters.

Bonus 1:

Get an entire line of text from the user.

Bonus 2:

Always reduce the printed word by one visible character (spaces are not visible). There is a function in the cctype library that you may use to determine if a character is a space or not.

Example:

Enter a word: Test
Test
Tes
Te
T

Bonus 2 example:

Enter a phrase: Hey there!
Hey there
Hey ther
Hey the
Hey th
Hey t
Hey
He
H

An incorrect version of bonus 2:

Enter a phrase: Hey there!
Hey there
Hey ther
Hey the
Hey th
Hey t
Hey
Hey
He
H

(notice the repetition)

Exercise 4

Write a program that takes a phrase and prints it reversed. Note: you do not need to reverse the string, just print it reversed.

Bonus:

If it is a palindrome, output a sentnce saying so.

Example 1:

Enter a phrase: Andre Castro
ortsaC erdnA

Bonus Example:

Enter a phrase: lionoil
lionoil
lionoil is a palindrome!

Exercise 5

Password-protect one of the previous exercises from this lab. The user gets at least 5 attempts to guess the password before the program quits with a failure message. The maximum number of tries is up to you. Read a single word as the password. Output a hint if the user gets it wrong.

[Bonus]: treat words with lowercase and uppercase letters the same. For instance, WorD and woRd should both be considered correct.

Example 1:

Enter a word: Test
The word "Test" is incorrect. Hint: it is green.
Enter another word: Grass
The word "Grass" is correct!

Exmaple 2:

Enter a word: Temporary
The word is incorrect. Hint: it starts with s
Enter another word: Sentence
The word is incorrect. Hint: it starts with s
Enter another word: Stilts
The word is incorrect. Hint: it starts with s
Enter another word: Sit
The word is incorrect. Hint: it starts with s
Enter another word: Stow
Im sorry. You failed to guesss the word. Goodbye.

Quiz!

quiz04