1 CPSC2620 Advanced Programming Spring 2003 Instructor: Dr. Shahadat Hossain 2 Today s Agenda Administrative Matters Course Information Introduction to Programming Techniques 3 Course Assessment Lectures: MWF 12:00 noon - 12:50 p.m. (Section A) 3:00 p.m. - 3:50 p.m. (Section B) Weekly Labs (Monday) and Tutorials (Wednesday) Tutorials begin this week; no labs this week Approximately 8 homework assignments Two quiz tests (in January and March) One midterm on February 15 Final exam 4 Course Material Lecture Notes: These slides will be posted on the course web page http://classes.uleth.ca/200301/cpsc2620a/ Assignments: Solutions will be posted after due date Text: Problem Solving With C++ by Walter Savitch 5 Grading Method Assignments: 25% of course grade Quiz tests: 5% each Midterm: 25% Final: 40% 6 Out of Class Help Academic Assistant: Rex Forsyth Instructor: - Office Hours: MWF 4:00 p.m. - 5:00 p.m or by appointment - Office Location: C540 University Hall Labs and Tutorials 7 Course Outline Introduction to Object-oriented design and standard libraries - vector, string - iostream library 1
Program performance, running time estimation Recursion, sorting, searching Designing and implementing classes - Member functions, constructors, destructors - Function and operator overloading 8 Course Outline (contd.) Storage types, dynamic memory management, pointers Simple data structures - Containers and iterators - Linked lists, stacks, queues, and binary trees Inheritance and polymorphism - Derived classes, abstract classes, pure virtual functions 9 What is cs2620? cs2620 is an introduction to programming and problem-solving using Object-Oriented (OO) techniques Assumes completion of cs1620 (or equivalent) and familiarity of C++ language syntax 10 Bits of advice to succeed in cs2620 Start assignments early. Document your code. Design before implementing Test each function/method code separately for correctness before you plug them in the main code Go back and review - practice what you have learned - mistakes will happen but you will learn from them You will be tested on the concepts you have learned 11 2
Questions? 12 Introduction to Programming Techniques Procedural Technique - Divide problem into sequence of subproblems to be solved - Program is sequence of procedure calls - Languages: C, Pascal, Fortran, COBOL, etc Procedural Design - identify simple tasks that can be programmed easily - break tasks into subtasks - write small useful routines and compose into larger procedures 13 Problems in Procedural Programs Large program built from many small procedures Not clear which does what to what data No enforced control over access to data Difficult to fix bugs, modify, and use procedures in other programs 14 Modular Programming Group together related procedures into units called Modules Modules can have their own data that they manipulate Example: Modula Problems: No enforced control to access of data 15 Object-Oriented Programming Think of building program from parts like building a machine! Parts are objects that interact to solve problem Define classes of objects that can be reused Think in terms of objects and their interactions Languages: C++, Java, Eiffel, Smalltalk, etc 16 Why Object-Oriented? Object interactions are defined by methods, which are just procedures (functions in C++) The complete program still is a sequences of procedure calls, but acting on objects (not just on some data structures) 3
Procedures are organized around objects Data access is easier to understand Data access is easier to control 17 Generalization in OOP Two approaches to defining classes in terms of others inheritance : inherit properties of other classes parameterized classes (templates) class defined in terms of parameter classes Design patterns are solutions to common design problems 18 OO Design Identify objects and classes Strategies: abstraction and separation Identify how objects interact in system Strategies: composition Identify hierarchies of related classes Strategies: generalization 19 OO Design Strategies Abstraction modeling essential properties Separation treat what and how independently Composition building complex structures from simpler ones Generalization identifying common elements 20 Example: Bank Administration Objects to be modeled - account - employee - client 21 How do represent an Account? Attributes: - account number - owner name - balance - interest YTD 4
(?) Behavior: - make deposit - withdraw - get balance - transfer - (?) 22 A bankaccount Class class bankaccount { public: void makedeposit(double amount); void withdraw(double amount); bool transfer(bankaccount &to, double amount); double getbalance() const; private: double balance; double interestytd; string ownername; int accountnumber; }; 23 Next Lecture Software Libraries: A very brief introduction to C++ Standard Template Library (STL) - string class - vector class Reading: Chapter 11 from the textbook Input/Output in C++ (also done in the tutorial) Basic stream input/output Reading: Chapter 5 from the textbook 5