Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.
-
Upload
joshua-hunt -
Category
Documents
-
view
215 -
download
0
Transcript of Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.
![Page 1: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/1.jpg)
Cramming for CS 247
![Page 2: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/2.jpg)
FAQ
• Q: Will you post these slides online?
• A: Yes.
![Page 3: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/3.jpg)
Single ADT Design
![Page 4: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/4.jpg)
02 - Classes in C++
• ADTs, Classes, Objects• Constructor• Destructor• Private vs public• Friends
![Page 5: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/5.jpg)
03 – Design decisions for a single class
• Should we write a constructor?• Should the constructor be explicit?
class Stack{public:
explicit Stack(int size);};
![Page 6: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/6.jpg)
03 – Design decisions for a single class
• Accessor and Mutatorclass Integer{
int x;public:
void setX(const int x);int getX() const;
};
![Page 7: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/7.jpg)
03 – Design decisions for a single class
• Operator overloadingclass Integer{
int x;public:
Integer operator+ (const Integer &y) const;};
![Page 8: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/8.jpg)
04 – Consts and References
• int *p;• const int *p;• int const *p;• int *const p;• const int *const p;
![Page 9: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/9.jpg)
05 – Copy constructor
• Purpose: Duplicating an existing object
• How copy constructors work• How operator= works• How operator== works
• More design decisions
![Page 10: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/10.jpg)
Multiple ADT Design
![Page 11: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/11.jpg)
06 – Modules
• .h files contain DECLARATIONS• .cpp files contain DEFINITIONS
• The “make” command• Makefile
![Page 12: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/12.jpg)
06 – Modules
• Namespaces• What does “using namespace” std mean?
![Page 13: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/13.jpg)
08 – UML Diagrams
• Visual representation of ADTs
class Integer{int x;
public:void setX(const int x);int getX() const;
}
Integer
- x : int
+ setX(int)+ getX() : int
![Page 14: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/14.jpg)
08 – UML Diagrams• Arrows : navigability
A has a pointer to B
• Numbers : multiplicity
A has 2 instances of B
A B
A B2
![Page 15: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/15.jpg)
08 – UML Diagrams
A and B are related
B is part of A
B is part of A, and B cannot exist without A
A B
A B
A B
![Page 16: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/16.jpg)
09 – Aggregation and Composition
How to code aggregation
and composition
in C++
A B
A B
![Page 17: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/17.jpg)
10 - Inheritance
• Creating new classes based on previous onesclass Animal {public: void walk();};
class Cat : public Animal {public: void purr();};
Animal has 1 function:walk
Cat has 2 functions:purrwalk
![Page 18: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/18.jpg)
11 - Polymorphism
• Allowing objects to take many forms
• Animal *a = new Animal(); //OK• Animal *b = new Cat(); //Also OK
• Function override, virtual functions
![Page 19: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/19.jpg)
12 – Design principles
• What CAN we inherit?• What SHOULD we inherit?• HOW should we inherit?
• Inheritance vs Composition
![Page 20: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/20.jpg)
Program Maintenance
![Page 21: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/21.jpg)
07 - Testing
• What is unit testing?• System vs Integration testing• What is boundary testing?• Black box vs white box testing
• Assert function
![Page 22: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/22.jpg)
15 - Debugging
• Using the GDB debugger• Debugger commands
![Page 23: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/23.jpg)
14 - Exceptions
• try and catch syntax in C++
• More design principles– When SHOULD we try and catch?– When SHOULDN’T we try and catch?
![Page 24: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/24.jpg)
Design Patterns
![Page 25: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/25.jpg)
16 – 19 - Design Patterns
• An algorithm is a standard step-by-step routine for solving a problem (e.g. quicksort)
• A data structure is a standard organization of data in memory (e.g. linked list)
• A design pattern is a standard object-oriented architectural layout (e.g. strategy pattern)
![Page 26: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/26.jpg)
16 – 19 - Design Patterns
• Strategy Pattern
SortStrategysort()
Quicksortsort()
Mergesortsort()
SortedArraysort()
Element*
![Page 27: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/27.jpg)
16 – 19 - Design Patterns
• Strategy Pattern• Template Method• Factory Method• Observer Pattern• Model View Controller• Composite Pattern• Iterator Pattern• Decorator Pattern
![Page 28: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/28.jpg)
STL
![Page 29: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/29.jpg)
20 - Templates
• Classes that support multiple data types template <typename T> class Stack{ … };• Stack <int> integerStack;• Stack <float> floatStack;
![Page 30: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/30.jpg)
21 – Generic Algorithms in STL
• #include <algorithm>– copy– find
• #include <iterator>• #include <functional>
![Page 31: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.](https://reader036.fdocuments.in/reader036/viewer/2022062500/5697bfee1a28abf838cb93f3/html5/thumbnails/31.jpg)
21 – Generic Contains in STL
• #include <vector>• #include <deque>• #include <list>• #include <set>• #include <map>
• More STL iterators