Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the definition and implementation of FortuneCookie below to answer the questions below. 1.5 In the constructor, two objects are allocated on the heap but

Consider the definition and implementation of FortuneCookie below to answer the questions below.

1.5 In the constructor, two objects are allocated on the heap but they are not de-allocated. Is that a problem in this class? Explain.(2)

1.6 Illustrate the parent-child object tree after an object of FortuneCookie is created. (2)

1.7 Assume that the below class needs to be changed so that the messages are displayed at regular intervals. In particular, the user should be able to:

- specify the time interval on the graphical user interface

- click on a start button for the program to read the time entered as well as to start displaying the messages at regular intervals

Write down the modified code of FortuneCookie (both definition and implementation) to achieve the above requirements. No pre-processor directives and no additional features are required in your answer.(8)

//definition

class FortuneCookie: public QDialog {

Q_OBJECT

private:

QStringList messages;

public:

FortuneCookie();

public slots:

void showFortune();

};

//implementation

FortuneCookie::FortuneCookie(){

messages << "Express yourself : Don't hold back" << "For

success today look first at yourself" << "Whenever

possible, keep it simple";

QPushButton *pb = new QPushButton("Open a fortune

cookie");

QVBoxLayout *layout = new QVBoxLayout();

layout->addWidget(pb);

this->setLayout(layout);

connect(pb, SIGNAL (clicked()), this,

SLOT(showFortune()));

}

void FortuneCookie::showFortune(){

QString m = messages[rand()% 3];

QMessageBox::information(this, "Message", m);

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions