100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

AWESOME! COS2614 Exam Solutions (Questions Answers)

Rating
4.3
(3)
Sold
31
Pages
73
Uploaded on
22-10-2020
Written in
2018/2019

7 EASY TO UNDERSTAND exam solutions! Contain BOTH Questions and solutions. Pass your subject with ease with these solutions. The following exams are covered in this document: 2018-06-P1, 2018-06-P2, 2017-10-P1, 2017-06-P2, 2016-10-P1, 2016-06-P1, 2015-10-P1

Show more Read less
Institution
Course

















Whoops! We can’t load your doc right now. Try again or contact support.

Connected book

Written for

Institution
Course

Document information

Uploaded on
October 22, 2020
Number of pages
73
Written in
2018/2019
Type
Exam (elaborations)
Contains
Unknown

Subjects

Content preview

,
,
,
,
,Question 1

bool valid = true;
QString name = "";
do{
name = QInputDialog::getText(0,
"Question 1",
"Please enter name");
if(name.length() == 0)
{
//error message:
QMessageBox::information(0,
"Error",
"Please enter name.");
valid = false;
continue;
}

QStringList list = name.split(",");
if(list.length() < 2){
QMessageBox::information(0,
"Error",
"Please enter first name and last name in
coma separated list.");
valid = false;
continue;
}

name = list.join(" ");
}while(valid == false);

QMessageBox::information(0,"Question 1",name);



Question 2

2.1

Registration::Registration(QString n, QString e, QString a){

attendee = Person(n, e, a);

date = QDate::currentDate();

}

2.2 toString, calculateFee

2.3 It means the class member is static. Which means that it can be accessed at the class level and
it’s value is shared between instances of the same class.

2.4

double StudentRegistration::calculateFee()
{
double _fee = Registration::calculateFee();
return _fee/3;

,}



2.5 class RegistrationList: public QList<Registration*>

2.6 Registration and StudentRegistration by order of inheritance.

2.7

double RegistrationList::totalFee()
{
double total = 0;
for(int i = 0; i < this->size(); i++){
total += this->at(i).calculateFee();
}
return total;
}

2.8 Polymorphism is the ability of something to take on multiple forms. The code in 2.7 shows how
the call to ‘calculateFee’ behaves differently depending on it’s type which can either be Registration
or StudentRegistration.

2.9 It could inherit from QMap<int, Registration*> instead, using int to store the id as the key and
Registration* to store the related value.

It could also make use of a QStack<Registration*> container making it easy to push and pop item in
the list.

2.10

Registration and Person:

They have a composition relationship. It’s a one is to one type relationship where one instance of
Registration can hold one instance of Person.

Registration and RegistrationList:

They have a composition relationship. It’s a one is to many relationship where one instance of
RegistrationList can hold many instances of Registration.

2.11 a. class RegistrationList: public QMap<int, Registration*>

2.11 b. QList allows you to store items directly in your list whereas QMap needs them to be stored in
key value form.

It’s easier to search for items in a QMap because they are accessed using their key. QList needs you
to iterate through the list when searching if you do not know the item’s index.

,Question 3

#ifndef FORTUNECOOKIE_H
#define FORTUNECOOKIE_H
#include <QDialog>

class FortuneCookie: public QDialog
{
Q_OBJECT

public:
FortuneCookie();
public slots:
on_button_click();
};

#endif // FORTUNECOOKIE_H


#include "fortunecookie.h"
#include <QPushButton>
#include "quotefactory.h"
#include <QMessageBox>
#include <QString>

FortuneCookie::FortuneCookie()
{
setFixedSize(150,50);
QPushButton* btn = new QPushButton("Open a fortune cookie",this);
setWindowTitle("Fortune Cookie");
connect(btn,SIGNAL(clicked(bool)),this,SLOT(on_button_click()));
}

FortuneCookie::on_button_click()
{
QuoteFactory qf;
QString quote = qf.getQuote();
QMessageBox::information(0,"Message",quote);
}


3.2 The child management facility is the ability of the parent container to manage the life time of its
child objects. When the parent is removed from memory, it will ensure that any child pointers are
deleted preventing memory leaks.

3.3 Views are classes responsible for generating the user interface. Model classes hold the data/
application logic used by the application. The benefit of this is that you can reuse application logic
between applications and user interfaces.

3.4 a.

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QMenu* menu = new QMenu("&Applications", this);
QAction* action = new QAction("&FortuneCookie", this);
QActionGroup* actionGroup = new QActionGroup(this);
actionGroup->addAction(action);

, menu->addActions(actionGroup->actions());
menuBar()->addMenu(menu);
QToolBar* toolbar = new QToolBar("Cookie bar",this);
toolbar->addActions(actionGroup->actions());
QMainWindow::addToolBar(Qt::BottomToolBarArea, toolbar);
connect(action, SIGNAL(triggered(bool)), this,
SLOT(startApplication()));
}


3.4 b.

void MainWindow::startApplication()
{
FortuneCookie* fc = new FortuneCookie();
setCentralWidget(fc);
}




Question 4

4. 1 Design patterns are efficient and elegant solutions to common problems in object oriented
software design. They are high-level abstract templates that can be applied to particular kinds of
design problems.

4.2 They attempt to express similar code in an abstract way, this allows for code reuse. Design
patterns also promote extensibility. A measure of how easy it is to add improvements to an
application

4.3

Composite: Every QObject maintains a list of its children. You can make one QObject a child of
another by calling setParent(), which automatically adds it to the list of children of its parent.

Observer: The QObject class represents the application of a simplified form of the observer pattern,
particularly in its implementation of signals and slots.

4.4 The implementation of implicit sharing in Qt containers applies a simplified form of the classic
flyweight pattern. Although it represents a way of saving memory by sharing data that would
otherwise be duplicated, there isn’t any explicit data. Examples: QString, QVariant, and QStringList.

4.5 It composes objects into tree structures to represent part-whole hierarchies. It is intended to
facilitate building complex (composite) objects from simpler (component) parts representing tree-
like structures.

4.6 Client, Component, Leaf and Composite.

,
$6.63
Get access to the full document:
Purchased by 31 students

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Also available in package deal

Reviews from verified buyers

Showing all 3 reviews
3 year ago

3 year ago

4 year ago

4.3

3 reviews

5
2
4
0
3
1
2
0
1
0
Trustworthy reviews on Stuvia

All reviews are made by real Stuvia users after verified purchases.

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
francoissmit University of South Africa (Unisa)
Follow You need to be logged in order to follow users or courses
Sold
467
Member since
5 year
Number of followers
264
Documents
4
Last sold
3 weeks ago
Computer Science Notes guaranteed to make you pass and finished my BSc in Computing degree

Over the years I have excelled at making summaries. These summaries I used to get 27/31 distinctions. What are you waiting for? You can get a distinction as well if you use my summaries and notes.

4.6

58 reviews

5
43
4
9
3
5
2
0
1
1

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions