C++ please, Specify, design, and implement a class that can be used in a program that simulates a combination lock. The lock has a circular knob, with the numbers 0 through 39 marked on the edge, and it has a three-number combination, which we'll call x, y, z. To open the lock, you must turn the knob clockwise at least one entire revolution, stopping with x at the top; then turn the knob counter-clockwise; stopping the second time that y appears at the top; finally turn the knob clockwise again, stopping the next time the z appears at the top. At this point the lock will be open. Your lock class should have a constructor that initializes the three-number combination (use 0,0,0 for default arguments). Also provide member functions: a. To alter the lock's combination b.To turn the knob in a given direction until a specified number appears on top c. To close the lock d. To attempt to open the lock e. To inquire the status of the lock (open or shut) f. To tell you what number is currently at the top You must use the class as defined on the back side of this paper for lock then derive a class object called safe that you will use in main. You are not allowed to change member function names or formats. You may however add data members to the private section as needed (no data members are to be made public). class lock { private: // THIS IS THE ONLY PLACE YOU MAY ADD VARIABLES bool open_lock(); protected: lock (int =0, int =0, int =0); void turn knob(int direction); void close_lock()l; bool lock status(); void change combo(); int num_at_top(); };
C++ please,
Specify, design, and implement a class that can be used in a program that simulates a combination lock. The lock has a circular knob, with the numbers 0 through 39 marked on the edge, and it has a three-number combination, which we'll call x, y, z. To open the lock, you must turn the knob clockwise at least one entire revolution, stopping with x at the top; then turn the knob counter-clockwise; stopping the second time that y appears at the top; finally turn the knob clockwise again, stopping the next time the z appears at the top. At this point the lock will be open.
Your lock class should have a constructor that initializes the three-number combination (use 0,0,0 for default arguments). Also provide member functions:
a. To alter the lock's combination
b.To turn the knob in a given direction until a specified number appears on top
c. To close the lock
d. To attempt to open the lock
e. To inquire the status of the lock (open or shut)
f. To tell you what number is currently at the top
You must use the class as defined on the back side of this paper for lock then derive a class object called safe that you will use in main. You are not allowed to change member function names or formats. You may however add data members to the private section as needed (no data members are to be made public).
class lock
{
private:
// THIS IS THE ONLY PLACE YOU MAY ADD VARIABLES
bool open_lock();
protected:
lock (int =0, int =0, int =0);
void turn knob(int direction);
void close_lock()l;
bool lock status();
void change combo();
int num_at_top();
};
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images