chapter 12: programming in the large by: suraya alias 1-1

Download Chapter 12: Programming in the Large By: Suraya Alias 1-1

If you can't read please download the document

Upload: shon-beasley

Post on 17-Jan-2018

233 views

Category:

Documents


3 download

DESCRIPTION

13.1 Using Abstraction to Manage Complexity Procedural Abstraction – Separation of what a function does from the details of how the function accomplished its purposes. – Example ; fopen(), sqrt() function Data Abstraction – Separation of the logical view of a data object (what is stored) from the physical view (how the information is stored) – Example ; data type double Information hiding – Protecting the implementation details of lower-level module from direct access by a higher-level module – Example ; only access data object through operators Encapsulate – Packaging as a unit a data objects and its operator 1-3

TRANSCRIPT

Chapter 12: Programming in the Large By: Suraya Alias 1-1 Figure 13.1 Preparing a Program for Execution 1-2 13.1 Using Abstraction to Manage Complexity Procedural Abstraction Separation of what a function does from the details of how the function accomplished its purposes. Example ; fopen(), sqrt() function Data Abstraction Separation of the logical view of a data object (what is stored) from the physical view (how the information is stored) Example ; data type double Information hiding Protecting the implementation details of lower-level module from direct access by a higher-level module Example ; only access data object through operators Encapsulate Packaging as a unit a data objects and its operator 1-3 13.2 Personal Libraries : Header Files Header file Has a.h extension, example header.h Contains the interface information about a library needed by a compiler to translate a program system Use the #include preprocessor directive 1-4 Figure 13.2 Header File planet.h for Personal Library with Data Type and Associated Functions 1-5 Figure 13.2 Header File planet.h for Personal Library with Data Type and Associated Functions 1-6 Figure 13.3 Portion of Program That Uses Functions from a Personal Library 1-7 13.2 Personal Libraries : Implementation Files Implementation file File containing the C source code of a library function and other info Example; if we create a personal library header.h we can include it in hello.c 1-8 Figure 13.4 Implementation File planet.c Containing Library with Planet Data Type and Operators 1-9 Figure 13.4 Implementation File planet.c Containing Library with Planet Data Type and Operators (contd) 1-10 13.4 Storage Classes 1.Auto Default storage class of function parameters and local variables 2.Extern Function names are of storage class extern It will be available to the linker 3.Global variable A variable that may be accessed by many functions in a program 4.Static Storage class of variables allocated only once, prior to program execution 5.Register Storage class of automatic variables that the programmer would like to have stored in register 1-11 Figure 13.5 Storage Classes auto and extern as Previously Seen 1-12 Figure 13.5 Storage Classes auto and extern as Previously Seen (contd) 1-13 Figure 13.6 Declaration of a Global Variable 1-14 In eg1.c, the declaration allocates space for global_var_x In eg2.c, the keyword extern allocates no memory. It only informs the compiler Figure 13.7 Use of Variables of Storage Class extern 1-15 13.5 Modifying Functions for inclusion in a Library The exit() function allows premature termination of program execution The break function can be used to terminate a nested loop 1-16 Figure 13.9 Conditional Compilation of Tracing printf Calls 1-17 13.6 Conditional compilation Figure Conditional Compilation of Tracing printf Calls 1-18 Figure Header File That Protects Itself from Effects of Duplicate Inclusion 1-19 Figure Header File That Protects Itself from Effects of Duplicate Inclusion (contd) 1-20 Figure Header File That Protects Itself from Effects of Duplicate Inclusion (contd) 1-21 Figure File Backup Using Arguments to Function main 1-22 13.7 Arguments to Function Main Command line arguments 1-23 13.7 Defining Macros with Parameters Macro Facility for naming a commonly used statement or operation Macro expansion Process of replacing a macro call by its meaning Use of parentheses Extending macro over two or more lines 1-24 Figure Program Using a Macro with Formal Parameters 1-25 Figure Macro Expansion of Second Macro Call of Program in Fig Figure Macro Calls Showing Importance of Parentheses in Macro Body 1-27 Figure Macro Calls Showing Importance of Parentheses in Macro Body (contd) 1-28 Figure Macro Expansions of Macro Calls from Fig Chapter 13 Dynamic data Structures 1-30 Pointers Dynamic data structures A structure that can expand and contract as a program executes Nodes Dynamically allocated structures that are linked together to form a composite structure 1-31 Pointers Pointers as function parameters long_division(40, 3, &quot, &rem) Pointers representing arrays and strings char *n or char n[] Pointers to structures An array of structures was represented as a pointer to the first array element Refer table 1-33 Figure 14.1 Comparison of Pointer and Nonpointer Variables 1-34 Figure 14.2 Function with Pointers as Output Parameters