EEM 480 Algorithms and Complexity - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

EEM 480 Algorithms and Complexity

Description:

Title: EEM 480 Algorithms and Complexity Author: Emin Last modified by: Germen Created Date: 9/30/2005 10:07:10 AM Document presentation format: On-screen Show – PowerPoint PPT presentation

Number of Views:86
Avg rating:3.0/5.0
Slides: 25
Provided by: Emin
Category:

less

Transcript and Presenter's Notes

Title: EEM 480 Algorithms and Complexity


1
EEM 480 Algorithms and Complexity
  • by
  • Assist. Prof. Dr. Emin Germen

2
What is this Course About
  • Of Course it is about
  • Algorithms
  • Complexity

3
Any More?
  • Algorithms Complexity Data Structure
  • Data Structure Concerns with the representation
    and manipulation of data.
  • All the programs use and manipulate data
  • IS (Computer Programming Data Structure)
  • YES OR NO

4
What is Data Structure
  • Designing the program which modifies data
  • The Key Point

Algorithm
5
What is this Course About
  • Learning and designing algorithms to manipulate
    the data
  • Comparing criteria of different algorithms
  • Understand what a good program is
  • Learning effective utilizations of computer
    sources

6
Syllabus
  • Review of C
  • Classes
  • Encapsulation, Overloading, Inheritance,
    Overriding
  • Pointers to objects
  • Templates
  • Arrays and Linked Lists
  • Linear lists
  • Formula based representation
  • Linked representations
  • Indirect addressing and pointers
  • Arrays and Matrices
  • Arrays, Matrices, Special matrices, Sparse
    matrices
  • Stacks
  • Queues
  • Hash Tables
  • Trees
  • Binary trees
  • Tree traversals
  • Priority Queues

7
Reference and Evaluation
  • Data Structures, algorithms, and Applications
    in C, Sartaj Sahni
  • Evaluation
  • Mt 1 10
  • Mt 2 20
  • Projects 30
  • Final Exam 40

8
Object Oriented Programming
  • Object
  • Class
  • Encapsulation
  • Inheritence
  • Polymormhism

9
Object
  • An object is a bundle of variables and related
    methods.
  • When an object is mapped into software
    representation, it consists of 2 parts
  • DATA STRUCTURE characteristics of data structure
    are refered to as ATTRIBUTES
  • PROCESSES that may correctly change the data
    structureprocesses are refered to as OPERATIONS
    or METHODS

10
Class
  • A class is a blueprint for an object.
  • Objects with the same data structure (Attributes)
    and behavior (Methods or Operations) are grouped
    together (called a class ).

11
Encapsulation
  • Encapsulation is the procedure of covering up of
    data and functions into a single unit
  • Class
  • Data1
  • Data2
  • Procedure1(Data1)
  • Data2 Procedure()
  • Encapsulation hides the implementation away from
    the user

12
Inheritence
  • As objects do not exist by themselves but are
    instances of a CLASS, a class can inherit the
    features of another class and add its own
    modifications. (This could mean restrictions or
    additions to its functionality). Inheritance aids
    in the reuse of code.

13
Polymorphism
  • Polymorphism means the ability to request that
    the same Operations be performed by a wide range
    of different types of things.

14
So What???????
  • What are those things????
  • How can I use them???????
  • I have searched OOP in the Internet and find
    ABSTRACTION. What does it mean????
  • I can write good programs using structural
    proggramming techniques? Why should I use OOP?

15
Intoduction to OOP with C
  • Object Oriented Programming
  • Class
  • The structure which keeps data and function
  • Interitance
  • Inheritance is also called derivation. The new
    class inherits the functionality of an existing
    class. The existing class is called the base
    class, and the new class is called the derived
    class. A similar inheritance can be derived for
    animals, mammals, and dogs.
  • Polymorphisim Overloading
  • Ability to have more than one function with the
    same name that differ in their parameter lists.

16
Program 1
Header for the basic C procedures
  • include ltstdio.hgt
  • include ltiostream.hgt
  • void main(void)
  • cout ltlt "This is not my first program"
  • cout ltlt "\n"

Streaming functions
17
Program 2
  • // Workspace Triangle
  • // Program name Area.cpp
  • // The area of a triangle is half its base times
    height
  • // Area of triangle (Base length of triangle
    Height of triangle)/2
  • include ltiostream.hgt // Precompiled header
  • double base,height,area // Declaring the
    variables
  • double Area(double,double) // Function
    Prototype/declaration
  • int main()
  • cout ltlt "\nEnter Height of Triangle " // Enter
    a number
  • cin gtgt height // Store the input in variable
  • cout ltlt "\nEnter Base of Triangle " // Enter a
    number
  • cin gtgt base // Store the input in variable
  • area Area(base,height) // Store the result
    from the Area function
  • // in the variable area
  • cout ltlt "The Area of the Triangle is "ltlt area
    ltlt endl

The Output
18
Program 3 Polymorphism
  • include ltiostream.hgt
  • double base,height,radius // Global variables
  • double Area_of_triangle,Area_of_circle // Global
    variables
  • int choice // Global variable
  • double Area (double,double) // Function
    prototype
  • double Area (double) // Function prototype
  • const double pi 3.14 // Constant variable
  • void main() // main function
  • cout ltlt "To find the area of a Triangle, input 1
    \n"
  • cout ltlt "To find the area of a Circle, input 2
    \n"
  • cin gtgt choice
  • if (choice 1)
  • if (choice 2)
  • cout ltlt "Enter radius of the Circle "
  • cin gtgt radius
  • Area_of_circle Area(radius)
  • cout ltlt "The area of the Circle is " ltlt
    Area_of_circleltltendl
  • if (choice ! 1 choice ! 2)
  • cout ltlt "Sorry! You must enter either 1 or 2
    \n"
  • double Area (double base, double height)
  • return (0.5baseheight)
  • double Area(double radius)

The Output
19
Defining Class in C
  • Almost same as defining Struct
  • Insert Functions into the Struct
  • Some important functions
  • Constructor
  • Destructor

20
Object Oriented C Class
CCircleCCircle(int r) m_radius
r CCircleCCircle() void
CCircleDisplayArea(void) float
fArea fArea CalculateArea() cout ltlt "The
Arae of the circle " ltlt fArea ltlt "\n" float
CCircleCalculateArea(void) float f f
(float) (3.14 m_radius m_radius) return
f
include ltiostream.hgt class CCircle public CCi
rcle(int r) void SetRadius(int r) void
DisplayArea(void) CCircle() private float
CalculateArea(void) int m_radius int
m_color
CONSTRUCTOR
DESTRUCTOR
21
Dynamic Memory Allocation
  • new
  • int y //pointer
  • y new int // creates place
  • y 10 // OK
  • Or
  • int y new int(10)

22
OOP in C
  • Simple example of defining object and class
  • Programming Example
  • Overloading
  • Programming Example
  • Inheritance
  • Programming Example
  • Templates
  • Programming Example

23
One Dimensional Array and Exception Handling
  • float x new float n
  • Or better
  • float x
  • try x new float n
  • catch (xalloc)
  • cerr ltlt Out of memory ltlt endl
  • exit(1)

24
Delete
  • delete y //free the memory allocated by y
  • delete x // free the one dimensional array
Write a Comment
User Comments (0)
About PowerShow.com