Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4,6 TrustPilot
logo-home
Document preview thumbnail
Preview 10 out of 91 pages
Summary

COMPLETE! COS2614 Summary (Programming: Contemporary Concepts)

Document preview thumbnail
Preview 10 out of 91 pages

This summary contains in depth concepts, explanations and examples which will not only allow you to reduce the amount of time you have to study, but will also assist you with getting a distinction for this module. This summary will replace your prescribe book entirely!

Content preview

c++ general summary:
Creating class in QT:
Right click on your project, say add new, then chose class. Then just type in
class name and header and cpp file will automatically be created for you.
Also, right click on a function and go refactor, then go add definition in .cpp file
then it will create an auto implementation for you.



General theory:
Partial overriding:
To implement an overridden function using partial overriding that means we
call the overridden function in the overwriting function to calculate something.
E.g. say calculateRental() was overridden

double Video::calculateRental(int num) const{

double rental = Film::calculateRental(num); //calling the overridden function

return (rental - (rental * discount / 100)) ;
}

Features of QMainWindow that allows for QAction objects:
QMenu and QToolBar

setCentralWidget(QWidget *wt)
Note this function takes a QWidget object, but you can add view classes object
inside as argument since the view class derived from QDialog or
QMainWindow and those classes derive from QWidget.
You can also put widgets like button as central widget since buttons derive
from Viewclass which derive from QDialog which derives from QWidget.

3 visible features that can be added to QAction(sub menus)
Text, icon, shortcut, tooltip

Destructor when QMap and QList are data members

,Both fooLsit and fooMap point to Foo objects. The 1st statement deallocate the memory occupied by
the objects. Now the 2nd statement tries to deallocate the Foo objects, but since they have already
been deallocated a runtime error will occur. Sollution is to remove one of the statements.

Implicit sharing application of Qt containers(lists)
When a copy of a Qt container is made, the data values stored in the container are not
copied unless a change is made to one or more elements of either container. Implicit
sharing saves memory, and delays the process of copying containers until it is necessary

Abstract class
An abstract class is a class that is designed to be specifically used as a base class.
An abstract class contains at least one pure virtual function which will get overridden by an
inheriting class.

