Anda di halaman 1dari 3

COSC 1437 (DL) Spring 2017

Make Up Set
Total Points: 30

Choose 3 of the 6 problems below for full credit. See 1437 Grading Program Sheet for
grading/submission information. Partial credit will be given. (10 points each)

1. Rewrite Program 8.1 pp. 458-459 using a templated function. Implement the searchList function as
a generic function. Test the function with int, double, and C++ string values. The function must use
templates for full credit.

Name the program: TemplatedSearchListXX.cpp, where XX are your initials.

2. The number 138 is called well-ordered because the digits in the number (1, 3, 8) increase from left
to right (1 < 3 < 8). The number 365 is not well-ordered because 6 is larger than 5. Write a C++
program that will find and display all possible three and four digit well-ordered numbers. Output ten
values per line with 5 spaces in between. Finally, report the total number of three and four digit well-
ordered numbers. Values must be algorithmically calculated. Output should be user friendly.

Name the program: WellOrderedNosXX.cpp, where XX are your initials.

3. One job of an assistant girls basketball coach is to keep track of the number of minutes that each girl
on the team plays. There are four quarters in a game and the time clock starts at 12:00 (12 minutes, 0
seconds) at the beginning of each quarter and counts down to 0:00 (0 minutes, 0 seconds). The assistant
records the minutes and seconds left in the quarter each time a player enters or leaves the game. Write a
C++ program that calculates the total playing time of each player.
Input will be from a text file where the first line will contain a single integer n that indicates the
number of lines to follow. Each of the next n lines will contain the first name of a player followed by one
of more data sets in the form Qx mm:ss Qy mm:ss. The quarter that the player entered the game is
denoted by x and is followed by the number of minutes and seconds left in that quarter when she
entered the game. The quarter the player exited the game is denoted by y and is followed by the number
of minutes and seconds left in that quarter when she exited the game. For each player, print the player's
name followed by the number of minutes and seconds that the player played during the game following
sample output. Assume the number of minutes will be in the range [0,12] and have no leading zeroes.
The number of seconds will always be a two-digit integer in the range [00,59]. Let the user input the file
name from the keyboard. Output should look similar to below.

1
Sample File
4
Mary Q1 12:00 Q1 2:13 Q2 10:45 Q2 7:33 Q2 4:12 Q3 4:33 Q4 9:27 Q4 0:00
Anne Q1 5:55 Q2 7:34 Q3 5:58 Q4 7:55
Suan Q1 9:21 Q2 10:12 Q2 2:21 Q2 1:08 Q3 12:00 Q3 4:03 Q4 3:13 Q4 0:00
Evie Q2 1:10 Q3 9:21

Sample Run:

Enter the file name: game.txt

Mary 34:05
Anne 20:24
Suan 23:32
Evie 3:49

Name the program: PlayingTimeXX.cpp, where XX are your initials.

4. Write the definition of a class SwimmingPool, to implement the properties of a swimming pool. The
class should have the instance variables to store the length (in feet), width (in feet), depth (in feet), the
rate (in gallons per minute) at which the water is filling the pool, and the rate (in gallons per minute) at
which the water is draining from the pool. Add appropriate constructors to initialize the instance
variables. Also, add member functions to do the following:
Determine the amount of water to fill an empty or partially filled pool
Determine the time needed to complete or partially fill or empty the pool
Add or drain water for a specific amount of time.

Write a C++ program to test the above class. Place all code into one file. Output should be user friendly.

Name the program: TestSwimmingPoolXX.cpp, where XX are your initials.

5. The Library of Congress Number (LCN) system for are used by libraries to place books on shelves.
Every book has a unique LCN. Each LCN has three parts: call letters, a call number, and cutters. The call
letters are two uppercase letters. The call number is a number between 1and 10,000, inclusive, possibly
including a decimal part with at most 3 digits. The cutters are a letter followed by 0 to 9 digits. Books
are placed in order of their call letters (AA precedes AB, etc.); books with the same call letters appear in
increasing value of their call numbers; books with the same call letters and call number are sorted by the
letter of their cutters followed by the value of the number that follows the letter. For example,
DE23.12X73 appears before DE23.12X123 because 73 is numerically less than 123. Write a C++ that
given a set of LCN place them in the correct sequence. Input from a data file will be four sets of three
LCNs. Read each LCN as a single string. Print each set of three LCNs in the correct sequence. On the final
line, print the correct sequence for all 12 LCNs. Let the user input the file name from the keyboard.
Output should look similar to below.

2
Sample File
AB3D4 ZZ52A3.95 EF9.12X
DD555A123 BB9A3 XX123H
BB515A5 BB9A21 BB9A123
BB9.12X3 BB9.12A543 BB9.12A98

Sample Run:

Enter the file name: books.txt

Set 1: AB3D4 EF9.12X ZZ52A3.95


Set 2: BB9A3 DD555A123 XX123H
Set 3: BB9A21 BB9A123 BB515A5
Set 4: BB9.12A98 BB9.12A543 BB9.12X3

All 12 LCNs in order:

AB3D4 BB9A3 BB9A21 BB9A123 BB9.12A98 BB9.12A543 BB9.12X3 BB515A5 DD555A123 EF9.12X XX123H
ZZ52A3.95

Name the program: LCNSortingXX.cpp, where XX are your initials.

6. Catalan numbers are a sequence of natural numbers that occur in many problems in mathematics.
The nth Catalan number is given directly in terms of binomial coefficients by

Write a non-recursive C++ program that asks the user for a number n (n 18) and calculates the nth
Catalan number. Use the following function header in your code:

long cat(int n)

Check for negative values. The function must be non-recursive for full credit. Output should look similar
to below.

Sample Runs (2):

Enter a number: 15

The Catalan number is: 9694845

Enter a number: -1
Enter a number: 0

The Catalan number is: 1

Name the program: IterativeCatalanXX.cpp, where XX are your initials.

Anda mungkin juga menyukai