100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COMPLETE! COS2614 Summary (Programming: Contemporary Concepts) $6.78   Add to cart

Summary

COMPLETE! COS2614 Summary (Programming: Contemporary Concepts)

7 reviews
 377 views  44 purchases
  • Course
  • Institution
  • Book

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!

Preview 10 out of 91  pages

  • Yes
  • October 22, 2020
  • 91
  • 2018/2019
  • Summary

7  reviews

review-writer-avatar

By: h_ayanda • 2 year ago

review-writer-avatar

By: jamesdeanmanderson • 1 year ago

review-writer-avatar

By: npritilall • 3 year ago

review-writer-avatar

By: raymondpiek • 3 year ago

review-writer-avatar

By: rtinent • 2 year ago

review-writer-avatar

By: coolboyh98 • 3 year ago

review-writer-avatar

By: baeLungsta • 4 year ago

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

reply-writer-avatar

By: francoissmit • 4 year ago

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

reply-writer-avatar

By: baeLungsta • 4 year ago

Thank you!

avatar-seller
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)
{

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller francoissmit. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $6.78. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

67096 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$6.78  44x  sold
  • (7)
  Add to cart