Consider the following definition and implementation of the PasswordKeypad class and answer the questions that follow: /

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Consider the following definition and implementation of the PasswordKeypad class and answer the questions that follow: /

Post by answerhappygod »

Consider The Following Definition And Implementation Of The Passwordkeypad Class And Answer The Questions That Follow 1
Consider The Following Definition And Implementation Of The Passwordkeypad Class And Answer The Questions That Follow 1 (25.7 KiB) Viewed 59 times
Consider the following definition and implementation of the PasswordKeypad class and answer the questions that follow: //definition class PasswordKeypad : public Dialog { Q_OBJECT private: QString password; QLabel * passwordLabel; public: PasswordKeypad(); public slots: void keylpressed(); void key2pressed(); void key3pressed(); void key4pressed(); }; // implementation PasswordKeypad: : PasswordKeypad() : password (""), passwordLabel (new QLabel("")) { Pushbutton * keyi = new QPushButton("1"); QPush Button * key2 new QPushButton ("2"); QPush Button key3 new QPushbutton ("3"); QPush Button * key4 = new Pushbutton ("4"); . =
QPushbutton * OKButton = new QPushbutton ("OK"); * QVBoxLayout vLayout = new QVBoxLayout(); QHBoxLayout * keys Layout = new QHBoxLayout(); vLayout->addWidget (passwordLabel); keys Layout->addWidget (keyl); keys Layout->addWidget (key2); keys Layout->addWidget (key3); keys Layout->addWidget (key4); vLayout->addLayout(keysLayout); vLayout->addWidget (OKButton); setLayout (vLayout); connect (keyi, SIGNAL (clicked()), this, SLOT (keylpressed())); connect (key2, SIGNAL (clicked()), this, SLOT (key2pressed())); connect(key3, SIGNAL (clicked(), this, SLOT (key3pressed())); connect (key4, SIGNAL (clicked()), this, SLOT (key4pressed())); connect (OKButton, SIGNAL (clicked()), this, SLOT (close()); } void PasswordKeypad: : keylpressed() { password += "1"; passwordLabel->setText (QString (password.length(),'*')); }
The implementations of key2pressed(), key3pressed() and key4pressed() are identical to keylpressed() except that the relevant digit ("2", "3" or "4") is used instead of "1". 1.1 Why are the string and the label (password and passwordLabel) declared as data members of PasswordKeypad, as opposed to the buttons and layouts which are declared as local variables in the constructor? (2) 1.2 The class definition above contains the keywords public slots: This is not standard C++ syntax, but the compiler does not give an error. Why not? (2) 1.3 Explain the purpose and working of the Qt framework's child-management facility. (5) 1.4 With respect to child-management, identify which statements of the given code make which objects children of which parents. (3) 1.5 The last statement of the constructor of the PasswordKeypad class connects the clicked() signal of OKButton to the close () slot of this, but close() is not declared as a slot of PasswordKeypad. Why is this not a problem? (2) 1.6 The above class uses four slots which do identical work. The design can be simplified by extracting the key of the button that was pressed from its text and using that in a single slot. Write a slot function called keyPressed() to replace the four slots. Also explain what changes need to be made to the PasswordKeypad class. (6) 1.7 Consider the constructor of the MyMainWindow class below and answer the question that follows: MyMainWindow:: MyMainWindow() {
QMenu * menu = new QMenu ("&Services", this); QAction * action = new QAction("&Login", this); QActionGroup * actionGroup = new QActionGroup(); actionGroup->addAction (action); menu->addActions (actionGroup->actions()); this->menuBar () ->addMenu (menu); connect (action, SIGNAL (triggered()), this, SLOT (getPassword())); } Change the constructor of MyMainWindow so that the main window also has a toolbar at the bottom with a single button on it. When the user clicks on the button, the effect should be the same as clicking on the Login option on the Services menu. (5) Maximum number of characters including HTML tags added by text editor): 32,000
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply