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++ » Program Control 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.
 

Program Control Functions

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

Summary: A general explanation of how functions are used to modularize a program.

Prerequisite Material

Critical to this module is the review of several Connexions modules:

  1. m_18861 – Titled: Modularization and C++ Program Layout
  2. m_19136 – Titled: Pseudocode Examples for Functions
  3. m_18682 – Titled: Hierarchy or Structure Chart

You should review these materials before proceeding. If you are viewing this module on-line, links to these items are in the "Links" box to your right.

Concept of Modularization

The concept is everywhere present in the real world about us. Simply put it is to take a large complicated problem and to divide it into smaller manageable pieces. The hierarchy chart of any large organization (government unit, company, university, hospital, etc.) will show levels of people with job titles that indicate a different area of responsibility. Each person is a small piece of the overall workings of the organization. Each person can concentrate on their unique talent or task to make sure it works properly. Collectively they accomplish the goals of the organization.  

Additionally, the concept has been around for a long time. A village of 300 years ago had farmers, tailors, butchers, blacksmiths, etc. Manufacturing is a prime example of not just work being modularized but the product itself is viewed in terms of modules or systems (Example of a automobile: engine, steering, brakes, etc.).

The world of computers, both hardware (equipment) and software (computer programs), also uses this modular concept. Thus, the concept migrates to a single computer program; allowing us to modularize the program into manageable tasks called functions.

Program Control Functions

Program Control functions normally do not communicate information to each other but use a common area for variable storage. The rules for how data is communicated in and out of a function vary greatly by programming language, but the concept is the same. The data items passed (or communicated) are called parameters. Thus the wording: parameter passing. However, with program control functions we use the data communication option of no communication in – with no communication out. Our data variables and constants are placed in a common area available to all functions (called global scope).

The identifier names for program control functions usually imply a task to be accomplished, such as get-data, process-data or show-results. As you learn to write more complicated programs the number of lines of code will increase. Prudence dictates that it would be beneficial to divide the program into functions that perform unique tasks. The larger the program the more need for modularization or creating of program control functions.

Depending on the programming language, there is a formal way to:

  1. define a function (it’s definition or the code it will execute))
  2. call a function
  3. declare a function (a prototype is a declaration to a complier)

One of the easier ways to understand program control function is to view an example. Even if you don’t know the C++ programming language, you can study the materials to help understand the modularization process.

Demonstration Program in C++

Creating a Folder or Sub-Folder for Source Code 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:

  • Demo_Programs

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

Download the Demo Program

Download and store the following file(s) to your storage device in the appropriate folder(s). You may need to right click on some of the links and select "Save Target As" in order to download some of the files. Following the methods of your compiler/IDE, compile and run the program(s). Study the source code file(s) in conjunction with other learning materials.

Download from Connexions: Demo_Program_Control_Functions_before_Compiler_Test.cpp

Download from Connexions: Demo_Program_Control_Functions_Pseudocode.txt

Download from Connexions: Demo_Program_Control_Functions_Hierarchy_Chart.jpg

Download from Connexions: Demo_Program_Control_Functions.cpp

Study the Materials Collectively to Understand Modularization

The four items represent a progression from no modularization to modularization:

  1. Program code before it is modularized
  2. Modularized pseudocode and a hierarchy chart for the program
  3. Program code that has been modularized

The simplicity of the program should not be considered during this review. It is obvious that the program does not need modularization. The example is to show or demonstrate how to modularize a program for program control.

Definitions

Definition 1: common area
An area of the program where variables and constants are defined so that they are available to all functions.

Collection Navigation

Content actions

Download:

Collection as:

PDF | More downloads ...

Module as:

PDF | 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