Subsections

Homework #14 (Due: Mon 02 Mar)

\begin{purpose}
The focus of this assignment is \lq\lq methods.'' You will create thr...
...ilar to writing an essay in that it
improves with each re-writing.
\end{purpose}

Problem Description

Modify the program you wrote for homework #10 so that it is designed in modular fashion using methods. In particular you will write three methods (in addition to main()) as explained below:
  1. Write a method that will have the user enter a guess in the range 1 to 100. The method should use a loop to validate the user input and should return the value they enter.
  2. Write a similar method that will have the user enter ``y'' or ``n''. The method should return the value they enter but should use a loop to require re-entry until one of those two values has been specified.
  3. Write a method that will actually play the game. This includes selecting the hidden number and a loop of user guesses.

When you have finished the program, main() should look something like this:

  do {
    call method to play the game
    ans= call method to see if they want to play again
  } while (ans is "y");

Important Information

If you are not sure where to get started then try following these steps. Do no proceed to the ``next'' step until you have finished the one before it. If you get stuck then get help ... but make sure that you are the problem-solver behind each statement!
  1. Create and test a method that has the user enter a guess in the range 1 to 100. The method should return the value entered by the user.
  2. Create and test a method that has the user enter a ``y'' or an ``n'' and validates the input. The method should return the value entered by the user.
  3. The program that houses these two programs can be temporarily ``set aside'' as you continue these steps.
  4. Make a copy of your most recent working guessing game program.
  5. Fix any indentation/documentation shortcomings in the program.
  6. Move the code that actually plays the game into a new method. Be sure to move necessary variable declarations with it. Then call that method from main. Compile and test!
  7. Take some time to look at each variable you've declared. Remove any unncessary variables.
  8. Copy and paste the methods you wrote in the first steps into this program. Compile to make sure that the methods are in the correct location. (You won't even be using them at this point.)
  9. Modify the program so that it calls each of the methods when appropriate. Compile and test.
  10. Make sure all indentation and documentation is up to spec. Compile and test.

Submission of Programs / Grading Criteria

When turning in your program, you should bring a printout of your source code to class. In addition you should email a copy of your source code to the homework account.

Recall that each method should have a description of it's purpose as part of the documentation.

Your program will be graded according to the following criteria:

Correctness/Completeness 10 pts
Documentation 3 pts
Design/Structure 7 pts
Total 20 pts

tsergeant@hsutx.edu

Quick Links