C++ Programing - Session 1: Introduction - FPT University

ppt 31 trang hoanguyen 4620
Bạn đang xem 20 trang mẫu của tài liệu "C++ Programing - Session 1: Introduction - FPT University", để tải tài liệu gốc về máy bạn click vào nút DOWNLOAD ở trên

Tài liệu đính kèm:

  • pptc_programing_sesion_1_introduction_fpt_university.ppt

Nội dung text: C++ Programing - Session 1: Introduction - FPT University

  1. Session 1-Introduction • A Language for Complex Applications • Object Terminology • Compiling Modular Programs Session 1-Introduction 1/31
  2. Objectives • A Language for Complex Applications – Complexity – Three Languages – A First Example • Object Terminology – Abstraction – Encapsulation – Hierarchy – Modularity • Compiling Modular Programs – A demonstration Session 1-Introduction 2/31
  3. A Language for Complex Applications • Many software applications are complex. The underlying problem domain is often quite intricate and detailed. • For an application to be practical and usable, it must represent some of the complexity of the problem domain. Session 1-Introduction 3/31
  4. Complexity(1) • We create a software solution by extracting the most important features of the problem domain. • There are 2 ways to identify the most important features: – into activities (distinct algorithms) – into things (distinct objects) • The two approaches are not mutually exclusive. We start with one approach and use its results as the basis for the other. This decomposition is an iterative process. Session 1-Introduction 4/31
  5. Complexity(2) • Consider an ordering system for a bookstore. The bookstore places orders with different publishers. Session 1-Introduction 5/31
  6. Complexity(3) • From the above chart, we identify an Order and a Special Order as the important objects. • The emphasis in this diagram is on the objects rather than the functional activities performed on them. The functional activities become part of the description of the objects themselves. Session 1-Introduction 6/31
  7. Popularity of programming languages Session 1-Introduction 7/31
  8. Three Languages(1) • C++ is one of the more popular third- generation languages. • Third-generation languages are typically algorithmic. That is, they let us describe fully the process that leads towards a result. They can be: – non object-oriented, – object-oriented, or – hybrid. Session 1-Introduction 8/31
  9. Three Languages(2) • C is non object-oriented. • Java is object-oriented. • C++ is hybrid C++ contains almost all of C as a subset: Session 1-Introduction 9/31
  10. Why Study C++ before Java? C++ has several advantages with respect to Java. C++ is • a multi-paradigm language – algorithmic (can focus on distinct activities) – object-oriented (can focus on distinct objects) • a superset of C • realistic, efficient and flexible enough for demanding projects – Windows operating system – Game Programming - Direct X or OpenGL • clean enough for successful teaching of the basic concepts of object-oriented programming • comprehensive enough for teaching the advanced concepts Session 1-Introduction 10/31
  11. History of C++ • Bjarne Stroustrup developed C++ at Bell Labs (AT&T Research Labs) and released it officially in October 1985. He had called the experimental 1979 version C with Classes. The name C++ arose around 1983: the ++ stands for the C post-fix increment operator. Stroustrup's web site(C++ Glossary ): Session 1-Introduction 11/31
  12. Interview with Bjarne Stroustrup • “It is important to remember that a programming language is only a tool. Once you master the basic concepts of a language, such as C++, it is far more important to gain a good understanding of an application area and of the problem you are trying to solve than it is to study the minute technical details of C++” Session 1-Introduction 12/31
  13. Object Terminology(1) • In 1956, Professor Miller, recently of Princeton University, suggested that most of us can only comprehend about seven chunks of information at a time, plus or minus two. We learn to identify chunks of information at an early age. In software development, we refer to such chunks as objects Session 1-Introduction 13/31
  14. Object Terminology(2) • There are four fundamental concepts associated with the chunking of information (Booch 1994): – abstraction – encapsulation – hierarchy – modularity Session 1-Introduction 14/31
  15. Abstraction(1) • Abstraction reduces the complexity of a problem domain. • Each object is an abstraction of one important aspect of the problem domain. • The objects that make up the solution ignore the non-essential features of the problem. Session 1-Introduction 15/31
  16. Abstraction(2) • Each object has a crisp boundary that distinguishes the object from all other objects. • Each object has integrity: it can only behave in ways that are appropriate to itself. – An ear cannot see, an eye cannot listen and a mouth cannot smell. A horse cannot bark and a dog cannot croak. Session 1-Introduction 16/31
  17. Abstraction(3) For example, • The cout object is an abstraction of an output device, which may be a monitor or a printer. The device itself is quite complex, yet the abstraction is simple. • The cin object is an abstraction of an input device, which may be a keyboard or some tablet. The device itself is quite complex, yet the abstraction that represents it is simple. Session 1-Introduction 17/31
  18. Abstraction-Classes(1) • An application may contain many objects. • Objects that have similar features and respond in a similar manner may share a common structure. A description of this common structure is called a class. A class describes the structure of the data held by an object and the behavior of the object. Session 1-Introduction 18/31
  19. Abstraction-Classes(2) • An object may have values that distinguish it from another object in a class. • The values stored in each object may vary from object to object, but the set of variables and their data types are common. • Each object is an instance of the class. The terms object and instance are interchangeable. Session 1-Introduction 19/31
  20. Classes vs. Objects Session 1-Introduction 20/31
  21. Encapsulation(1) • Encapsulation separates the implementation details of an object from its external appearance. • Encapsulation focuses on the interior of an object, combining the data that describes the object's state and the algorithms that define its behavior. Session 1-Introduction 21/31
  22. Encapsulation(2) • A well-encapsulated object has all of its implementation details hidden within the object. • If an object is well-encapsulated, a programmer can change the object's internal structure without introducing any changes to the software that uses the object. Session 1-Introduction 22/31
  23. Hierarchy • Some of the objects in an application may be hierarchically related to one another. The hierarchy may be one of: – aggregation, or – shared structure and behavior • Aggregation describes a "has a" relationship between objects. The parent object "has a" child object. The two objects need not share a common structure. • Shared structure and behavior entails an "is a kind of" relationship. This appears as a hierarchy of classes. One class "is a kind of" another class Session 1-Introduction 23/31
  24. Modularity(1) • A module is a physical unit of a program. • Each module is a highly cohesive unit. • The set of modules is loosely coupled Session 1-Introduction 24/31
  25. Modularity(2) A C++ module typically consists of two files: – a header file (.h) – an implementation file (.cpp) • The header file contains the declarations of the identifiers used in the module, but does not contain any executable statements. • The implementation file contains all of the function definitions. Session 1-Introduction 25/31
  26. Modularity(3) • C++ compilers compile each module independently of other modules in a programming solution. Session 1-Introduction 26/31
  27. Object Terminology-Summary • The four fundamental concepts applied in object- oriented software development are: Abstraction: focuses on the external view of an object, identifying the essential features that distinguish it from all other objects. Encapsulation: focuses on the implementation of each object; identifying the data that describes its state and developing the algorithms that describe its behavior. Hierarchy: ranks and orders objects amongst other objects. Aggregation defines object-wise containment, while inheritance defines class-wise ranking. Modularity: identifies physical components of a solution. Session 1-Introduction 27/31
  28. Compiling Modular Programs(1) Session 1-Introduction 28/31
  29. Compiling Modular Programs(2) • The C++ compiler is a set of programs translates source code into the executable machine language code in three separate stages: – the pre-processor inserts all externally declared prototypes and substitutes all #define strings to create each source module, – the compiler proper translates each source module into a binary module, and – the linker assembles all binary modules, resolves all external references, and appends code from binary libraries to create a single executable file. Session 1-Introduction 29/31
  30. Compiling Modular Programs(3) • A demonstration Session 1-Introduction 30/31
  31. Summary • A Language for Complex Applications – Complexity – Three Languages – A First Example • Object Terminology – Abstraction – Encapsulation – Hierarchy – Modularity • Compiling Modular Programs – A demonstration Q&A Session 1-Introduction 31/31