Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "EEM 480 Algorithms and Complexity by Assist. Prof. Dr. Emin Germen."— Presentation transcript:

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

2 What is this Course About Of Course it is about : Of Course it is about :AlgorithmsComplexity

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 Learning and designing algorithms to manipulate the data Comparing criteria of different algorithms Comparing criteria of different algorithms Understand what a good program is Understand what a good program is Learning effective utilizations of computer sources Learning effective utilizations of computer sources

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

7 Reference and Evaluation Data Structures, algorithms, and Applications in C++, Sartaj Sahni Data Structures, algorithms, and Applications in C++, Sartaj Sahni Evaluation: Evaluation: Mt 1 10% Mt 1 10% Mt 2 20% Mt 2 20% Projects 30% Projects 30% Final Exam40% Final Exam40%

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

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

10 Class A class is a blueprint for an object. 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 ). 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 Encapsulation is the procedure of covering up of data and functions into a single unitClassData1Data2Procedure1(Data1) Data2 = Procedure() Encapsulation hides the implementation away from the user 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. 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. 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???? What are those things???? How can I use them??????? How can I use them??????? I have searched OOP in the Internet and find ABSTRACTION. What does it mean???? 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? I can write good programs using structural proggramming techniques? Why should I use OOP?

15 Intoduction to OOP with C++ Object Oriented Programming Object Oriented Programming Class Class The structure which keeps data and function Interitance 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 Polymorphisim Overloading Ability to have more than one function with the same name that differ in their parameter lists.

16 Program 1 #include #include void main(void) { cout << "This is not my first program"; cout << "\n"; } Header for the basic C++ procedures 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 // Precompiled header double base,height,area; // Declaring the variables double Area(double,double); // Function Prototype/declaration int main() { cout << "\nEnter Height of Triangle: "; // Enter a number cin >> height; // Store the input in variable cout << "\nEnter Base of Triangle: "; // Enter a number cin >> base; // Store the input in variable area = Area(base,height);// Store the result from the Area function // in the variable area cout << "The Area of the Triangle is: "<< area << endl ; return 0; } double Area (double base, double height) // Function definition { area = (0.5*base*height); return area; } The Output

18 Program 3 Polymorphism # include # include 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 << "To find the area of a Triangle, input 1 \n"; cout << "To find the area of a Circle, input 2 \n"; cin >> choice; if (choice == 1) { cout << "Enter the base of the triangle: "; cin >> base; cout << "Enter the height of the triangle: "; cin >> height; Area_of_triangle = Area(base,height); cout << "The Area of the Triangle is: " << Area_of_triangle<<endl; } if (choice == 2) { cout << "Enter radius of the Circle: "; cin >> radius; Area_of_circle = Area(radius); cout << "The area of the Circle is: " << Area_of_circle<<endl; } if (choice != 1 && choice != 2) { cout << "Sorry! You must enter either 1 or 2 \n"; } double Area (double base, double height) { return (0.5*base*height); } double Area(double radius) { return (pi*radius*radius); } The Output

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

20 Object Oriented C++ Class #include class CCircle { public: CCircle(int r); void SetRadius(int r); void DisplayArea(void); ~CCircle(); private: float CalculateArea(void); int m_radius; int m_color; }; CCircle::CCircle(int r) { m_radius = r; } CCircle::~CCircle() {} void CCircle::DisplayArea(void) { float fArea; fArea = CalculateArea(); cout << "The Arae of the circle : " << fArea << "\n"; } float CCircle::CalculateArea(void) { float f; f = (float) (3.14 * m_radius * m_radius); return f; } 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 Simple example of defining object and class Programming Example Programming Example Programming Example Programming Example Overloading Overloading Programming Example Programming Example Programming Example Programming Example Inheritance Inheritance Programming Example Programming Example Programming Example Programming Example Templates Templates Programming Example Programming Example Programming Example 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 << “Out of memory << endl; cerr << “Out of memory << endl; exit(1); } exit(1); }

24 Delete delete y; //free the memory allocated by *y delete [] x // free the one dimensional array


Download ppt "EEM 480 Algorithms and Complexity by Assist. Prof. Dr. Emin Germen."

Similar presentations


Ads by Google