Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help on my C++ project The Class DoorKnob represents some kind of turnabl

ID: 3771767 • Letter: I

Question

I need help on my C++ project

The Class DoorKnob represents some kind of turnable handle.
The instances knob and goldenknob were created by saying:

Knob ImageDoorKnob knob;   By default, an unlockable door knob
Knob ImageDoorKnob goldenknob( true );   A lockable door knob


Based on this implementation of DoorKnob, define and implement the class SmartKnob (a .h file and a .cpp file). A Smart DoorKnob instance represents an internet connected Knob that sends its state information to other connected devices. The relationship between SmartDoorKnob and DoorKnob is shown in the class diagram below.

DoorKnob

^
|
|
|
SmartDoorKnob


Make sure your definition of SmartKnob supports the following kinds of constructors:

Locked Door   // by default, a smart door knob that is locked
SmartKnob knob;
Unlocked Door   // a smart door knob that is unlocked and lockable
// false indicates it is not locked
// true parameter indicated is lockable
Door UnlockedAndOpen( false, true );

The SmartKnob constructor must call the parent-class Knob constructor

----------------------------------------DriverSample.cpp -------------------------------------

#include <iostream>
#include <stdexcept>
#include <string>
#include "DoorKnob.h"
using namespace std;

int main()
{
DoorKnob ();
DoorKnob (bool isLockable);
void turn();
void push();
void pull();
bool canBeLocked() const;
void lock(); // only does something if the knob
// is lockable
void unlock();
bool myIsLockable;
bool isLocked;

return 0;
}

---------------------------------DoorKnob.cpp-----------------------------------

#include <iostream>
#include <stdexcept>
#include <string>
#include "DoorKnob.h"

DoorKnob::DoorKnob() {
myIsLockable=false;
myIsLocked=false;
}

DoorKnob::DoorKnob( bool isLockable ) {
myIsLockable=isLockable;
myIsLocked=false;
}

void DoorKnob::turn()
{
if (!myIsLocked)
{
cout << "turning knob..." << endl;
}
else
{
cout << "knob is locked!" << endl;
}
}

void DoorKnob::push()
{
if (!myIsLocked)
{
cout << "pushing knob..." << endl;
}
else
{
cout << "knob is locked!" << endl;
}
}

void DoorKnob::pull()
{
if (!myIsLocked)
{
cout << "pulling knob..." << endl;
}
else
{
cout << "knob is locked!" << endl;
}
}

bool DoorKnob::canBeLocked() const {
return( myIsLockable );
}

void DoorKnob::lock() {
if (myIsLockable) { myIsLocked=true; }
}

void DoorKnob::unlock() {
if (myIsLockable) { myIsLocked=false; }
}

-----------------------------------------------DoorKnob.h------------------------------------------------

#ifndef DOORKNOB_H
#define DOORKNOB_H
#include <iostream>
using namespace std;

class DoorKnob
{
public:
DoorKnob ();
DoorKnob (bool isLockable);
void turn();
void push();
void pull();
bool canBeLocked() const;
void lock(); // only does something // if the knob is lockable
void unlock();

private:
bool myIsLockable;
bool myIsLocked;
};
#endif

Explanation / Answer

Your question is quite clear and your code is bit wierd. Also your naming of class and functions is not uniform. Sometimes its "SmartKnob knob;" and sometimes its "SmartDoorKnob knob;". This makes things less understandable.

What I could understand from your question is that you need a sub class of DoorKnob class which has some additional functions to make it able to send its lock status to other doors. So here I wrote a code as per my understanding of the question.

SmartDoorKnob.h

#ifndef SMARTDOORKNOB_H
#define SMARTDOORKNOB_H
#include <iostream>
#include "DoorKnob.h"

using namespace std;
class SmartDoorKnob: public DoorKnob
{
   public:
   SmartDoorKnob::SmartDoorKnob();   
   SmartDoorKnob::SmartDoorKnob(bool flag, bool flag2);
   void sendLockStatus();
  

};
#endif

SmartDoorKnob.cpp

#include <iostream>
#include <stdexcept>
#include <string>
#include "DoorKnob.h"
#include "SmartDoorKnob.h"
using namespace std;
SmartDoorKnob::SmartDoorKnob() // Unlocked door constructor
{
  
   myIsLocked=true;
  
}

SmartDoorKnob::SmartDoorKnob(bool flag, bool flag2) { // UnlockedAndOpen door constructor
  
   myIsLockable=flag;
   myIsLocked=flag2;
  
}
void SmartDoorKnob::sendLockStatus()
{  
       cout << "Sending Lock Status..."<< myIsLocked << endl;
  
}

Change the two private members of DoorKnob class to protected

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote