正在实现密码锁,但无法弄清楚如何实现旋钮

问题描述

所以从本质上讲,我正在尝试创建一个模拟密码锁的程序。

说明:在本作业中,要求您指定,设计,实现和测试可在模拟密码锁的程序中使用的类。锁有一个圆形旋钮,在边缘上标记了数字0到39,并且有一个三位数字的组合,我们将其称为x,y,z。要打开锁,您必须顺时针旋转旋钮至少整整一圈,并以x停在顶部;然后逆时针旋转旋钮,第二次停止y出现在顶部;最后再次顺时针旋转旋钮,下次z出现在顶部时停止。此时,您可以打开锁。您的锁类应具有一个初始化三位数组合的构造函数认参数使用0、0、0)。

还提供以下成员函数

  1. 将锁的密码更改为新的三位数密码
  2. 沿给定方向旋转旋钮,直到指定的数字出现在顶部。
  3. 关闭锁。
  4. 尝试打开锁。
  5. 查询锁的状态(打开或关闭)。
  6. 告诉您当前排名靠前的数字。

代码如下:

// Lock_Outline.cpp : This file contains a combination lock outline.
//
//CONSTRUCTORS for the Combo_Lock class:
//   Combo_Lock(int x = 0,int y = 0,int z = 0)
//      Precondition: All three lock sections must start at 0.
//      Postcondition: The lock must be able to be opened with the right combination.
//MODIFICATION MEMBER FUNCTIONS for the Combo_Lock class:
//   void AltCombo(int x,int y,int z)
//      Postcondition: These three values are able to be changed.
//   void TurnKnob(bool Dir,int NumClicks)
//      Postcondition: The direction and number for the 3 numbers must be able to be entered in.
//CONSTANT MEMBER FUNCTIONS for the Combo_Lock class:
//   GetLockStatus(()
//      Postcondition: The lock is either open or closed.
//   GetCurrentNumber()
//      Postcondition: The number turned to must be returned.


#include <iostream>
#include <cstdlib>
#include <cassert>
using namespace std;

    class Combo_Lock
    {
    private:
        int  State = 0;                     //State 0 (first number) State 1 (Second number) State 2 
(Third and last number)
        int  NumClicks = 0;            //Number of clicks (0-39) as we would see on a combination 
lock)
        bool LockStatus = false;  //Indicate if the lock is open or locked.
        void OpenLock();                //Opens the lock if we successfully entered the three numbers 
correction 
        void ClosedLock();             //Close the lock and set the State to 0 awaiting the first 
number once again
    public:
        //CONSTRUCTORS
        Combo_Lock(int x = 0,int z = 0);   //Constructor with a default combo of 0,0
        //MODIFICATION MEMBER FUNCTIONS
        void AltCombo(int x,int z);                      //Method to changes the combination
        void TurnKnob(bool Dir,int NumClicks);   //Enter direction and number for 1st,2nd,and 3rd 
number
        //CONSTANT MEMBER FUNCTIONS
        bool GetLockStatus();                                            //See if lock is open or 
closed
        int  GetCurrentNumber();                                   //Return the current number we 
turned to
    };

    void Combo_Lock::AltCombo(int x,int z)
    {
        int x1 = x;
        int y2 = y;
        int z3 = z;
    }



    Combo_Lock::Combo_Lock(int x,int z)
    {
        AltCombo(x,y,z);
    }

    int main()
    {
        int x = 0,y = 0,z = 0;
        int state = 0;
        Combo_Lock Lock1(3,4,6);  // I set the combo to 3,and  6.  

        cout << "Enter the first number.\n\n";
    
        cin >> x;

           assert(x == 3);

           if(x == 3)
              {
       
                  cout << "\nThis is correct.\n\n";
              }

        cout << "\nEnter the second number.\n\n";

        cin >> y;
       
           assert(y == 4);
           if (y == 4)
              {
        
                  cout << "\nThis is correct.\n\n";
              }


        cout << "\nEnter the third number.\n\n";

        cin >> z;

  
           assert(z == 6);

           if (z == 6)
              {
             cout << "\nThe lock has been opened.\n\n";
              }

    
        return EXIT_SUCCESS;
    }
        void Combo_Lock::OpenLock()
        {
        void OpenLock();
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)