Skip to content Skip to navigation Skip to collection information

OpenStax_CNX

You are here: Home » Content » Programming Fundamentals - A Modular Structured Approach using C++ » Using a Header File for User Defined Specific Task Functions

Navigation

Table of Contents

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Endorsed by Endorsed (What does "Endorsed by" mean?)

This content has been endorsed by the organizations listed. Click each link for a list of all content endorsed by the organization.
  • CCQ display tagshide tags

    This collection is included in aLens by: Community College of Qatar

    Comments:

    "Used in the Computer Programming Fundamentals I course."

    Click the "CCQ" link to see all content they endorse.

    Click the tag icon tag icon to display tags associated with this content.

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • OrangeGrove display tagshide tags

    This collection is included inLens: Florida Orange Grove Textbooks
    By: Florida Orange Grove

    Click the "OrangeGrove" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

  • Houston Community College display tagshide tags

    This collection is included in aLens by: Houston Community College

    Comments:

    "COSC1436 Programming Funaamentals I"

    Click the "Houston Community College" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

  • Featured Content display tagshide tags

    This collection is included inLens: Connexions Featured Content
    By: Connexions

    Comments:

    "Programming Fundamentals - A Modular Structured Approach Using C++ is a new course written by Kenneth Leroy Busbee, a faculty member at Houston Community College. This text introduces students to […]"

    Click the "Featured Content" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

Also in these lenses

  • Busbee's Compter Science display tagshide tags

    This collection is included inLens: Busbee's Computer Science Lens
    By: Kenneth Leroy Busbee

    Comments:

    "Texas Common Course Numbering: COSC1336 or COSC1436"

    Click the "Busbee's Compter Science" link to see all content selected in this lens.

    Click the tag icon tag icon to display tags associated with this content.

  • Lens for Engineering

    This module and collection are included inLens: Lens for Engineering
    By: Sidney Burrus

    Click the "Lens for Engineering" link to see all content selected in this lens.

  • eScience, eResearch and Computational Problem Solving

    This collection is included inLens: eScience, eResearch and Computational Problem Solving
    By: Jan E. Odegard

    Click the "eScience, eResearch and Computational Problem Solving" link to see all content selected in this lens.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.
 

Using a Header File for User Defined Specific Task Functions

Module by: Kenneth Leroy Busbee. E-mail the author

Summary: Concepts and an example of how to create a user library within the C++ programming language.

Concept: User Defined Specific Task Functions

Most companies have certain tasks that are unique to their company. Collectively the programming staff may decide to build several functions and organize them into one or more user libraries. Specific task functions are often built using a testing shell program. The sole purpose of the testing shell program is to create the specific task functions and to test them to insure that they are working properly. Think of a clam, its shell surrounds the important part, the pearl. A testing shell program surrounds the specific task function (the important part). Usually the testing shell program will be used to create several functions that will be placed into a user defined library. The process flows as follows:

  1. The testing shell program with the specific task functions is built and thoroughly tested.
  2. A copy of the testing shell source code is saved as the header file that once modified will be placed in the user library. You delete the main part of the program leaving a comments area, any needed include file references and the specific task functions.
    Figure 1: Creating a header file from a copy of the testing shell.
    Header File Creation
    Shows header file creation
  3. Another copy of the testing shell source code is saved as the prototypes file. This is a text file that retains only the prototypes for the functions that were placed into the header file. The functions should be using meaningful identifier names, thus the prototypes should provide adequate information to others on how to call the function with appropriate parameter passing.
    Figure 2: Creating a prototypes file from a copy of the testing shell.
    Prototypes File Creation
    Shows prototypes file creation
  4. Another copy of the testing shell source code is saved as the verify header program. You delete the functions prototypes and definitions then provide an include that points to the header file. This program is compiled and run to make sure the header file is working properly.
    Figure 3: Creating a verify header file from a copy of the testing shell.
    Verify Header File Creation
    Shows verify header file creation

A good way to understand the concept is to review the four files described above that have been created by a programmer. We will be using the C++ programming language, however the code is easy to understand and will serve our needs well at explaining the concepts; even if you are not familiar with C++.

Demonstration Using C++

Creating a Folder or Sub-Folder for the Four Files

Depending on your compiler/IDE, you should decide where to download and store source code files for processing. Prudence dictates that you create these folders as needed prior to downloading source code files. A suggested sub-folder for the Bloodshed Dev-C++ 5 compiler/IDE might be named:

  • Monitor_Header

If you have not done so, please create the folder(s) and/or sub-folder(s) as appropriate.

Download the Four Files

Download and store the following files to your storage device in the appropriate folder. You may need to right click on some of the links and select "Save Target As" in order to download some of the files.

Download from Connexions: Monitor_Testing_Shell.cpp

Download from Connexions: udst_monitor.h

Download from Connexions: udst_monitor_prototypes.txt

Download from Connexions: Monitor_Verify_Header.cpp

Study the Files Collectively to Understand the Concepts

Take a few moments to review the files in conjunction with the concept discussion above. You should compile and run the Monitor_Testing_Shell.cpp program.

Creating a Folder or Sub-Folder for your User Library

Depending on your compiler/IDE, you should decide where to create a folder that will hold the header files you create. We suggest that you create the folder in conjunction with the compiler/IDE software. If you were using the Bloodshed Dev-C++ 5 compiler/IDE you most likely installed the compiler/IDE software at: C:\Dev-Cpp\ if you installed it on your machine or at: DriveLetter:\Dev-Cpp\ (where the DriveLetter is the drive that represents your flash drive) if you installed it on a flash drive. We suggest that you create a sub-folder at that location named:

  • user_library

The path of: C:\Dev-Cpp\user_library would be created as the location for your user library if using your machine installation. You can literally place it anywhere and name the library any name, but once you decide on a place and name; you do not want to move or rename the folders.

Placing the Header File into the User Library

You need to copy the udst_monitor.h file placing it into the user_library folder just created. As you can guess the udst stands for user defined specific task. The functions within this header file would be used to control the interaction a user has with the monitor. The .h is a convention of the C++ programming language and indicates a header file. Thus the identifier name for the header file is very meaningful and descriptive.

Verify that the Header File Works Properly

Review the Monitor_Verify_Header.cpp source code file and note the two include commands are different.

  1. The Standard Library uses a less than and a greater than to bracket the Standard Library name of: iostream
  2. The user library uses quote marks to bracket the location of the header file. This identifies to the complier that we are specifying the exact file we want. We provide a complete file specification (drive, path information, filename and extension).
  3. Because this item is technically a string within C++, we must use two back slashes between the drive, path(s) and filename. This is because the first back slash assumes that the next character is an escape code and if we really don't want an escape code but a back slash, the second back slash says no I wanted a back slash.This string: "C:\\Dev-Cpp\\user_library\\udst_monitor.h" will be interpreted to mean: C:\Dev-Cpp\user_library\udst_monitor.h

Depending on what drive you are using, what path folder structure you are using and what you called your folder; you may need to correct the include reference within the source code so that it properly references the header file.

Compile and run the Monitor_Verify_Header.cpp program. Note: It should work exactly as the Monitor_Testing_Shell.cpp program.

Definitions

Definition 1: udst
User Defined Specific Task
Definition 2: testing shell
A program used to create specific task functions.
Definition 3: header file
A file that contains items we want to have included toward the top of our source code.

Collection Navigation

Content actions

Download:

Collection as:

PDF | More downloads ...

Module as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Add:

Collection to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks

Module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks