20070110 chap13 Chapter 13 Programming in the Large.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Chapter 7: User-Defined Functions II
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
Chapter 5 C Functions The best way to develop and maintain a large program is to divide it into several smaller program modules, each of which is more.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Structure of a C program
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
FunctionsFunctions Systems Programming. Systems Programming: Functions 2 Functions   Simple Function Example   Function Prototype and Declaration.
Using Abstraction to Manage Complexity Abstraction: procedural abstraction & data abstraction. Procedural abstraction=> function development should separate.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
CS 201 Functions Debzani Deb.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Methods of variable creation Global variable –declared very early stage –available at all times from anywhere –created at the start of the program, and.
Guide To UNIX Using Linux Third Edition
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
FunctionsFunctions Systems Programming Concepts. Functions   Simple Function Example   Function Prototype and Declaration   Math Library Functions.
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
C++ for Engineers and Scientists Third Edition
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
Copyright 2001 Oxford Consulting, Ltd1 January Storage Classes, Scope and Linkage Overview Focus is on the structure of a C++ program with –Multiple.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Chapter 6: Modularity Using Functions. In this chapter, you will learn about: – Function and parameter declarations – Returning a single value – Returning.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
 2007 Pearson Education, Inc. All rights reserved C Functions.
Programming With C.
Chapter 6: User-Defined Functions
Chapter 13 Programming in the Large Dr. Jiung-yao Huang Dept. Comm. Eng. Nat. Chung Cheng Univ. TA: 鄭筱親 陳昱豪.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 13: Programming in the Large Problem Solving & Program Design.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Learners Support Publications Classes and Objects.
 2007 Pearson Education, Inc. All rights reserved C Functions -Continue…-
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
ECE 103 Engineering Programming Chapter 36 C Storage Classes Herbert G. Mayer, PSU CS Status 8/4/2014 Initial content copied verbatim from ECE 103 material.
Dale Roberts CSCI 230 Functions Scope, Parameter Passing, Storage Specifiers Department of Computer and Information Science, School of Science, IUPUI Dale.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
#include using namespace std; // Declare a function. void check(int, double, double); int main() { check(1, 2.3, 4.56); check(7, 8.9, 10.11); } void check(int.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
A FIRST BOOK OF C++ CHAPTER 6 MODULARITY USING FUNCTIONS.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Brief Edition Chapter 6 Functions.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Functions  A Function is a self contained block of one or more statements or a sub program which is designed for a particular task is called functions.
Chapter 12: Programming in the Large By: Suraya Alias 1-1.
CSci 162 Lecture 8 Martin van Bommel. Large-scale Programming Up to now we have been writing relatively short programs to solve simple problem Want to.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
2Object-Oriented Program Development Using C++ 3 Function Declarations and Definitions Analogize functions to methods –Share same basic features –Unlike.
CHAPTER 8 Scope, Lifetime, and More on Functions.
Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
Building Programs from Existing Information Solutions for programs often can be developed from previously solved problems. Data requirements and solution.
Revisiting building. Preprocessing + Compiling 2 Creates an object file for each code file (.c ->.o) Each.o file contains code of the functions and structs.
1 Chapter 8 Scope, Lifetime, and More on Functions CS185/09 - Introduction to Programming Caldwell College.
Unit 10 Code Reuse. Key Concepts Abstraction Header files Implementation files Storage classes Exit function Conditional compilation Command-line arguments.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
User-Written Functions
Chapter 6 CS 3370 – C++ Functions.
CISC105 – General Computer Science
Chapter 3: Using Methods, Classes, and Objects
Chapter 4: Writing Classes
User-Defined Functions
Chapter 5 - Functions Outline 5.1 Introduction
Scope, Parameter Passing, Storage Specifiers
Introduction to Classes and Objects
Classes and Objects.
Presentation transcript:

chap13 Chapter 13 Programming in the Large

chap13 2 Objectives Difficulties of Developing Large Software Systems Reduce the complexity of development and maintenance. Flexible Macros Storage classes of variables and functions Library of reusable code Additional preprocessor directives

chap13 3 Using Abstraction to Manage Complexity (1/2) what Procedural Abstraction: separation of what a function does from how the function accomplishes its purpose. Data Abstraction: separation of the logical view of a data object (what is stored) from the physical view (how the information is stored).

