Last Updated:
June 25, 1998 Home Chat Room C++ Tutorials and Resources C++ Exercises Programming Helpers Links |
C++ Exercises and Problems
Instructions On Submitting Your Exercise Problems Instructions On Submitting Your Answers Senior Division, Contest #4 "Countdown" Problem: Given a date in the 1990's, report the number of days from that until January 1, 2000. For example, an input of November 20, 1999 would return a value of 41 bcause 10 days remain in November (21st, 22nd, ..., 30th) and 31 days remain in December. Input Format: Each date must be entered as a single string, exactly as shown below. There are three formats that you must be prepared to handle:
Sample Input:
The test data is not available until further notice. Sorry for the inconvenience.
April 22, 1998
Write a program that generates the times table from 1 to 10. The output should look similar to this:
1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 20 30 40 50 60 70 80 90 100
March 15, 1998
The number 6 is said to be a perfect number because it is equal to the sum of all its factors, excluding itself.
Write a program that finds and prints the five smallest perfect numbers.
March 15, 1998
Using FOR loops, print out all the even numbers from 1 to 20, then print out the odd numbers from 1 to 20. Output the numbers in two columns, one for even numbers, another for odd numbers.
Sample Output:
2 1 4 3 6 5 . . . . . . 20 19
March 14, 1998
Write a program that generates a random letter, case is not sensitive, so either upper or lower case will be fine. Ask the user to input a character, and output if the input is smaller, larger, or equal to the mystery letter. Remember to convert the input to the case you used. For example, if your random letter is a capital, then you will have to convert all your inputs to capitals. In addition, give a fixed number of chances for your user, and prompt your user how many guesses they have left.
March 14, 1998
Senior Division, Contest #3 "Pretty Poor Privacy" Problem: A hot topic these days is how to protect the privacy of information on computers. A simple way to protect the contents of a file is to encrypt its contents. For example, if you translated all A's to C's, B's to D's, ..., and Z's to B's, then the string PRIVACY would be encoded as RTKXCEA. This encoded string can be converted back to its original form (only by somebody who knew how the encryption was performed) by converting all C's to A's, and so on. However, in this problem, you don't need to do any decoding. To make this problem a bit more interesting, you'll be given a number N, between -100 and 100 inclusive, which will indicate how many characters to offset the translation of the first word. For example, N = 2 would convert A's to C's as described above; N = -3 and N = 75 would both convert A's to X's, B's to Y's and so on. For each subsequent word in the string, add to N the number of characters in the previous word. A word is a sequence of characters terminated by a space or the end of the string. We guarantee that there will never be multiple adjacent spaces. For example, if the string were "Now, I think, is the right time.", and N were 5, you'd use N = 9 for converting the second word, N = 10 for the third word, N = 16 for the fourth word, N = 18 for the fifth word, and so on. And finally, just to make this problem even more interesting, after you've converted the input line, go back and reverse the letters in each word. Don't change the positions of any of the non-letters in the word. Input: You'll be given 5 input lines, each consisting of a string and an integer N. Output: Print the encoded version of each string. Maintain the case sensitivity of the input, as shown in the sample below, and leave all non-letters exactly as they appear in the input.
Sample Input:
The test data is available below. This is all the information you will need to complete this program. Please don't email me with a bunch of questions, because this is a problem solving question, you should try to solve it yourself. Also, only look at the test data after you have completed your program, because it will ruin the purpose if you know the test data before you complete your program. Email me if you really need help, but try to do it yourself first. Good luck.
March 7, 1998
Test Data - "Pretty Poor Privacy" The test data is only executed once on your program for your score. If you can it wrong, you can fix your program and try again, but that will not be counted on your score.
Answers: |