4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
Introduction to Business System COBOL Programs
description
Transcript of Introduction to Business System COBOL Programs
Introduction to Business System
- 44 -
Program no.10 W.A.P. to display pyramid of stars
SOLUTION:-
clear
?"program to display starpyramid"
?replicate('-',20)
input"Enter number of rows required"to row_num
for line_count=1 to row_num
for space_count=row_num to line_count step(-1)
??" "
endfor
for star_count= 1 to (2*line_count-1)
??"*"
endfor
?""
endfor
Introduction to Business System
- 45 -
Program no.11 W.A.P to generate right angle triangle
SOLUTION:-
clear
?"Pattern of Right Triangle"
?Replicate('-',20)
Input "Enter the desire no of rows" to Row_num
for line_num=1 to Row_num
for star_num=1 to line_num
??"*"
endfor
?""
endfor
Introduction to Business System
- 46 -
Program no.12 W.A.P whether a character is vowel or not.
SOLUTION:-
Clear
set talk off
? "The current date is", date (), " Time", time ()
? "The Program to check whether a character is vowel or not"
? Replicate ('--’, 20)
Accept "Enter the character" to ch
Do Case
Case ch = 'a'
? "The Character Entered is vowel"
Case ch = 'A'
? "The Character Entered is vowel"
Case ch = 'e'
? "The Character Entered is vowel"
Case ch = 'E'
? "The Character Entered is vowel"
Case ch = 'i'
? "The Character Entered is vowel"
Case ch = 'I'
? "The Character Entered is vowel"
Case ch = 'o'
? "The Character Entered is vowel"
Case ch = '0'
? "The Character Entered is vowel"
Case ch = 'u'
Introduction to Business System
- 47 -
? "The Character Entered is vowel"
Case ch = 'U'
? "The Character Entered is vowel"
Otherwise
? "The Character Entered is a consonant"
Endcase
Introduction to Business System
- 48 -
Program No.13W.A.P to find fibonacci series.
SOLUTION:-
clear
?"Prog to find fibonacci series"
?replicate('-',25)
fir=0
se=1
input"Enter the limit" to n
?fir
?se
for i=1 to n step(1)
b=fir+se
fir=se
se=b
?b
Endfor
Introduction to Business System
- 49 -
Program No.14 W.A.P to find the average of numbers.
SOLUTION:-
clear
?"Prog to find avg"
?replicate('-',25)
sum=0
input"Enter limit" to n
for i=1 to n
input"Enter no" to num
sum=sum+num
endfor
AVG=sum/n
?"Average is",AVG
Introduction to Business System
- 50 -
Program No.15 Calculate grade of student according to marks obtained in 5
subject.
i) Percentage above or equal to 70 – A grade
ii) Percentage between 50 to 69 – B grade
iii) Percentage between 40 to 49 – c grade
iv) Percentage equal or below 40 – Fail.
SOLUTION:-
clear
?"program to give grades to students"
?replicate('-',25)
input" enter the marks" to num
if(num>= 70)
?"A grade"
else
if(num<=69)
if(num>=50)
?"B grade"
else
if(num<=49)
if(num>=40)
?"C grade"
endif
endif
endif
endif
if(num<40)
Introduction to Business System
- 52 -
PRACTICAL NO :-5
AIM:- INTRODUCTION TO MICROSOFT EXCEL
THEORY:-
Microsoft Excel is allows you to create professional spreadsheets and charts. It performs
numerous functions and formulas to assist you in your projects.
Starting Microsoft Excel:- Two Ways:-
1.Double click on the Microsoft Excel icon on the desktop.
2.Click on Start --> Programs --> Microsoft Excel
Introduction to Business System
- 53 -
Creating Formulas:-
1.Click the cell that you want to enter the formula. Type = (an equal sign).
2.Click the Function Button
3.Select the formula you want and step through the on-screen instructions
Order of Operations Excel Uses:-
Precedence Operation Operator
1 Exponentiation ^
2 Multiplication *
2 Division /
3 Addition +
3 Subtraction -
4 Concatenation &
5 Equal To =
5 Greater Than >
5 Less Than <
Adding Borders and Shading to Cells:-
1.Make sure you have the Formatting toolbar visible
Click on View --> Toolbars --> Formatting
2.Select cells you wish to format by left clicking on them and highlighting them
3.Click the button to shade a cell and/or the to give a cell a border
Introduction to Business System
- 54 -
Inserting A Chart:-
1.Select over the text you want to make your chart with
2.Click Insert --> Chart
3.Select the type of chart you want
Introduction to Business System
- 55 -
4.Confirm or change your data range. Update the Chart Options
5.Select if you want to put it into the current worksheet or into a new worksheet.
Introduction to Business System
- 56 -
PRACTICAL NO :-6
AIM: INTRODUCTION TO COBOL.
THOERY
COBOL is a high-level programming language first developed by the CODASYL Committee
(Conference on Data Systems Languages) in 1960. Since then, responsibility for developing new
COBOL standards has been assumed by the American National Standards Institute (ANSI).
The word COBOL is an acronym that stands for Common Business Oriented Language. As the
expanded acronym indicates, COBOL is designed for developing business, typically file-
oriented, applications. It is not designed for writing systems programs. For instance you would
not develop an operating system or a compiler using COBOL.
COBOL is simple:-
COBOL is a simple language (no pointers, no user defined functions, no user defined types) with
a limited scope of function. It encourages a simple straightforward programming style. Curiously
enough though, despite its limitations, COBOL has proven itself to be well suited to its targeted
problem domain (business computing).
The structure of COBOL programs:-
COBOL programs are hierarchical in structure. Each element of the hierarchy consists of one or
more subordinate elements.
We can represent the COBOL hierarchy using the COBOL met language as follows;
Introduction to Business System
- 57 -
Divisions:-
A division is a block of code, usually containing one or more sections, that starts where the
division name is encountered and ends with the beginning of the next division or with the end of
the program text.
Sections:-
A section is a block of code usually containing one or more paragraphs. A section begins with
the section name and ends where the next section name is encountered or where the program text
ends.
Section names are devised by the programmer, or defined by the language. A section name is
followed by the word SECTION and a period.
See the two example names below -
SelectUnpaidBills SECTION.
FILE SECTION.
Paragraphs:-
A paragraph is a block of code made up of one or more sentences. A paragraph begins with the
paragraph name and ends with the next paragraph or section name or the end of the program text.
A paragraph name is devised by the programmer or defined by the language, and is followed by
a period.
See the two example names below -
PrintFinalTotals.
PROGRAM-ID.
Sentences and statements:-
A sentence consists of one or more statements and is terminated by a period.
For example:
MOVE .21 TO VatRate
MOVE 1235.76 TO ProductCost
COMPUTE VatAmount = ProductCost * VatRate.
Introduction to Business System
- 58 -
PRACTICAL NO. 7
AIM:-TO STUDY VARIOUS PROGRAMS OF COBOL.
Programs:-
1. Write a program to display the string.
Sol:- IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO
PROCEDURE. DIVISION.
DISPLAY “savita”
STOP RUN.
OUTPUT:-
Introduction to Business System
- 59 -
2. Write a program to add two numbers.
Sol:- IDENTIFICATION DIVISION.
PROGRAM-ID. SUM.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PICTURE 99 VALUE IS 10.
01 B PICTURE 99 VALUE IS 10.
01 C PICTURE 99 VALUE IS 0.
PROCEDURE DIVISION.
A-PARA.
DISPLAY " A= ", A.
DISPLAY " B= ", B.
COMPUTE C= A + B
DISPLAY " C= ", C.
STOP RUN.
Output:-
Introduction to Business System
- 60 -
3. Write a program to subtract two numbers
Sol:- IDENTIFICATION DIVISION.
PROGRAM-ID SONY
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 99 VALUE IS 20.
01 B PIC 999 VALUE IS 80.
PROCEDURE DIVISION.
Q-PARA.
SUBTRACT A FROM B.
DISPLAY "B=" , B.
STOP RUN.
Introduction to Business System
- 61 -
4. Write a program to multiply two numbers
Sol:- IDENTIFICATION DIVISION.
PROGRAM-ID. FIRST.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PICTURE 99 VALUE IS 10.
01 B PICTURE 99 VALUE IS 10.
01 C PICTURE 999 VALUE IS 0.
PROCEDURE DIVISION.
A-PARA.
DISPLAY " A= ", A.
DISPLAY " B= ", B.
MULTIPLY A BY B GIVING C.
DISPLAY " C= ", C.
STOP RUN.
Introduction to Business System
- 62 -
5. Write a program to demonstrate input output verbs.
Sol:- IDENTIFICATION DIVISION.
PROGRAM-ID. DEMONSTRATE-INPUT-OUTPUT-VERBS.
AUTHOR.XXXXXXX
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 999 VALUE 101.
PROCEDURE DIVISION.
M-PARA.
DISPLAY "ENTER THE NUMBER".
ACCEPT A.
DISPLAY "ENTERED NUMBER IS= ", A.
STOP RUN.
Introduction to Business System
- 63 -
6. Write a program to demonstrate picture and value clause
Sol:- IDENTIFICATION DIVISION.
PROGRAM-ID. DEMONSTRATE PICTURE CLAUSE.
AUTHOR. XXXXXXX
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 99 VALUE 77.
PROCEDURE DIVISION.
M-PARA.
DISPLAY "A=", A.
STOP RUN.
Introduction to Business System
- 64 -
7. Write a program to demonstrate data movement verb.
Sol:- IDENTIFICATION DIVISION.
PROGRAM-ID. DEMONSTRATE-DATA-MOVEMENT-VERB.
AUTHOR. XXXXXXX
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 999 VALUE 101.
01 B PIC 999.
PROCEDURE DIVISION.
M-PARA.
DISPLAY "A=", A.
MOVE A TO B.
DISPLAY "MOVING VALUE OF A TO B."
DISPLAY "B=", B.
STOP RUN.