Summary of CS 271
An old old old summary of topics in CS 271…
Plain C
- functions and procedures (unique names)
- global and local variables (also static)
- printf() and scanf() – not typesafe
- data representation limits (ranges, also accuracy for FP)
- Pointers!
- malloc() and free() – not typesafe
- structs and linked structures
- macros and conditional compilation (#define, #ifdef..#endif)
- using C effectively requires using the C Standard Library effectively
C++
- function overloading (unique parameter lists)
- default arguments
- new and delete (and array forms)
- iostreams (partially covered) – typesafe
- Classes!
- Encapsulation: data and methods in class (abstract data type) plus ability to declare private data and methods
- Inheritance: reusing functionality by implicit inclusion (subclass and base or super class); subclasses can override behavior if the base class declares the methods virtual
- Polymorphism: “run-time” selection of proper behavior for type (dynamic resolution of virtual functions in classes)
- static class methods – sort of like a module of functions
Design, Tools, and UML
- file layout - header files, source files
- C++: one header and one source file per class (use #ifdef in header file)
- compilation and linking process: compiling to executable or to object code
- public and private - all data private (use getter and setter methods)
- refactoring
- testing
- noun/verb analysis of problem description
- UML class diagrams
- make
- gdb
- building a library
C++ vs. Java
- C++ has programmer-managed memory - i.e., new and delete.
- Java has garbage collection - i.e., only new, no delete.
- C++ has multiple inheritance - a class can have more than 1 base class
- Java has single inheritance (one base class) plus interfaces
- A C++ pure virtual base class is like a Java interface - no method implementations or data members, just method interface declarations
- C++ allows non-OO features – plain C functions, global data, etc.
- Java only has classes and objects – even main() must be in a class
- Both allow static class methods and data
- C++ has operator overloading. Java does not (although is discussed)
- C++ has templates. Java does not (but will someday).