Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program is for a combination lock in C++. lock.h class lock { public: static const int SIZE = 40; static const int MAX_NUMBER =

This program is for a combination lock in C++.

lock.h

class lock

{

public:

static const int SIZE = 40;

static const int MAX_NUMBER = SIZE - 1;

lock(int combo1, int combo2, int combo3);

void setcombo(int combo1, int combo2, int combo3);

void turn(int number, bool is_clockwise, int turns);

void close();

void try_to_open();

bool is_open() const

{

return open;

}

int top() const;

private:

int combo1, combo2, combo3;

int state = 0;

bool open;

};

lock.cpp

lock::lock(int combo1 = 0, int combo2 = 0, int combo3 = 0)

{

this->combo1 = combo1;

this->combo2 = combo2;

this->combo3 = combo3;

}

void lock::setcombo(int combo1, int combo2, int combo3)

{

this->combo1 = combo1;

this->combo2 = combo2;

this->combo3 = combo3;

}

void lock::turn(int number, bool is_clockwise, int turns)

{

open = false;

switch (state)

{

case 0:

if (state = 0 && number > 0)

{

is_clockwise = true; //right

state = 1;

combo1 = number;

}

break;

case 1:

break;

case 2:

break;

case 3:

break;

}

}

void lock::close()

{

open = false;

}

I'm stuck on the logic concerning my switch statement. The way I'm approaching it is if the state hits 1, 2 and so on the lock is unlocking like a combination. If there's a mistake somewhere, it'll set the state back to zero. I ommited the preprocessors and a demo file because I can do those myself. Any help is appreciated.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

Explain the difference between a tax issue and a research question.

Answered: 1 week ago