Você está na página 1de 4

COSC 4331

02 K-Essien

Homework 4
Due Date: 7/31/11 11:59pm
Answers are accepted as reports written in Word or Text format.
Submission guidelines:
The assignment is due on midnight Aug 1. Assignments are turned in after due date will be docked 5% per day. You should submit your homework as an attachment file through Blackboard (or email me to zhuq@uhv.edu if Blackboard doesnt work and you need to catch up for the due date). For the written exercises (Part I) you are to turn in your answers in either Word or Text file with your name clearly written on the top of the document, along with the title "Assignment 4, Part I". For the programming exercise (Part II) you are to turn in:

a single file named assignment4.cpp (or assignment4.java) containing all your C+ + (or Java) source code a single text file named readme1.txt containing your name and any relevant information about your program (known bugs, compilation or operating anomalies, or instructions, etc). a single file containing the outputs of several test runs of the program demonstrating that the program works in all reasonable cases.

I will run your programs using Visual C++ or Java.

If your file is unreadable, or I cannot compile and execute your program, I will send you an email and you will have 24 hours to provide me with a working copy (normal late penalties apply).

Part I: written exercises. These are from the Problem sets from the text. 1. Text, pages 519 Problem set #2 (Version8 pages 505, #2) -2 points The statement is not true because the user is given access to the stack through the returned value of the "top" function. For example, if p is a pointer to objects of the type stored in the stack, we could have: p = top (stack1); *p = 42;

COSC 4331

02 K-Essien

These statements access the stack directly, which violates the principle of a data abstraction. 2. Text, page 520, Problem set #14 (Version8 page 506, Problem set #11) 2 points The three ways a C++ client program can reference a name from a namespace defined in a header file are ( assuming the namespace name isMyStack and the variable is namedtopPtr): a. MyStack::topPtr b. Including the statement: usingMyStack::topPtr; in the program. c. Including the statement: using namespace MyStack; in the program and referencingtopPtr by its name. 3. Text, pages 566, problem set #3 (Version8, pages 553, #1) 2 points In C++, a method can only be dynamically bound if all of its ancestors are marked virtual. Be default, all method binding is static. In Java, method binding is dynamic by default. Static binding only occurs if the method is marked final, which means it cannot be overriden. 4. Text, pages 566, problem set #6 (Version8, pages 553, #4) 1 points

5. Text, pages 166, problem set #6(a) only (Version 8, pages 163, #6(a) only) 3 points (only (a), no (b) and (c) ) <assign> =><id> = <expr> A = <expr> A = <id> * <expr> A = A * <expr> A = A * ( <expr>) A = A * (<id> + <expr>) A = A * ( B + <expr>) A = A * ( B + (<expr>) ) A = A * ( B + (<id> * <expr>) ) A = A * ( B + ( C * <expr>) ) A = A * ( B + ( C * <id>) ) A=A*(B+(C*A))

COSC 4331

02 K-Essien

6. Text, pages 167, problem set #12 (version 8, pages 164, #12) 3 points

Part II: programming exercise (Please start early, it takes a little bit long time) The goal of this exercise is to use some of the object oriented features of C++ or Java. The program is to simulate a tennis tournament, for our purposes, takes a field of 8 players and plays a series of three rounds, eliminating half the players with each round ending with a single (winning) player. Individual rounds operate as follows:

Randomly divide the remaining players into pairs. Simulate a single game between each pair, using the scoring rules specified in assignment 1. The winners advance to the next round, the losers are eliminated.

The user should enter the names of the 8 players, then the program should simulate each of the three rounds, printing the result of each game. At the end of the tournament the program should print the name of the winner and the name of the second place finisher. Your software must include appropriate classes of object for both a player and a tournament, but beyond that the design is at your discretion. In addition, the simulation between any two players is as follows:

The score will start at 0/0, and will continue until someone wins the game. It is assumed that either player one or player two will win a point on each play. A (pseudo) random number generator will be used to determine the results of each play, with each player equally likely to win any given point. After each play, the program should indicate which player won the point, the new score, and which player is serving next. The program should then pause until the user strikes a key to continue play.

The player who won the previous point serves for the next point (randomly determine the player to serve first in the game). The score is determined as follows (scores displayed as server/receiver). See http://tennis.about.com/cs/beginners/a/beginnerscore.htm

COSC 4331 Previous Score 0/0 0/15 0/30 0/40 15/0 15/15 15/30 15/40 30/0 30/15 30/30 30/40 40/0 40/15 40/30 deuce advantage Marking guidelines: Part I will be worth 12 marks. Server wins point 15/0 15/15 15/30 15/40 30/0 30/15 30/30 30/40 40/0 40/15 40/30 deuce game game game advantage game Receiver wins point 0/15 0/30 0/40 game 15/15 15/30 15/40 game 30/15 30/30 30/40 game 40/15 40/30 deuce advantage deuce

02 K-Essien

Part II will be worth 13 marks, with 7 marks allocated for code quality, and 6 marks allocated for code execution. The code quality marks will be determined from your submitted source listing, and will be based on code clarity, layout, commenting, efficiency, and correctness. The execution marks will be based on the output of compiling and executing your source code over several trial runs. If the source code submitted for execution does not match your submitted printout then you will receive 0 marks for execution.

Você também pode gostar