CSC 533: Organization of Programming Languages
Fall 2000

HW3: C++ Programs

For this assignment, you are to write solutions to the following problems in C++. These problems are presented in the style of programming contests, where the input and output formats are very strict. In a contest setting, the elegance of the program is not considered, only its behavior. This is not the case for this assignment, however! You should strive to make your code as efficient and elegant as possible.


A Perfect World

A perfect number is a positive integer that is equal to the sum of all its positive, proper divisors. For example, 6 is a perfect number since 6 = 1 + 2 + 3. Likewise, 28 is a perfect number since 28 = 1 + 2 + 4 + 7 + 14. A positive integer that is not perfect is either deficient or abundant depending on whether the sum of its positive, proper divisors is smaller or larger than the number itself. For example, 9 is deficient since 9 > 1 + 3, while 12 is abundant since 12 < 1 + 2 + 3 + 4 + 6.

Problem Statement:   Given a number, determine if it is perfect, deficient, or abundant.

Input:   A list of N positive integers (none greater than 30,000), with 1 < N < 100. A 0 will mark the end of the list.

Output:   The first line of output should read PERFECTION OUTPUT. The next N lines of output should list for each input integer whether it is perfect, deficient, or abundant, as shown in the example below. Format counts: each integer should be displayed, followed by two spaces, followed by the description of the integer in capital letters. The final line of output should read END OF OUTPUT.

Sample Input:

15 28 6 56 22 0

Sample Output:

PERFECTION OUTPUT 15 DEFICIENT 28 PERFECT 6 PERFECT 56 ABUNDANT 22 DEFICIENT END OF OUTPUT


I Did It All for the Bookie

You have been hired by Rainbow Bennie the bookie to automate his gambling accounts. Each week, Rainbow Bennie accepts bets from his clients on football games. In particular, he only accepts OVER-UNDER bets, where he predicts the total number of points that will be scored in a game and gamblers then bet as to whether the teams will score OVER or UNDER that number. For example, Rainbow Bennie might predict that the Bears and Lions will score a combined 28 points in their game. If they actually score 29 or more points, then a bet of OVER would win; if they score 27 or fewer points, then a bet of UNDER would win; if they score exactly 28 points, then neither OVER nor UNDER wins (Rainbow Bennie takes the money).

Problem Statement:   Read in the numbers for a series of games, including team names, the actual number of points scored by each team, and the predicted number of points. Also, read in a series of bets, including a gambler's name, the amount of the bet, a team name, and whether the bet is OVER or UNDER. Then, display the total amounts won or lost by each of the gamblers.

Input:   The first line of input will contain a positive integer, G, specifying the number of games that can be bet on (1 <= G <= 15). The next G lines will contain the name of the visiting team, the number of points that team scored in the game, the name of the home team, the number of points scored by the home team, and the predicted number of points for the game. The next line of input will contain a positive integer, B, specifying the number of bets to be processed (1 <= B <= 30). The next B lines will contain the name of a gambler, the amount bet (a positive integer), the name of a team involved in a game, and the type of bet for that game (either "OVER" or "UNDER"). You may assume that team and gambler names consist of no more than 10 letters, and that all input values are separated by a single space.

Output:   For each gambler listed, the total amount won or lost should be displayed on a line, listing that gambler's name, a single space, either the word "WON" or "LOST" (as appropriate), another space, and the total amount they won or lost. If the gambler broke even, the phrase "BROKE EVEN" should appear after their name. Gamblers should be listed in the order in which they first appeared in the input.

Sample Input:

4 BEARS 17 LIONS 14 28 RAMS 20 49ERS 14 33.5 CHARGERS 3 VIKINGS 30 35.5 EAGLES 8 RAVENS 10 18 6 JOE 200 BEARS OVER ALEX 50 49ERS UNDER DAN 20 RAMS OVER JOE 100 RAVENS OVER JOE 25 VIKINGS UNDER DAN 20 LIONS UNDER

Sample Output:

JOE WON 125 ALEX LOST 50 DAN BROKE EVEN