Everyone is familiar with the number guessing game. “I’m thinking of a number between 1 and 100” is how it starts. Then people start guessing numbers to see if anyone can get it right. You are going to write the entire header file for a class
named guessGame that can be used by someone writing a program that simulates this simple game. Your class has one data item: an integer that will hold a random number. Your class has the following member functions:
• Default constructor that will set the random number to a number between 1 and 100. You will have to seed the random number generator before calculating the random number.
• isSame is a function that will take a number that is passed to it andreturn true if the number matches the random number stored in the object. It returns false if the number does not match.
• giveUp is a function that has no arguments. It simply returns the random number stored in the object.
Header file goes below.
Header file help c++?
class guessGame {
//Fill it up
};
Reply:First you do an
#ifndef GUESSGAME
#define GUESSGAME
Then you include your header files, %26lt;iostream%26gt; at least and possibly %26lt;cstlib%26gt; for the random function, then you define your class but do not implement its methods.
Finally you do an
#endif
so if the header is called twice it only gets written into the preprocessed file once.
EDIT: If your professor wants you to implement methods, the general procedure is to do so in a separate .cpp file. You may as well ask.
This should all be very straightforward from here.
Reply:Do your own homework.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment