CIT241 Prerequisite Knowledge ◦ Variables ◦ Operators ◦ C++ Syntax ◦ Program Structure ◦ Classes Basic Structure of a class Concept of Data Hiding Concept of Inheritance Concept of Polymorphism
CIT241 Objectives Study of data structures and algorithms Use of STL ◦ Containers ◦ Iterators ◦ Algorithms Searching Sorting Other Use of C++11 new instructions ◦ Auto, Array, lambda, intelligent pointers, tuples
Why C++ Where is it being used ◦ Real-time systems Embedded products ◦ Building tools OSs Compilers Tools for developers / designers ◦ Games Reasons ◦ Speed ◦ Closeness to machine architecture (Native) See
Programming Languages Java ◦ Write once, run anywhere (there’s a JVM) ◦ Huge framework ◦ Garbage collection.NET – C# and VB ◦ Write once, run anywhere (there’s Windows) ◦ Huge framework ◦ Separation of concerns – visual designers / developers ◦ Garbage collection C++ ◦ Compilers for most machines ◦ Differences – machine architecture, OS services ◦ Stack and Heap ◦ Automatic deallocation using smart pointers ◦ Commercial libraries provide good amount of frameworks
Software Design Software Life Cycle ◦ Analysis – the What ◦ Design – the How ◦ Implementation – the Code ◦ Testing and debugging – the Quality
Survey from CodeProject
Design Methodologies Structured design ◦ Waterfall methodology ◦ Data Flow Diagrams, Structure Charts, HIPO diagrams, Pseudo Code ◦ Functional decomposition Object-Oriented design ◦ Iterative and Incremental design ◦ UML – use cases, class diagrams, sequence charts, state diagrams, packages ◦ Object decomposition
Agile Methodologies Do only what is necessary ◦ Capture requirements at a high level ◦ Develop small, incremental releases and iterate Write tests before code Refactor code Pair programming
Algorithms More than one approach Deals with trade-offs ◦ Memory space ◦ Processing time ◦ Simplicity of code Study of Data Structures and Algorithms ◦ Containers ◦ Functions ◦ Searching and Sorting
Big-O Notation Efficiency of an algorithm Interested in asymptotic behavior ◦ Especially as it approaches infinity Measure number of operations How does number of operations grow as number of elements grow
Growth Rates nlog 2 nn log 2 nn2n2 2n2n , ,294,967,296
Searching Linear search Binary search Cost of two methods ◦ Frequency of adding new element ◦ Frequency of searching for an element
Classes and Objects Class represents a type of object ◦ Extensible programming language ◦ Encapsulates state and behavior ◦ Reusable ◦ Classes used to model problem Objects are the instances ◦ Data members represent current state of a single object ◦ Behavior is shared by all objects of a class
Determining Classes Problem Domain ◦ Vision ◦ Use cases or scenarios Nouns as potential classes CRC cards ◦ Responsibility Sequence diagrams ◦ Actor interacting with Interface class(es) ◦ Interface class interacting with domain classes
Relationships between Classes Has a – composition Is a – inheritance Uses – association Relationships have multiplicity ◦ 1 – 1 ◦ 1 – Many ◦ Many – Many ◦ Many(s) in model most often held in container
Class Data members ◦ Fields Static Field Member functions ◦ Accessors and mutators Standard C++ does not support properties Implements get and set functions ◦ Static member functions Accessibility ◦ Private ◦ Protected ◦ Public
Class Methods Constructors ◦ Constructors with default parameters Destructor Public Private Built-in Operations ◦ member access (.) or (->) for dynamic objects ◦ assignment (=)
Patterns Model/View/Controller - Separation of concerns ◦ Data part ◦ Presentation part ◦ Control part – handle requests / events Data Persistence ◦ Separate data from storing/retrieving of data
Date Class How is it going to be used? Methods ◦ Constructors ◦ Destructor? ◦ Set/Get functions ◦ Calculation functions ◦ Formatting functions
Vectors Vector is a dynamic array ◦ Can grow or shrink as needed Vector is part of STL, hence uses template vector intvect; vector studentvect(24); void push_back(const T& newelem); T& operator[ ](size_type n); const T& operator[ ](size_type n) const; T& at(size_type n); const T& at(size_type n) const;
Accessing the elements Regular for loop, range for loop For loop for (int ndx = 0; ndx < vint.size(); ++ndx) { cout << vint[ndx] << endl; } for (auto iter = vint.begin(); iter != vint.end(); ++iter) { cout << *it << endl; } Range for loop for (int curr : vint) { cout << curr << endl; }
Project 1 Simple ToDoList Application Need to capture an activity that has a description and a planned completion date. Need to have the ability to add an increment to the date for an activity. The increment can be both negative and positive. We would also like to capture the difference between two date values. We need to record the actual completion date element for an activity as well as its planned completion date value.