chap13 4 Both enable the designer to make implementation decision in a piecemeal fashion  Information Hiding Information Hiding: protecting the implementation details of a low-level module from direct access by a high-level module. Reusable code Encapsulate a data object and its operators in a personal library. #include Using Abstraction to Manage Complexity (2/2)

chap13 5 Personal Libraries: Header Files Copying the code of the functions into other programs to allow reuse is possible but cumbersome. C permits source code files to be complied separately and then linked prior to loading and execution.

chap13 6

7 Header files header file To create a personal library, we must first make a header file. Header file: text file containing the interface information about a library needed by a complier to translate a program system that used the library or by a person to understand and use the library.

chap13 8 Typical Contents of a Header File A block comment summarizing the library ’ s purpose #define directives naming constant macros Type definitions Block comments stating the purpose of each library function and declarations of the form.

chap13 9 Case Study: planet.h

chap13 10

chap13 11 Notes for Header File Design The common boundary between two separate parts of a solution is called the interface. The header file ’ s purpose is to define the interface between a library and any program that uses the library. Cautionary Notes: the constant macro defined ( PLANET_STRSIZ ) has a long name that begins with the library name. This reduces the conflict likelihood.

chap13 12 Personal Libraries: Implementation Files Implementation File: file containing the C source code of a library ’ s functions and any other information needed for compilation of these functions. The elements of an implementation file: A block comment summarizing the library ’ s purpose. #include directives for this library ’ s header file and for other libraries used by the functions in this library. #define directives naming constant macros used only inside this library. Type definitions used only inside this library. Function definitions including the usual comments.

chap13 13 Implementation File planet.c

chap13 14 Use Functions from a Personal Library Angular brackets : indicate to the preprocessor that a header file is to be found in a system directory. Quotes “planet.h” : a library belonging to the programmer.

chap13 15 Storage Classes C has five storage classes auto extern global variable static register

chap13 16 Auto and Extern Variables auto: default storage class of function parameters and local variables Storage is automatically allocated on the stack at the time of a function call and deallocated when the function returns. extern: storage class of names known to linker. the name of the functions themselves

chap13 17 Global Variables A variable that may be accessed by many functions in a program. Only the defining declaration, the one in eg1.c, allocates spaces for global_var_x. A declaration beginning with the keyword extern allocated no memory; it simply provides information for the computer. /* eg1.c */ int global_var_x; void afun(int n) … /* eg2.c */ extern int global_var_x; void bfun(int n) …

chap13 18

chap13 19 Static Variables static: storage class of variables allocated only once, prior to program execution. int fun_frag(int n) { static int once = 0; int many = 0; } many is allocated space on the stack each time fun_frag is called. Every time fun_frag returns, many is deallocated. Static variable once is allocated and initialized one time, prior to program execution. It remains allocated until the entire program terminates.

chap13 20 Register variables Storage class of automatic variable that the programmer would like to have stored in registers. It is closely related to storage class auto and may be applied only to local variables and parameters. By choosing storage class register, the programmer indicates an expectation that the program would run faster if a register, a special high-speed memory location inside the central processor, could be used for the variable.

chap13 21 Modifying Function for Inclusion in a Library Error: return an error code or display an error message.

chap13 22 Conditional Compilation C allows the user to select parts of a program to be complied and parts to be omitted. This ability can be helpful. Example 1: one can build in debugging printf calls when writing a function and then include these statements in the complied program only when they are needed.

chap13 23 #define TRACE

chap13 24

chap13 25 Conditional Compilation Example 2 Library sp_one (uses library sp ) Library sp_two (uses library sp also) A program uses the facilities of both sp_one & sp_two. This would lead to inclusion of sp.h twice. C prohibits such duplicate declarations. Example 3: Design a system for use on a variety of computers Allows one to compile only the code appropriate for the current computer.

chap13 26

chap13 27 Arguments to Function main int main(int argc, /*input - argument count */ char *argv[])/*input - argument vector*/ Command line arguments: options specified in the statement that activates a program. Example: prog opt1 opt2 opt3 argc 4 argv[0] prog argv[1] opt1 argv[2] opt2 argv[3] opt3

chap13 28 backup old.txt new.txt See Fig 13.12

chap13 29 Defining Macros with Parameters

chap13 30 Importance of Parentheses in Macro Body

chap13 31