|
|
Object-Oriented Assignments
|
|
|
|
Assignment 5
|
|
|
|
separate linked array and dynamic array into header/body
|
|
|
|
remove templates
|
|
|
|
compile using both methods and run test
|
|
|
|
now add templates
|
|
|
|
compile classes
|
|
|
|
try to link to main
|
|
|
|
its not working,
|
|
|
|
how to fix?
|
|
|
|
three methods
|
|
|
|
drawbacks
|
|
|
|
which is the best?
|
|
|
|
compile and link and run sniffex.c in sudo mode and tell the output!
|
|
|
|
having a pack of files with dependencies, make it compile and work using both methods
|
|
|
|
DynamicArray
|
|
|
|
Resize
|
|
|
|
Order
|
|
|
|
Solving Edges
|
|
|
|
Memory Fragmentation
|
|
|
|
LinkedArray
|
|
|
|
Encapsulating Linked List
|
|
|
|
Container Interface
|
|
|
|
String
|
|
|
|
BigNumber
|
|
|
|
Associative Array
|
|
|
|
Vector2D
|
|
|
|
Basic Object Oriented
|
|
|
|
Copy Constructor
|
|
|
|
Syntax: myclass(const myclass&)
|
|
|
|
function argument
|
|
|
|
myclass y=x; //assignment
|
|
|
|
myclass y(x); //constructor
|
|
|
|
Properties
|
|
|
|
Getter/Setter
|
|
|
|
read-only properties
|
|
|
|
Public member
|
|
|
|
Property (language spec)
|
|
|
|
Static members
|
|
|
|
Static methods (for class not for object)
|
|
|
|
Class member initialization
|
|
|
|
member variables
|
|
|
|
static const
|
|
|
|
Function Overloading
|
|
|
|
method overloading
|
|
|
|
Library Management and Linking
|
|
|
|
Why Terminal?
|
|
|
|
Text-only
|
|
|
|
Remote / Bandwidth
|
|
|
|
No-Feedback
|
|
|
|
Platform Definition
|
|
|
|
Solution Making
|
|
|
|
why so many files?
|
|
|
|
how to name files?
|
|
|
|
how to include them?
|
|
|
|
Linking
|
|
|
|
g++ fullcode
|
|
|
|
g++ -o
|
|
|
|
Linking a function to your code
|
|
|
|
g++ file1 file2 file3 -o output
|
|
|
|
g++ -c code -o code.o (no linking, just compile and make object. preparing header/body)
|
|
|
|
why header/body?
|
|
|
|
body is compilable into object (body + many headers)
|
|
|
|
header is compilable but not linkable
|
|
|
|
header/body dissolves dependency problems
|
|
|
|
compiling with makefile only recompiles files that are changed
|
|
|
|
Using extern on a variable + linking
|
|
|
|
g++ -I/usr/opt/include
|
|
|
|
g++ -L/usr/opt/lib
|
|
|
|
g++ -lpcap
|
|
|
|
g++ -S assembly
|
|
|
|
Link error : undefined symbol
|
|
|
|
Open Source Development
|
|
|
|
libs
|
|
|
|
Static Linking
|
|
|
|
Dynamic Linking
|
|
|
|
makefile
|
|
|
|
configure script
|
|
|
|
make
|
|
|
|
make install
|
|
|
|
File Operations
|
|
|
|
Binary Files
|
|
|
|
Open
|
|
|
|
Read
|
|
|
|
Seek
|
|
|
|
Close
|
|
|
|
Filesystem
|
|
|
|
Text Files
|
|
|
|
abstraction
|
|
|
|
usage
|
|
|
|
Open
|
|
|
|
Read
|
|
|
|
Parse
|
|
|
|
Close
|
|
|
|
Command Line Arguments
|
|
|
|
How to use
|
|
|
|
Commong usage
|
|
|
|
Benefits
|
|
|
|
Other forms of IPC
|
|
|
|
Search and Sort Algorithms
|
|
|
|
Linear Search
|
|
|
|
Binary Search
|
|
|
|
Hash Search
|
|
|
|
O(n^2) Sorts
|
|
|
|
Bubble
|
|
|
|
Insertion
|
|
|
|
Selection
|
|
|
|
etc
|
|
|
|
O(n) Sorts
|
|
|
|
Counting Sort
|
|
|
|
O(n lg n) Sorts
|
|
|
|
Merge Sort
|
|
|
|
Quick Sort
|
|
|
|
Heap Sort
|
|
|
|
Operator Overloading
|
|
|
|
Unary Prefix Operators
|
|
|
|
Unary Postfix Operators
|
|
|
|
Infix / RPN for evaluation
|
|
|
|
Binary Arithmetic Operators
|
|
|
|
Binary Relational Operators
|
|
|
|
Binary Assignment Operators
|
|
|
|
Refernce or Value?
|
|
|
|
Access Operators
|
|
|
|
Friend Operators, Why and How
|
|
|
|
Typecast Operators
|
|
|
|
IOStream Operators
|
|
|
|
Basic Data Structures
|
|
|
|
Stack
|
|
|
|
Queue
|
|
|
|
DynamicArray
|
|
|
|
Linked List
|
|
|
|
Tree
|
|
|
|
Graph
|
|
|
|
Hash
|
|
|
|
Asynchronous Programming
|
|
|
|
Why async?
|
|
|
|
Polling method
|
|
|
|
Interrupt method
|
|
|
|
Interrupt Handlers
|
|
|
|
Registering for an Interrupt
|
|
|
|
Implementations of Asynchronous Programming
|
|
|
|
Callbacks
|
|
|
|
Function Pointers
|
|
|
|
Usually with Closures (not C++)
|
|
|
|
Threads
|
|
|
|
Operating System abstraction
|
|
|
|
Separate Stack Segment
|
|
|
|
Concurrent Programming
|
|
|
|
Parallel CPU Cores
|
|
|
|
Time Slice (Non Atomicity)
|
|
|
|
Critical Regions (Thread Unsafety)
|
|
|
|
Asynchronous Mechanisms
|
|
|
|
Events
|
|
|
|
I/O Critical Operations
|
|
|
|
Signals
|
|
|
|
Errors
|
|
|
|
Conceptual Inheritance and Object Relations
|
|
|
|
Inheritance
|
|
|
|
Defines is_a
|
|
|
|
Public
|
|
|
|
usual method, common languages
|
|
|
|
derived inherits from base
|
|
|
|
base is more general
|
|
|
|
derived is more specific
|
|
|
|
Protected
|
|
|
|
not important :)
|
|
|
|
Private
|
|
|
|
Another method of composition/aggregation
|
|
|
|
Only C++
|
|
|
|
Only one instance
|
|
|
|
Not recommended
|
|
|
|
Composition (ownership)
|
|
|
|
Defines has_a (owns_a)
|
|
|
|
Car has an Engine
|
|
|
|
instantiate Engine in Car
|
|
|
|
or use Private inheritance
|
|
|
|
If Car is created, Engine is created as well
|
|
|
|
If Car is gone, Engine is gone for good
|
|
|
|
Much more common than inheritance
|
|
|
|
Depicted in UML as "filled diamond"
|
|
|
|
Aggregation (non ownership)
|
|
|
|
Defines has_a
|
|
|
|
Lake has a Duck
|
|
|
|
Ahmad has a Car (but his brother also has the same car)
|
|
|
|
a Reference/Pointer to the Duck in Lake
|
|
|
|
Can have an array of References (DynamicArray<Car*> myCars)
|
|
|
|
If Ahmad is gone, the Car is still there
|
|
|
|
If Lake is gone, Duck is still there
|
|
|
|
Even more common than Composition
|
|
|
|
Forms most of object-relations in Object Oriented Design
|
|
|
|
Depicted in UML as "unfilled diamond"
|
|
|
|
Containment
|
|
|
|
LinkedArray contains lots of Linked List Cells
|
|
|
|
DynamicArray<float> contains lots of Floats
|
|
|
|
Very common in use, Whenever we need groups
|
|
|
|
Common Forms:
|
|
|
|
Dynamic Array
|
|
|
|
Linked List
|
|
|
|
Associative Array
|
|
|
|
Hash Table
|
|
|
|
Hash Map
|
|
|
|
Binary Tree
|
|
|
|
Heap (Priority List)
|
|
|
|
Multiple Inheritance
|
|
|
|
Only allowed in C++
|
|
|
|
Strictly not recommended, Except for implementing Interfaces
|
|
|
|
Causes Design to be a Graph, instead of a Tree
|
|
|
|
Graphs are hard (bad)
|
|
|
|
Trees are simple (good)
|
|
|
|
Abstract Class
|
|
|
|
A class that has at least "one abstract method"
|
|
|
|
Abstract method is : virtual type method(type arg,...) = 0;
|
|
|
|
has no body
|
|
|
|
should be virtual
|
|
|
|
equals zero
|
|
|
|
Abstract Classes can't get instantiated
|
|
|
|
They are only good for heritage!
|
|
|
|
Form more complex interfaces (with member variables)
|
|
|
|
30% of classes in a project are usually abstract
|
|
|
|
Interface
|
|
|
|
Abstract classes without any member variables and function bodies
|
|
|
|
Or, a set of abstract functions
|
|
|
|
Define protocols to work with a group of classes
|
|
|
|
classes "implement" some interfaces, Thus they accept the protocol
|
|
|
|
Makes programming easy both in concept and context
|
|
|
|
more than 90% usage in projects
|
|
|
|
Templates
|
|
|
|
Function Templates
|
|
|
|
template <class T> T& getMax(T a, T b);
|
|
|
|
float x,y; getMax(x,y);
|
|
|
|
getMax<int>(x,y);
|
|
|
|
Class Templates
|
|
|
|
template <class T, class U> class myClass { ... };
|
|
|
|
myClass <int,float> a;
|
|
|
|
outside method body is
|
|
|
|
template <class T> void myClass<T>::myMethod(T input);
|
|
|
|
Template Specialization
|
|
|
|
template <> class DynamicArray <bool> {...};
|
|
|
|
Non-type Templates
|
|
|
|
template <class T, int N> class DynamicArray { T * data= new T [N] ; };
|
|
|
|
Template Header/Body problem
|
|
|
|
Error Handling
|
|
|
|
Errors happen when Exceptions happen
|
|
|
|
Exceptions are bad, Errors are good
|
|
|
|
Making an Error
|
|
|
|
force division by zero (C Style)
|
|
|
|
throw object; (C++ Style)
|
|
|
|
How to handle exceptions?
|
|
|
|
Try/Catch blocks
|
|
|
|
Try { erroneous code here }
|
|
|
|
Catch (type e) { ... }
|
|
|
|
Catch (...) { all arguments }
|
|
|
|
Signals / Signal Handling
|
|
|
|
Standard Exceptions
|
|
|
|
exception base class
|
|
|
|
catch with reference (don't cut the tail)
|
|
|
|
char * what(); //description method
|
|
|
|
List of common exceptions
|
|
|
|
bad_alloc
|
|
|
|
bad_cast
|
|
|
|
bad_exception (no match)
|
|
|
|
bad_typeid
|
|
|
|
ios_base::failure
|
|
|
|
Software Development Methodologies
|
|
|
|
STL
|
|
|
|
Version Control
|
|
|
|
GUI Programming
|
|
|