Coutn function to check if there are repeated numbers in a
list:
foreach(int i, result){
if(result.count(i) > 1){ //here we use count function, count returns
number on instances of argument in the list, result is the list
message = "Input contains repetitions.";
}


When a function is written skew in UML then it is pure
virtual function, when it is not, but appear in inheriting
classes then it is non pure virtual function.
Purpose of having a function in a list class that adds objects
of the list instead of using the append.

,To implement a customized element addition to QList, which is different from the addition offered by the
append() of QList . For example, to ensure that all objects pointed to by Account*s in AccountList have unique
account numbers


Note when we working with a List Class which have no
members and we want to call it’s functions then just go this-
> before the function call or call it by itself:
double SavingsAccount::totalBalance() const{

double result = 0;


for(int i =0; i < this->size(); i++){ //call size() without object, e.g. object.size

result += this->at(i)->getBalance(); //call list’s at() function without object @ front

} return result;

}


Constructor of this list class without data members
AccountList::~AccountList() {

qDeleteAll(*this); //give pointer to the current class

}



Creating QAction object with icon saved in file Done.png
and the title “Done”:
QAction *action = new QAction(QIcon("Done.png"), "Done", this);


UML Notation and what it means:
Composition/aggregation relationship: It is when a class is a
member in another class we say that the member class is a
part of the other class. It is shown by a diamond. The side of
the diamond is a class who contain the other class as a
member.

,Note UML class have 3 compartments: Class name, data members and then
member functions
When you have a class in another class. It’s better to start of writing the
implementation of the class who is a member of the other class.
Static data member: A static data member is underlined.
nextID is static. To make it static just add ‘static’ in front in the
type and we make it public:
static int nextID;




Inheritance:
here Salary, Commission and Hourly inherit from Payment

,UML visibility (access specifier):
A + on the left side of a function says it is a public member. – means it is
private, # means it’s under the protected access modifier.
Return type is at the end of a member, function or variable



Diffirence between <> and “”:
When you include an existing class you put it between <> and when you include a header
file or class that you created then you put it in between “ “
e.g.
#include <QString>
#include "accounting.h"




Static function:
When you call a static function from a class you don’t need to create an object
of the class 1st.
e.g. Take the QInputDialog class.

,To call a function from an object of the class you would code like this:
QInputDialog object;
object.accept(); //here we go dot and then followed by the
function

With a static function you don’t have to make an instance of that object, you
use the class name and the :: operator.
QString userINput = QInputDialog::getText(); //here we don’t
have to declare an object. Remember :: tells you which class
the function getText() belongs to




const after a function:
double LoyaltyCard:: currentValue() const
{
//If we change any data members in here compiler will give us an error.
Thus //const after a function insures that we don’t change any data
members
}

Always write const after all functions that doesn’t change any
members in the function. So all ‘get’ functions should be changed.
Also toString functions also get const
To use QString & QStringList you need to include them in Qt:
#include "QString"
#include "QStringList"


foreach:
General Syntax:
foreach(typeOfElement element_ofListVar, List)
{
do_somethingWithEachElement;
}



Example:


void displaySalaries(EmployeeList& el, QString type){
cout << "Displaying " << type << " employees: " << "\n";
foreach(Employee e, el){

, if(e.getPayment()->getType() == type){
cout << e.getName() << "\t" << e.getID() << "\t" <<
e.getPayment()->pay()<< "\n";
}
}
cout << endl;
}

Example:
QStringList strList;

strList.append("aaa");
strList.append("bbb");
strList.append("ccc");

foreach(QString s, strList)
{
cout << s << endl;
}

General class implementation documentation:
The only difference between a member function
decleration/definition and implementation header is that in the
header it get class name followed by :: in front of the function
name. Also no semicolon after header
Declaration:
void setDetail(QString name, QString email, bool isManufacturer);

Implementation:
void Vendor::setDetail(QString name, QString email, bool isManufacturer)
{

}

If a variable is constant then the const comes infront of the type:
Employee(const Employee& e);



Virtual functions:
Only put virtual in front of the base class function. Also add const and =
0 to make it pure virtual function, but you don’t have to make it a pure
virtual function. ‘= 0’ makes it a pure virtual function so it will get
overridden. A pure virtual function does not have implementation, so
don’t implement it in .cpp file

,class Payment
{
public:

//virtual function in base class so add 'virtual'
//keyword infront of base class function
virtual double pay() const = 0;

Now in the inheriting class just implement the functions normally and it
will override the base class’ virtual function
class Hourly : public Payment{
public:
Hourly(double hr);
void addHours(double hrs);
double pay() const;

in .cpp file
double Hourly::pay() const{
return hours * hourlyRate;
}

Non pure virtual function:
class A
{
public:
virtual void display() //non pure virtual function
{
cout << "display from class B" << endl;
}
};

class B: public A
{
public:
void display()
{
cout << "display from class B" << endl;
}

};

int main() {
A *APtr;
APtr = new B;
APtr->display(); //will still override A's display function
}

Static implementations:
Put static in front of variable when you declare it.
static int nextID;

Then @ the top of the class .cpp file add

,type class_name::var_name = value;
int Employee::nextID = 1001;

Then increment the variable in constructor and decrement it in destructor

Employee::Employee(QString fn, QString sn)
{
nextID++;
}



Copy constructor and assignment operator:
Give the parameter a constant since we will not change the paramter
variable itself. Also both of them will have the same parameter


//copy constructor
Employee::Employee(const Employee& e)
{

}



How to implement constructor of inheriting class and also
constant value
SYNTAX:
Classname::Classname(par_list):baseClassConstructor(arguments),
data_mem1(par1) ,data_mem2(par2)
Payment::Payment(QString typ):type(typ)
{
}
Salary::Salary(double sal):Payment("Salary"), salary(sal)
{
}
So what is happening here is when a salary is created then the
salary’s constructor is invoked. It sends Salary to Payment
constructor which then update the type data member of Payment

Note we give payment a constant value, sometimes we need to give
values constant values if a value is not provided in the parameter list.
Look out for when they say a data member of base class is protected to
allow it to be initialized by constructors of base classes

, Increment by something:
totalSales += sv;

If you have a class that has another class as a data
member and this class is a base class:

Then you need to include all the inheriting classes in the top class(class
that has other class as its data member) so


Copy constructor and assignment operator with class
pointers:
So if we have this:




Note that the class Employees are responsible for a creation of Employee objects
since it has a constructor that will create Employees

Employee e1("John","Smith"); //creating an employee object

Note that we have a class pointer in Employee and it points to an Payment object.
But this Payment class is an abstract class so no object will be made of it, so we are
going to only make objects of the inheriting classes.

So now in the copy constructor and assignment operator we will have a pointer of
type base class which will point to objects of the inheriting class. So how do we do
this:

Employee::Employee(const Employee& e)
{

Connected book
 image
Publisher: 2011 ISBN: 9780132826457 Edition: 2

Document information

Summarized whole book?
Yes
Uploaded on
October 22, 2020
Number of pages
91
Written in
2018/2019
Type
Summary
R119,00
Purchased by 45 students

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

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
4,6
(58)
Sold
467
Followers
264
Items
4
Last sold
9 months ago


Reviews from verified buyers

5 year ago

this is perfect may you kindly make notes for COS2601 AND COS1511

Thank you! I am planning to, but only in the future.

Thank you!




Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

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

Student with book image

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

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions