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
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...
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...
please use linux/unix command terminal to complete, step 1 1-create a new directory named by inlab4...
please use linux/unix command terminal to complete, step 1 1-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 to hold reversed string */ reverse("cat", str); /*Reverse the string "cat" */ printf("reverse(\"cat\")=%s\n", str); /*Display result */ reverse("noon", str); /*Reverse the string "noon" */ printf("reverse(\"noon\")=%s\n", str); /*Display result */ } reverse(char *before,...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop...
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop to complete the task. A while loop has this basic structure: /* variable initializations */ while (/*stop condition*/){ /* statements to be performed multiple times */ /* make sure the variable that the stop condition relies on is changed inside the loop. */ } Despite the structure of the while loop being different than that of a for loop, the concept behind it is...
C++ Programming   You are to develop a program to read Baseball player statistics from an input...
C++ Programming   You are to develop a program to read Baseball player statistics from an input file. Each player should bestored in a Player object. Therefore, you need to define the Player class. Each player will have a firstname, last name, a position (strings) and a batting average (floating point number). Your class needs to provide all the methods needed to read, write, initialize the object. Your data needs to be stored in an array of player objects. The maximum...
Please use C++. You will be provided with two files. The first file (accounts.txt) will contain...
Please use C++. You will be provided with two files. The first file (accounts.txt) will contain account numbers (10 digits) along with the account type (L:Loan and S:Savings) and their current balance. The second file (transactions.txt) will contain transactions on the accounts. It will specifically include the account number, an indication if it is a withdrawal/deposit and an amount. Both files will be pipe delimited (|) and their format will be the following: accounts.txt : File with bank account info...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT