Each part of this lab will use the same input file, named “lab3-in.dat.” This file will be located in the same directory as the executables (do not specify a path for the file in the Select statements). This file is a roster of animals in a travelling carnival. The record format for the file is as follows: Field Description Length Data Type Name 12 String Gender 1 String Species 15 String The end result of each part of this assignment is the same. You will be given different programming specifications in each, to force you to use some of the different statements and concepts we have discussed recently. If some aspect of a program does not have specifications dictating how to accomplish that part, then you are free to use whatever approach you wish. Each program is a hybrid of batch and interactive. The input is coming from a file, but the output will be going to the console window; there is no output file. The programs will determine how many animals fall into each class. These classes, and animal species in each, are (note the proper case): Amphibian: (Frog, Newt, Salamander, Toad) Bird: (Albatross, Eagle, Falcon, Hawk, Pelican, Vulture) Mammal: (Ape, Cheetah, Chimp, Coyote, Lion, Mongoose, Otter, Tiger, Wolf) Reptile: (Alligator, Boa, Cobra, Komodo, Turtle, Viper) Other: Anything else The output should consist solely of class names and counts, nicely formatted. Allow 3 digits for each count. This will seem like more work than it is; a lot of the code amongst each part is the same so there are plenty of copy-and-paste opportunities. Part A You will create an OpenCOBOL program, named lab3a.cob, that will generate the desired counts adhering to the following specifications: Use a condition name to denote and check for the end of file. Use Set to manipulate the end of file variable Use condition names and If statements to determine in which category each animal belongs Part B You will create an OpenCOBOL program, named lab3b.cob, that will generate the desired counts adhering to the following specifications: Use an Evaluate statement without condition names to determine in which category each animal belongs Part C You will create an OpenCOBOL program, named lab3c.cob, that will generate the desired counts adhering to the following specifications: The program will initially prompt the user to provide (from the keyboard) the number of records in the file (the sample file has 71 records). Allow for a 3-digit record count. o Repeat prompting the user for a record count until the user provides a nonnegative value o You are free to assume that the user will not provide a record count that exceeds the number of records in the file o You are free to assume the user will only provide numeric values Instead of checking for the end of file, use the Perform Times loop with the value provided by the user as the limit Use If statements without condition names to determine in which category each animal belongs Part D You will create an OpenCOBOL program, named lab3d.cob, that will generate the desired counts adhering to the following specifications: The program will initially prompt the user to provide (from the keyboard) the number of records in the file (the sample file has 71 records). Allow for a 3-digit record count. o Repeat prompting the user for a record count until the user provides a nonnegative value o You are free to assume that the user will not provide a record count that exceeds the number of records in the file o You are free to assume the user will only provide numeric values Instead of checking for the end of file, use the Perform Varying loop with the value provided by the user as the limit Use condition names and an Evaluate statement to determine in which category each animal belong?
Given data,
Program Files:
lab3a.cob
Identification Division.
Program-ID. Lab3a.
Environment Division.
Input-Output Section.
File-Control.
Select InFile
Assign to "lab3-in.dat"
Organization is Line Sequential.
Data Division.
File Section.
FD InFile.
01 InString Pic X(28).
Working-Storage Section.
01 Names Pic X(12).
01 Gender Pic X(1).
01 Species Pic X(15).
88 Amphibian Value "Frog" "Newt" "Salamander"
"Toad".
88 Bird Value "Albatross" "Eagle" "Falcon"
"Hawk" "Pelican" "Vulture".
88 Mammal Value "Ape" "Cheetah" "Chimp" "Coyote"
"Lion" "Mongoose" "Otter" "Tiger"
"Wolf".
88 Reptile Value "Alligator" "Boa" "Cobra"
"Komodo" "Turtle" "Viper".
01 EndFileStr Pic X Value "n".
88 EndFile Value "y"
When Set to False is "y".
01 AmphibCount Pic 9(3).
01 BirdCount Pic 9(3).
01 MamCount Pic 9(3).
01 RepCount Pic 9(3).
01 OtherCount Pic 9(3).
01 AmphibStr Pic ZZ9.
01 BirdStr Pic ZZ9.
01 MamStr Pic ZZ9.
01 RepStr Pic ZZ9.
01 OtherStr Pic ZZ9.
01 InStringLength Pic 99.
Procedure Division.
000-Main.
Open Input InFile
Perform until EndFile
Read InFile
At end
Set EndFile to false
Not at end
Perform 100-SeparateStrings
Perform 200-ClassCount
End-Read
End-Perform
Close InFile
Move AmphibCount to AmphibStr
Move BirdCount to BirdStr
Move MamCount to MamStr
Move RepCount to RepStr
Move OtherCount to OtherStr
Display "Amphibian: " Function Trim(AmphibStr)
Display "Bird: " Function Trim(BirdStr)
Display "Mammal: " Function Trim(MamStr)
Display "Reptile: " Function Trim(RepStr)
Display "Other: " Function Trim(OtherStr)
Stop Run.
100-SeparateStrings.
Unstring InString (1:12)
Into Names
End-Unstring
Unstring InString (13:13)
Into Gender
End-Unstring
Move Function Length(InString) to InStringLength
Unstring InString (14:InStringLength)
Into Species
End-Unstring.
200-ClassCount.
If Amphibian
Add 1 to AmphibCount
Else if Bird
Add 1 to BirdCount
Else if Mammal
Add 1 to MamCount
Else if Reptile
Add 1 to RepCount
Else
Add 1 to OtherCount
End-If.
lab3b.cob
Identification Division.
Program-ID. Lab3b.
Environment Division.
Input-Output Section.
File-Control.
Select InFile
Assign to "lab3-in.dat"
Organization is Line Sequential.
Data Division.
File Section.
FD InFile.
01 InString Pic X(28).
Working-Storage Section.
01 Names Pic X(12).
01 Gender Pic X(1).
01 Species Pic X(15).
01 EndFile Pic X.
01 AmphibCount Pic 9(3).
01 BirdCount Pic 9(3).
01 MamCount Pic 9(3).
01 RepCount Pic 9(3).
01 OtherCount Pic 9(3).
01 AmphibStr Pic ZZ9.
01 BirdStr Pic ZZ9.
01 MamStr Pic ZZ9.
01 RepStr Pic ZZ9.
01 OtherStr Pic ZZ9.
01 InStringLength Pic 99.
Procedure Division.
000-Main.
Open Input InFile
Perform until EndFile = "y"
Read InFile
At end
Move "y" to EndFile
Not at end
Perform 100-SeparateStrings
Perform 200-ClassCount
End-Read
End-Perform
Close InFile
Move AmphibCount to AmphibStr
Move BirdCount to BirdStr
Move MamCount to MamStr
Move RepCount to RepStr
Move OtherCount to OtherStr
Display "Amphibian: " Function Trim(AmphibStr)
Display "Bird: " Function Trim(BirdStr)
Display "Mammal: " Function Trim(MamStr)
Display "Reptile: " Function Trim(RepStr)
Display "Other: " Function Trim(OtherStr)
Stop Run.
100-SeparateStrings.
Unstring InString (1:12)
Into Names
End-Unstring
Unstring InString (13:13)
Into Gender
End-Unstring
Move Function Length(InString) to InStringLength
Unstring InString (14:InStringLength)
Into Species
End-Unstring.
200-ClassCount.
Evaluate Species
When "Frog"
When "Newt"
When "Salamander"
When "Toad"
Add 1 to AmphibCount
When "Albatross"
When "Eagle"
When "Falcon"
When "Hawk"
When "Pelican"
When "Vulture"
Add 1 to BirdCount
When "Ape"
When "Cheetah"
When "Chimp"
When "Coyote"
When "Lion"
When "Mongoose"
When "Otter"
When "Tiger"
When "Wolf"
Add 1 to MamCount
When "Alligator"
When "Boa"
When "Cobra"
When "Komodo"
When "Turtle"
When "Viper"
Add 1 to RepCount
When Other
Add 1 to OtherCount
End-Evaluate.
lab3c.cob
Identification Division.
Program-ID. Lab3c.
Environment Division.
Input-Output Section.
File-Control.
Select InFile
Assign to "lab3-in.dat"
Organization is Line Sequential.
Data Division.
File Section.
FD InFile.
01 InString Pic X(28).
Working-Storage Section.
01 Names Pic X(12).
01 Gender Pic X(1).
01 Species Pic X(15).
01 AmphibCount Pic 9(3).
01 BirdCount Pic 9(3).
01 MamCount Pic 9(3).
01 RepCount Pic 9(3).
01 OtherCount Pic 9(3).
01 AmphibStr Pic ZZ9.
01 BirdStr Pic ZZ9.
01 MamStr Pic ZZ9.
01 RepStr Pic ZZ9.
01 OtherStr Pic ZZ9.
01 InStringLength Pic 99.
01 UserNum Pic S9(4) Value 0.
Procedure Division.
000-Main.
Open Input InFile
Display "Enter how many lines of the file you would " &
"like sorted: " With no advancing
Accept UserNum
Perform until UserNum>0
Display "Please enter a number greater than 0"
Display "Enter how many lines of the file you would" &
" like counted: " with no advancing
Accept UserNum
End-Perform
Perform UserNum times
Read InFile
At end
Exit perform
Not at end
Perform 100-SeparateStrings
Perform 200-ClassCount
End-Read
End-Perform
Close InFile
Move AmphibCount to AmphibStr
Move BirdCount to BirdStr
Move MamCount to MamStr
Move RepCount to RepStr
Move OtherCount to OtherStr
Display "Amphibian: " Function Trim(AmphibStr)
Display "Bird: " Function Trim(BirdStr)
Display "Mammal: " Function Trim(MamStr)
Display "Reptile: " Function Trim(RepStr)
Display "Other: " Function Trim(OtherStr)
Stop Run.
100-SeparateStrings.
Unstring InString (1:12)
Into Names
End-Unstring
Unstring InString (13:13)
Into Gender
End-Unstring
Move Function Length(InString) to InStringLength
Unstring InString (14:InStringLength)
Into Species
End-Unstring.
200-ClassCount.
If Species="Frog" or "Newt" or "Salamander" or "Toad"
Add 1 to AmphibCount
Else if Species="Albatross" or "Eagle" or "Falcon" or
"Hawk" or "Pelican" or "Vulture"
Add 1 to BirdCount
Else if Species="Ape" or "Cheetah" or "Chimp" or "Coyote" or
"Lion" or "Mongoose" or "Otter" or "Tiger" or "Wolf"
Add 1 to MamCount
Else if Species="Alligator" or "Boa" or "Cobra" or
"Komodo" or "Turtle" or "Viper"
Add 1 to RepCount
Else
Add 1 to OtherCount
End-If.
lab3d.cob
Identification Division.
Program-ID. Lab3d.
Environment Division.
Input-Output Section.
File-Control.
Select InFile
Assign to "lab3-in.dat"
Organization is Line Sequential.
Data Division.
File Section.
FD InFile.
01 InString Pic X(28).
Working-Storage Section.
01 Names Pic X(12).
01 Gender Pic X(1).
01 Species Pic X(15).
88 Amphibian Value "Frog" "Newt" "Salamander"
"Toad".
88 Bird Value "Albatross" "Eagle" "Falcon"
"Hawk" "Pelican" "Vulture".
88 Mammal Value "Ape" "Cheetah" "Chimp" "Coyote"
"Lion" "Mongoose" "Otter" "Tiger"
"Wolf".
88 Reptile Value "Alligator" "Boa" "Cobra"
"Komodo" "Turtle" "Viper".
01 AmphibCount Pic 9(3).
01 BirdCount Pic 9(3).
01 MamCount Pic 9(3).
01 RepCount Pic 9(3).
01 OtherCount Pic 9(3).
01 AmphibStr Pic ZZ9.
01 BirdStr Pic ZZ9.
01 MamStr Pic ZZ9.
01 RepStr Pic ZZ9.
01 OtherStr Pic ZZ9.
01 InStringLength Pic 99.
01 UserNum Pic S9(4) Value 0.
01 Indx Pic 999.
Procedure Division.
000-Main.
Open Input InFile
Display "Enter how many lines of the file you would " &
"like sorted: " With no advancing
Accept UserNum
Perform until UserNum>0
Display "Please enter a number greater than 0"
Display "Enter how many lines of the file you would" &
" like counted: " with no advancing
Accept UserNum
End-Perform
Perform varying Indx
From 0 by 1 until Indx>=UserNum
Read InFile
At end
Exit Perform
Not at end
Perform 100-SeparateStrings
Perform 200-ClassCount
End-Read
End-Perform
Close InFile
Move AmphibCount to AmphibStr
Move BirdCount to BirdStr
Move MamCount to MamStr
Move RepCount to RepStr
Move OtherCount to OtherStr
Display "Amphibian: " Function Trim(AmphibStr)
Display "Bird: " Function Trim(BirdStr)
Display "Mammal: " Function Trim(MamStr)
Display "Reptile: " Function Trim(RepStr)
Display "Other: " Function Trim(OtherStr)
Stop Run.
100-SeparateStrings.
Unstring InString (1:12)
Into Names
End-Unstring
Unstring InString (13:13)
Into Gender
End-Unstring
Move Function Length(InString) to InStringLength
Unstring InString (14:InStringLength)
Into Species
End-Unstring.
200-ClassCount.
Evaluate true
When Amphibian
Add 1 to AmphibCount
When Bird
Add 1 to BirdCount
When Mammal
Add 1 to MamCount
When Reptile
Add 1 to RepCount
When Other
Add 1 to OtherCount
End-Evaluate.
<<<<Please Give Me Like>>>>>
Get Answers For Free
Most questions answered within 1 hours.