Introduction to Programming

一月 9, 2007 by billrain
Filed under: Cobol 

Introduction to Programming

Introduction

In this section a gentle introduction to programing in general, and to programming in COBOL in particular, is provided. This is done by writing some simple COBOL programs that use the three main programming constructs – Sequence, Iteration and Selection.

Don’t worry if you don’t understand these programs at this point. The main purpose of this section is to give you a first look at some simple COBOL programs.


Let’s write a program

A program is a collection of statements written in a language the computer understands.

A computer executes program statements one after another in sequence until it reaches the end of the program unless some statement in the program alters the order of execution.

Computer Scientists have shown that any program can be written using the three main programming constructs;

Sequence
Selection
Iteration

This section introduces COBOL programming by writing some simple COBOL programs using these constructs.


Sequence Program Specification

We want to write a program which will accept two numbers from the users keyboard, multiply them together and display the result on the computer screen.

Any program consists of three main things;

  1. The computer statements needed to do the job
  2. Declarations for the data items that the computer statements need.
  3. A plan, or algorithm, that arranges the computer statements in the program so that the computer executes them in the correct order.

Program Statements and Data items

What COBOL program statements will we need to do the job specified above and what data items will we need to access?

We will need a statement to take in the first number and store it in the named memory location (a variable) – Num1
ACCEPT Num1.

We will need a statement to take in the second number and store it in the named memory location – Num2
ACCEPT Num2.

We will need a statement to multiply the two numbers together and to store the result in the named location – Result
MULTIPLY Num1 BY Num2 GIVING Result.

We will need a statement to display the value in the named memory location “Result” on the computer screen -
DISPLAY “Result is = “, Result.

VN:F [1.9.3_1094]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.3_1094]
Rating: +1 (from 1 vote)

Comments

Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!





  • 分类目录

  • 功能

  • 联络订阅

    google reader
    订阅到抓虾
    订阅到鲜果
    订阅到飞鸽
    bloglines
    my yahoo
    netvibes