Question

Each part of this lab will use the same input file, named “lab3-in.dat.” This file will...

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?

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while loop to take in user's name and desired destination for as long as there are user inputs. Prompt user to input yes to continue and no to quit. Prompt for user's name. Receive the name into the program and save it as the value of name variable. Prompt user for their desired vacation destination. Receive response and save it as the value of a...
Make a directory named hw4 then cd into that directory • In the hw4 directory use...
Make a directory named hw4 then cd into that directory • In the hw4 directory use nano to create a text file named words.txt that contains 6 words – each on a different line. They can be any random words. For example: eggs apples class homework car games part two: Write a shell script named hw4.sh that first clears the screen (using the clear command) then does the following: • Asks the user (using the echo command) to enter a...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes and methods. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Animal that has the following attributes and methods and is saved in the file Animal.py. Attributes __animal_type is a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc....
This is C++ Note, for part 2 of this assignment, you DO NOT NEED to use...
This is C++ Note, for part 2 of this assignment, you DO NOT NEED to use arrays or vectors. All changes, calculations, etc should be performed in place ( in the file). You may need one or two structures that temporary hold data needed to be displayed, changed, etc. Part 2: Binary Files Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or...
Python (Using for reference please comment which is which!) Exercise 1: Store Unique Words as Dictionary...
Python (Using for reference please comment which is which!) Exercise 1: Store Unique Words as Dictionary Keys Write a program that stores unique words as keys in a dictionary. Don't worry about upper/lowercase for now (i.e., it's ok for you to have separate entries for "The" and "the"), and just assign 1 as the value for each key. Use an input loop (while loop with an input function) to accepts values putting them into the dictionary until the user enters...
I can open the file in the program, but I cannot figure out how to properly...
I can open the file in the program, but I cannot figure out how to properly split the data and assign a grade to the number values in the text file. I keep getting :: ValueError: invalid literal for int() with base 10: 'Roger Jones 75\n' Below are the assignment details: This program processes grades for a small class. It reads an input file named grade_input.txt where each record contains a student’s first name, last name and numeric grade (a...
Code a C file, following these instructions: This lab is about getting the input from a...
Code a C file, following these instructions: This lab is about getting the input from a file. Let’s assume the words are provided in one file, passed as an argument to your program. The names of the files are provided as arguments to your program (i.e., they are copied by the shell in the argv variable), and each file is a text file with lots of words. Open the manual page for open() system call and add to your code...
can you please do this lab? use lunix or C program its a continuation of a...
can you please do this lab? use lunix or C program its a continuation of a previous lab. the previous lab: Unix lab 4: compile and link multiple c or c++ files Please do the following tasks step by step: create a new directory named by inlab4 enter directory inlab4 create a new file named by reverse.c with the following contents and then close the file: /*reverse.c */ #include <stdio.h> reverse(char *before, char *after); main() {       char str[100];    /*Buffer...
The project CreateDirectoriesDemo is included with the files for this chapter as a zipped file. rewrite...
The project CreateDirectoriesDemo is included with the files for this chapter as a zipped file. rewrite the program so that it asks the user for the location where the new directories are to be created, and then asks the user to enter, one at a time, the relative path names of the directories it should create. Amended additional details to the above abstraction of the requirements. The application should be multiplatform adaptive. This means that it should work on an...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT