Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Language C++ Xulong Peng CSC415 Programming Languages.

Similar presentations


Presentation on theme: "Programming Language C++ Xulong Peng CSC415 Programming Languages."— Presentation transcript:

1 Programming Language C++ Xulong Peng CSC415 Programming Languages

2 Outline History Design, Syntax and Semantics Evaluation Code demonstration

3 History of C++ C++ was developed from C Written by Dr. Bjarne Stroustrup from Bell Labs in 1979 “C and classes” and then named C++ Standardized by ISO in 1998.  C++98, C++03, C++11 and C++14 New features: OOP, addition safety, operator overloading, templates, exception handling

4 Name, Binding and Scopes Name(Identifiers) Letter, digits and underscore case-sensitive Keywords(i.e. int, while, using, for, namespace) Binding Static binding and dynamic binding C++ supports OOP and implements dynamic binding

5 Name, Binding and Scopes (continues) C++’s scopes  Local scope  Class scope  Namespace scope  Global scope

6 Data Type (C++ is a typed language) numeric types (integer, floating and double) Boolean (true and false) character void type pointer (*pt) array User-defined (struct, enum, class)

7 Data Type Conversion Narrowing conversion (double -> float) Widening conversion (int -> float) Implicit or explicit conversion

8 Expression and Assignment Statements C++ provides a rich set of operators  unary, binary and ternary operators ++, --, +, - and ? :  support % operator (only apply to integer)  relational operators operator associativity and precedence

9 Associativity and Precedence (source: Deitel and Deitel, 2012)

10 Assignment Statements Expression int count = 10; Compound statements One or more individual statements in {} Control statements If …else, loop and switch

11 Control Structure Sequence Statement Selection Statement Iterative (or loop) Statement C++ provides break, continue, goto and return to alter the flow of control

12 Selection Statements Selection statements offer a choice between two or more execution.  If statement  If…else statement  Switch statement

13 Repetition Statements for (counter init; condition; counter update) While (condition expression){statements} do { statements to execute} while (condition); C++11 also provide a rang-based for loop http://en.cppreference.com/w/cpp/language/range-for

14 Functions C++ uses prototype as a function declaration Function definition: typeName functionName (parameter list) { statements; return;}

15 Functions C++ parameters can be passed by: value, reference or const-reference Example: double avg (const vector & arr, int n, bool & errorFlag); An inline function to speed up execution Function overloading template

16 C++’s OOP features Encapsulation  Supports build-in data type and user-define ADT(class) Inheritance  Provides single and multiple inheritance Polymorphism  Supports dynamic binding

17 Exception Handling try … catch block In C++, an exception is either a user or a library defined class Must be explicitly raised using throw

18 Concurrency Original C++ standard only supports single thread programming C++11 adds concurrency in the form of C++11 model C++11 uses a thread library for starting and managing threads

19 Evaluation of C++ Readability  C++ is a large language which complicates its readability  User defined operator overloading (aids and harms)  Supports numeric as Boolean expression affects readability.  Case sensitive, good control structures, more flexible iteration statements helps readability  Use of OOP improves its readability and writability

20 Evaluation of C++ Writability  Its writability is highly associated with its readability  C++ has rich data type and supports abstraction improves writability  Efficient expression helps writability  Flexible and efficient control statements  C++’s template improves writability

21 Evaluation of C++ Reliability  It is reliable if used carefully  flexibility and efficiency vs. reliability (not strongly typed and does not have strict type checking)  The use of pointer type is very flexible but could cause dangling pointer and memory leaking  Abstraction and information hiding improves its reliability  Exception handling improves its reliability

22 Evaluation of C++ Cost  Hard to learn as it is a large language.  The cost of writing C++ depends on applications. Generally, it is easy to write as syntax is very straightforward.  Backward compatible with C (low cost for C programmer)  Cheaper or free IDE reduces cost for training  Inexpensive compliers decrease the cost of compilation and execution  Flexibility and efficiency speed up execution  The cost on reliability and maintenance with trade-offs.

23 Some Code Examples

24 Shape 2 D 3 D Circle Square Sphere Cube

25 Q & A


Download ppt "Programming Language C++ Xulong Peng CSC415 Programming Languages."

Similar presentations


Ads by Google