Title: LaTeX Notes
1LaTeX Notes
All Latex files must have the extension
.tex Create LaTeX files using an ordinary text
editor. Skeleton LaTeX file \documentclassarti
cle \begindocument text goes
here \enddocument
2LaTeX Notes
Use latex myfile to compile a latex file Use
xdvi myfile to view a compiled latex file Use
dvipdf myfile to generate a pdf file of your
compiled latex file.
3LaTeX Notes
Generating math equations Equations are
indicated by eg x2 To write a
math fraction, use \fracdxdy To write large
brackets, use \left( and \right)
4LaTeX Notes
To do a section heading use \sectionAssignment
3 Example math equation \fracddx x2
2 x
5Object Orientated Programming
The fundamental unit of OOP is the
object. Objects are simply an encapsulation of
data and functions that act on data. TCircle
class double x, y, radius double
area() return 23.1415radius
6Object Orientated Programming
TCircle circle circle.radius 12.3 print
circle.area() The reason for this
representation is that real-world entities have
an analogous grouping, so OOP tries to enable a
programmer to describe a problem in a more
natural way. Thus a real-world circle has
dimensional properties but it also has a set of
operations that can be applied to it.
7Object Orientated Programming
CLASS A class is a blue-print for an
object. OBJECT An object is an actual instance
of a class
8Object Orientated Programming
- Three three main concepts in OOP are
- Encapsulation
- Inheritance
- Polymorphism
9Object Orientated Programming
- Three three main concepts in OOP are
- Encapsulation
- Inheritance
- Polymorphism
- Encapsulation allows a programmer to hide
unnecessary details from another programmer. - It also allows a programmer to protect code from
accidental corruption. The end result is more
robust program development.
10Object Orientated Programming
Inheritance Inheritance is the ability to build
new classes based on existing classes. In other
words it allows one to extend the behaviour of a
parent class by inheriting core functionality
into a child class.
11Object Orientated Programming
TCircle class double x, y, radius
TColor fillColor, penColor double area()
void draw() . TSquare class
double x, y, w, h TColor fillColor,
penColor double area() void
draw() .
12Object Orientated Programming
TShape class double x, y TColor
fillColor, penColor TSquare class inherit
from TShape double w, h double area()
void draw() . TCircle class
inherit from TShape double radius
double area() void draw() .
13Object Orientated Programming
Inheritance introduces the idea of specialization
and generalization. Inheritance also encourages
code reuse. Taxonomy is the classic
inheritance problem.
14Object Orientated Programming
Polymorphism This feature allows a programmer to
treat related objects in the same way. Each of
our shapes has a draw function. This is used to
draw the object on the screen. To create a
polymorphic draw function we need to declare an
empty draw function in the parent class called a
virtual function. A virtual function doesnt
actually have any code, its just a declaration
of intent.
15Object Orientated Programming
Polymorphism In child classes, we now declare
all our draw() functions as overriding the
parent draw() function. TShape class void
draw() virtual TCircle class inherits from
TShape override void draw() ..
16Object Orientated Programming
Polymorphism We can create an entire family of
shapes where each shape overrides the draw()
function. But why bother? It means that if I
receive a shape variable and I want to draw it, I
no longer have to worry about what shape it
actual is. For example I can now create an array
of TShapes and store in it different kinds of
shapes (provided they inherit from TShape). If I
want to draw each shape all I do is for (i 0
IltnShapes I) shapesi.draw()
17Object Orientated Programming
Application