PHP File Processing
Assignment Description
Complete the PHP program named project3.php
. This file program has a main
function that prompts the user for an input file name and an output file name; there is a comment indicating where to start the implementation of your solution. The program should have the following general outline:
Read the contents of the input file (the main function checks if the file exists, so you do not need to check that.)
Transform the data into a different format.
Write the transformed data to the output file.
There is an input file named animals.dat
included in the handout directory. This file has four lines for; the lines of data will contain the following information, in this order:
- Common name
- Class (mammal, bird, fish, reptile, amphibian)
- Conservation status code
- EX: extinct
- EW: Extinct in the wild
- CR: critically endangered
- EN: endangered
- VU: vulnerable
- NT: near threatened
- LC: least concern
- DD: data deficient
- NE: not evaluated
- Number of the animal at ten different zoos, each number separated by a space.
The expected output file format is as follows:
The first line of the file must be:
Animal,Class,Status,Total
Each animal has one line in the output file of the following form:
<animal name>,<animal class>,<status code>,<total number>
where the first three values are from the input file directly and the last value is the sum total population of the given animal among all zoos.
The rows must be sorted according to the highest population to the lowest population. If there are more than one animal with the same total population, then arbitrarily choose which one comes first.
Instructions
To start the assignment, login to your university Linux account and copy the assignment code to a location somewhere under your home directory. The assignment code is located at:
/export/home/public/schwesin/csc242/projects/project3-handout
You need to edit the project3.php
file. Do not change the names of the file.
To submit your assignment, execute the following command from within your project3-handout
directory:
~schwesin/bin/submit csc242 project3
Grading Criteria
Concise, accurate documentation following the CSC Department documentation guidelines
Modular design.
Correct implementation of the specification
Note: If the code has syntax errors or does not execute properly, you will receive a failing grade for this assignment. If the submission includes material that was not covered in class and the material is not properly cited, then you will receive a failing grade for this assignment.
Appendix
Expected contents of the output file for the given animals.dat
file:
Animal,Class,Status,Total
African penguin,bird,EN,39
Western lowland gorilla,mammal,CR,33
Massi giraffe,mammal,VU,20
Scimitar-horned oryx,mammal,EW,20
Grants zebra,mammal,LC,20
Dart frog,amphibian,LC,19
Red kangaroo,mammal,LC,19
Black-capped lorikeet,bird,LC,17
Saddle-billed stork,bird,LC,13
Emu,bird,LC,12
African spurred tortoise,reptile,LC,9
Tammar wallaby,mammal,LC,9
Aardvark,mammal,LC,9
Gila monster,reptile,NT,8
Northern bald eagle,bird,LC,8
White rhino,mammal,NT,7
Blue-throated macaw,bird,EN,6
Tropical forest snake,reptile,VU,5
Loggerhead sea turtle,reptile,VU,4
Wyoming Toad,amphibian,EW,3
Chinese alligator,reptile,EN,2