Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 17P. 1Winter Quarter Personal Libraries.

Slides:



Advertisements
Similar presentations
An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
Advertisements

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 10P. 1Winter Quarter Repetition Structures.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect FXP. 1Winter Quarter Course Wrap Up and Final Review Topics Lecture.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 16P. 1Winter Quarter Strings Lecture 16.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions.
Engineering EG167C - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect FXP. 1Winter Quarter Course Wrap Up and.
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 20AP. 1Winter Quarter File Transfer Lecture.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition P. 1Winter Quarter Daily Assignment A21 A21 asks.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 13P. 1Winter Quarter Scope of Variables.
Software Design Project
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Computer Science II Exam I Review Monday, February 6, 2006.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review Topics.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Guide To UNIX Using Linux Third Edition
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M2P. 1Winter Quarter Midterm 2 Review Topics.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 8P. 1Winter Quarter Control Statements Lecture.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect FXP. 1Winter Quarter Course Wrap Up and.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 16AP. 1Winter Quarter UNIX Process Management.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 9P. 1Winter Quarter Switch Case Structures.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 28P. 1Winter Quarter Inheritance and Overloading.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 4P. 1Winter Quarter Introduction to UNIX.
Computer Science 210 Computer Organization Modular Decomposition Making a Library Separate Compilation.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 21P. 1Winter Quarter MATLAB: Structures.
chap13 Chapter 13 Programming in the Large.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Chapter 13 Programming in the Large Dr. Jiung-yao Huang Dept. Comm. Eng. Nat. Chung Cheng Univ. TA: 鄭筱親 陳昱豪.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 1Winter Quarter C++ Lecture 24.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 7P. 1Winter Quarter File I/O in C Lecture.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 25P. 1Winter Quarter C++: I/O and Classes Lecture 25.
Compilation & Linking Computer Organization I 1 November 2009 © McQuain, Feng & Ribbens The Preprocessor When a C compiler is invoked, the.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering Problem Solving and Logic.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 20AP. 1Winter Quarter File Transfer Lecture 20A.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions Lecture 12.
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
15. WRITING LARGE PROGRAMS. Source Files A program may be divided into any number of source files. Source files have the extension.c by convention. Source.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 22P. 1Winter Quarter MATLAB: Simultaneous.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Functions (2)
Program in Multiple Files. l all C++ statements are divided into executable and non-executable l executable - some corresponding machine code is generated.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Chapter 3 Part II. 3.8 Placing a Class in a Separate File for Reusability.cpp file is known as a source-code file. Header files ◦ Separate files in which.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 10P. 1Winter Quarter Repetition Structures Lecture 10.
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Week 3-4 Control flow (review) Function definition Program Structures
What Is? function predefined, programmer-defined
User-Written Functions
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Separate Compilation.
Computer Science 210 Computer Organization
C Preprocessor(CPP).
Introduction to Classes and Objects
Comments, Prototypes, Headers & Multiple Source Files
C++ Compilation Model C++ is a compiled language
CSE 303 Concepts and Tools for Software Development
What Is? function predefined, programmer-defined
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
Presentation transcript:

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 17P. 1Winter Quarter Personal Libraries Lecture 17

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 17P. 2Winter Quarter The Steps in Making a Program 1) Create the program source file. 2) Compile to produce an object file. 3) Link with other object files (stored in a library) to produce an executable file.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 17P. 3Winter Quarter Creating Personal Libraries To create a personal library, we first create a special kind of source code file called a header file. It is a text file that contains all the information the compiler needs about the things in the library. This information might include: Comments #define directives Function prototypes for the functions that are in the personal library. This file would have a ".h " file extension

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 17P. 4Winter Quarter Creating the "Implementation" File We must also create another special kind of C source code file called an implementation file. This file might include: –Comments << –#include directives –#define directives (for constant macros used only inside this library) –Type definitions used only in this library. –Function definitions for the functions you want in the library. <<

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 17P. 5Winter Quarter Creating an Object File The implementation file is saved with a ".cpp " extension and is must be compiled before it is used: >g++ mylib.cpp -c The " -c " switch means "compile only" This produces an object file called mylib.o

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 17P. 6Winter Quarter Creating Personal Libraries Note that the mylib.o object file is NOT a "true" library file. It is analogous to a book that we want to put into a library. We can create a true library file and put a copy of our object file into the library with the UNIX archive (ar) command: >ar -r mylib.lib mylib.o

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 17P. 7Winter Quarter Creating Personal Libraries Since our file contains two or three functions, it usually would be better to separate them into three files such as square.cpp, cube.cpp, and (optionally) factorial.cpp. Then we would compile each one of these separately to produce square.o, cube.o and factorial.o object files.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 17P. 8Winter Quarter Maintaining Personal Libraries Then we could remove mylib.o from our library: >ar -d mylib.lib mylib.o and place into it our three new object files: >ar -r mylib.lib square.o cube.o factorial.o It we want to see the contents of our library file we can get a table of contents with: >ar -t mylib.lib or >nm mylib.lib

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 17P. 9Winter Quarter Using a Personal Library Put an include statement in your program file #include "mylib.h" Note the quotes (" ") not angle brackets (<>) Put the names of both your program file and your library file in the compile/link command. Compile and link the program with the library: >g++ -o g15.out g15.cpp mylib.lib

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 17P. 10Winter Quarter Assignment G15 Three steps in the assignment: –Create your own header file, mylib.h. –Make your own library file in two steps: 1). Create library source file, mylib.cpp 2). Compile mylib.cpp to produce mylib.o (You are not required to make a "true" UNIX library file for this assignment.) –Create your test program, g15.cpp.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 17P. 11Winter Quarter A Recursive Factorial Function (Optional) // From Deitel & Deitel Chap 5 Section 13 long factorial (long number) { if ( number <= 1 ) return 1 ; else return ( number * factorial (number - 1)) ; }