Division of Mathematics and Computer Science Maryville College
Outline Course Overview 1 Course Overview 2 3 4
Preliminaries Course Overview Required Materials Big C++ 2nd Edition by Cay Horstmann An Account on smc.cs.maryvillecollege.edu Catalog Description A continuation of Computer Science 111 with emphasis on advanced programming features. Laboratory work supplements and expands lecture topics and offers supervised practice using programming.
Recommended Supplementary Text The C++ Programming Language 4th Edition by Bjarne Stroustrup Written by the creator of C++ Serves as a Good Reference Very in-depth Explanations of The Language This should be on the bookshelf of all serious C++ programmers.
Course Goals Gain an advanced understanding of Object Oriented Programming. Learn to use Object Oriented Analysis and Design to build large complex programs. Gain a preliminary understanding of low level programming concepts, especially memory addressing. Increase your knowledge of using and programming the UNIX operating system. Hone your knowledge of programming tools like make, g++, and gdb. Learn new tools, like rcs.
Grading Course Overview Grading Labs 15% Programming Assignments 50% Exams 35%
Summary of Classroom Expectations Show up for class. Don t cheat. Attempt all the work. Ask lots of questions. Late assignments will generally not be accepted. Don t Panic!
Outline of Major Topics I. Object Oriented Programming a. Classes and Objects b. Inheritance and Polymorphism c. Overloaded Operators and Functions d. Object Oriented Analysis and Design II. Problem Solving Techniques a. Recursion b. Backtracking III. Tools and Techniques a. gdb b. UNIX System API c. Exceptions
Software Development Life Cycle Programming Is: Expensive Very Complex Critical The Ninety-Ninety Rule The first 90 percent of the code accounts for the first 90 percent of the development time. The remaining 10 percent of the code accounts for the other 90 percent of the development time. Tom Cargill, Bell Labs Image Source: wikipedia.org
Coping with Complexity The Main Challenge is Dealing With Complexity Analyze Big Tasks Decompose Big Tasks Encode Tasks into Computer Code
Coping with Customers Real world customers are not very tech savvy. Often, programs perform tasks outside of the programmer s expertise. Many iterations are needed to capture requirements. Even then, requirements are typically vague!
What Makes Programming Difficult Complexity Vague and Underdeveloped Requirements Time Pressure One-Off Nature of Programs
Programming Paradigms Programming paradigms represent ways of thinking and methods of decomposition. Imperative Programming All statements are direct commands which alter the program s state. (ex. Assembly and ALGOL) Procedural Programming Programs are decomposed into sub-routines. (ex. C and Pascal ) Functional Programming Computation is represented as mathematical functions. (ex. LISP and Erlang) Object Oriented Programming Programs are decomposed into objects. (ex. C++ and C#)
Effective Use of a Programming Language General Tips for Programming Language Use A programming language is a formal representation of ideas. Think first and then code! Use a language that is well suited to the task at hand. Learn the idioms of your language. Always use the language to express, rather than obscure, your intentions!
Objects and Classes Object An entity with state and behavior. (Instance of Classes) Variables Concrete Objects Class A collection of objects with identical attributes and behaviors. (Definition of Objects) Member Functions Member Variables Abstract Entity
Parts of Speech and OOP Nouns Objects and Classes Verbs Member Functions Adjectives Member Variables
An OOP Translation Example 1 Write some sentences describing the robot and its state. 2 Write some sentences describing what the robot can do. 3 Sketch out what a robot class may look like.
Four Major Principles of Object Oriented Programming Encapsulation Attributes and state are contained within objects and access to these attributes are restricted. Abstraction The inner workings of the objects are hidden. Inheritance Objects types can be derived from, and extend, other object types. (Is-A relationship) Polymorphism Objects can be referenced by different types, and they still behave correctly when treated as inherited types.
Goals for Effective Object Oriented Programming Your programs should be clear in intention. Objects should be cohesive. Objects should not be tightly coupled with other objects.
Class Declaration class name { public: //public methods protected: //protected variables and methods private: //private variables and methods };
Access Modifiers public Accessible to code inside and outside of the class. Methods Constructors Destructor protected Accessible to code within the class and sub-classes. (A big part of inheritance.) Variables (with great care) Methods private Accessible only to code within the class. Variables Methods
Constructors and Destructors Constructors Initializer for a class Can be overloaded Declared with same name as an object: name(); No return type Destructor Cleans up after an object. Used frequently with dynamic memory. Named: name();
Member Initialization Lists Member initialization lists can be used when simply copying values from constructor arguments. They are an absolute must when working with references! name(int x, int y) : x(x), y(y) { //constructor code }
Constructor and Destructors Best Practices Unless you really know what you are doing, constructors should be public. You should provide at least: 1 No-Argument constructor: name(); A copy constructor: name(name &c); If initial conditions make sense, you should have a constructor which allows them to be set. If you use any dynamic memory, you must create a destructor.
Putting it All Together Let s implement our robot class!