The following programs will be tested with redirection, as in q1.exe < testFile1.txt.
Question 1. Read in two whole numbers and two floating
point numbers (the latter are guaranteed to not be integers),
though not necessarily in that order. Print out the
sum of the two whole numbers, a space, and the sum of the two floating
point numbers.
Sample input: 2 4.2 3.7 6
Sample output: 8 7.9
Question 2. A perfect number is a positive integer
which is the sum of its proper divisors. So, for example, the first
three perfect numbers are:
6 = 1 + 2 + 3,
28 = 1 + 2 + 4 + 7 + 14, and
496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248.
Read in two whole numbers, n1 and n2, and output all the perfect numbers
which are between n1 and n2 inclusively.
Question 3. Here we invent the term triangular prime. This is a prime number with 3 digits where the 3 digits themselves could be the sides of a triangle. Read in two whole numbers: n1 and n2. Print out the sum of the areas of all the triangular primes which are between n1 and n2 inclusively.
Question 4. Here we play a simple game of Animals.
Your program builds a set of rules to guess an animal that the user is
thinking of. It starts with the default guess -- a panther.
If it ever guesses right, it reports how many guesses it took and starts
over (quitting when the user hits 'n' to quit). If it guesses wrong
and it is at a leaf, it asks for a new YES/NO question to discern the current
animal from the leaf, then places the new question at the leaf and adds two
new leaves, one for each possible answer.
If it guesses wrong at an interior node, however,
it just asks the YES/NO question at that node, and proceeds to the question
at the child corresponding to the user's reply. Here is
the I/O spec for this problem:
Sample I/O (user input is underlined):
Think of an animal....
Is it a panther? no
Darn. Then what is it: dog
List a yes/no question which discerns a panther
from a dog: Does it bark?
What is the correct answer for a dog? yes
Play again? [y]es or [n]o y
Think of an animal....
Does it bark? yes
Is it a dog? yes
Yippee!!! I got it in 2 questions!!!
Play again? [y]es or [n]o y
Think of an animal....
Does it bark? yes
Is it a dog? no
Darn. Then what is it: hyena
List a yes/no question which discerns a dog from
a hyena: Does it laugh?
What is the correct answer for a hyena? yes
Play again? [y]es or [n]o y
Think of an animal....
Does it bark? yes
Does it laugh? no
Is it a dog? no
Darn. Then what is it: wolf
List a yes/no question which discerns a dog from
a wolf: Is it big and bad?
What is the correct answer for a wolf? yes
Play again? [y]es or [n]o y
Think of an animal....
Does it bark? no
Is it a panther? no
[...]
Question 5. Here you create a substitution cypher. Your input will be a single line of up to 10,000 UPPERCASE letters (all between A and Z inclusive) without spaces. Your goal is to find a substitution cypher, which you will output as a sequence of 26 letters, those being the substitutions in order from A to Z. Which cypher? Find the cypher in which the representation of the input string contains the fewest possible 1's in its binary ASCII representation. If more than one such cypher exists, print out the one that is alphabetically first when the 26 letter output is viewed as a single word.
Question 6. Read in a single whole number M. Print out the number of people who must be in a room such that it is more likely than not that at least M of them share the same birthday. You may assume there are no leap years.