DOC PREVIEW
Yale CPSC 427 - Problem Set 3
School name Yale University
Pages 3

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Assignment GoalsProblemDerived classesCoding styleTestingDeliverablesYALE UNIVERSITYDEPARTMENT OF COMPUTER SCIENCECPSC 427a: Object-Oriented Programming Handout #6 (rev. 1)Professor M. J. Fischer September 30, 2011Problem Set 3Due before midnight on Friday, October 7, 2011.1 Assignment Goals1. To learn how to create a derived class.2. To learn how to use ctors.3. To learn how to use polymorphic pointers.4. To apply rules for good coding style.2 ProblemThis problem set builds on Problem Set 2. In that problem set, you are asked to define aclass RandBit with member function next() that will return the next bit in a bit sequence.RandBit is supposed to have two modes of operation: normalMode and testMode. InnormalMode, the output is a biased random bit generated using a pseudorandom numberwith initial seed s, where the probability of 0 is p. Here, p and s are parameters that arespecified when RandBit is instantiated. In testMode, the bits are fake random bits, readfrom a file rather than being generated by any kind of a random or pseudorandom process.Somehow, the function RandBit::next() has to test the mode in order to do the rightthing.2.1 Derived classesFor this problem set, you are to rewrite the code for RandBit to use derived classes andpolymorphism to accomplish the same end. When you are done, there should be a cleanseparation between RandBit and its client(s). In particular, no explicit tests for the modeof operation should be made anywhere in your code, except for the code to create theappropriate class instance in the first place.In greater detail, your new program should have three classes: a base class RandBit andtwo derived classes, RandBitNormal and RandBitTest. The function RandBit::next()should be declared to be a pure virtual function.1A pure virtual function is declared likea virtual function but with “=0” in place of the definition. Be sure to also declare a virtualdestructor for the class.The two derived classes should each define next() in ways that are appropriate for themode of operation that each supports.• RandBitNormal performs pseudorandom bit generation.• RandBitTest returns bits read from a file.1This causes RandBit to b ecome an abstract base class.2 Problem Set 32.2 Coding styleOne purpose of this assignment is to improve your coding style. In particular, I am lookingfor clean code that makes use of polymorphic pointers and polymorphic derivation. Inaddition, you should rewrite/restructure your code from PS2 as necessary to follow goodstyle guidelines.1. As usual, your code should be well documented.2. The isolation between modules should be made as strong as possible through appro-priate use of const and the visibility keywords public, protected, and private. Ingeneral, every data member should be private or protected, and every explicit orimplicit parameter to a function that in fact is not modified by the function shouldbe labeled const.3. Your program should be divided into several files to reflect the modular structureof your code. One file, main.cpp should contain the main program. Each classdefinition should be placed in a file name.hpp file, and the implementation of thatclass should be in a corresponding name.cpp file, where name is the class name ora shortened form that is suggestive of the class name. Two or more classes may becombined in the same .hpp and .cpp files if they are closely coupled and do notmake sense in isolation. For example, it is okay to put the RandBit, RandBitNormal,and RandBitTest class definitions together in the same file randbit.hpp, and thecorresponding implementations in the file randbit.cpp.4. Unnecessary redundancy should be avoided, unless its use helps clarity. For example,do not write this->x when x would have the same meaning.5. Avoid overly long function definitions. If a function is more than 10 or 20 lines long,it is probably too long and should be split into smaller parts. This is not an absoluterule but a good guideline for clean code.6. Chapter 1 of the textbook gives other style guidelines. Follow them! If you think youneed to violate these rules, check with me first.7. Make sure your storage management is clean. Run valgrind to make sure that thereare no memory errors and that all memory is freed on normal program exit.3 TestingYour new program should be functionally identical to the requirements for your old PS2solution, so you should run it through the same tests and make sure that it is still workingcorrectly.4 DeliverablesYou should submit this assignment using the submit script that you will find in/c/cs427/bin/ on the Zoo. Remember to submit the following items:Handout #6 (rev. 1)—September 30, 2011 31. All source code and header files. Even if a PS2 file has not changed, submit itagain. Your PS3 submission should be self-contained without reference to previousassignments.2. A makefile and any other files necessary to build your project. (If you’re usingEclipse with the default settings, the makefiles will be found in the directory Debug.)3. The output of several runs of your program using different seeds and different numbersof experiments.4. Unit test programs along with test input and output that you used to verify that yourprogram was operating correctly.5. A brief report named report.txt (or any other common format such as .pdf) de-scribing the design choices you made in implementing the required code extensions.You can also put any other information here that the TA should know about


View Full Document

Yale CPSC 427 - Problem Set 3

Download Problem Set 3
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Problem Set 3 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Problem Set 3 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?