FILE: / SET COUNTERS TO ZERO / SUMMARY FILE
-name / OPEN INPUT FILE / -COUNT GREEN PLAIN
-color(R/G) / OPEN SUMMARY FILE / -COUNT GREEN NUT
-core(P/N) / OPEN GREEN NUT EXPIRED REPORT / -RED PLAIN
-Year expire / WRITE TITLE & HEADINGS / -RED NUT
OPEN RED NUT EXPIRED REPORT
WRITE TITLE & HEADINGS / GREEN NUT EXPIRED
READ RECORD / -NAME
CALC CATEGORY / -YEAR expired
WRITE TO EXPIRED REPORT
WRITE SUMMARY REPORT / RED NUT EXPIRED
CLOSE FILES / -NAME
-YEAR expired
SOURCE CODE
<?php
// file input vars
$name = "";
$color = ""; // CODES: G/R
$core = ""; // CODES: N/P
$expire = 0;
// calculation vars
$redNutCount = 0;
$greenNutCount = 0;
$redPlainCount = 0;
$greenPlainCount = 0;
$fin = fopen("mm.txt", "r") or die("NO MMS FOR YOU!");
$fsum = fopen("summary.txt", "w") or die("ERROR OPEN SUMMARY");
fprintf( $fsum,"\n SUMMARY REPORT\n");
$fgne = fopen("GreenNutExpire.txt", "w") or die("ERROR OPEN Green Nut Expire");
fprintf( $fgne,"\n Green Nut Expire Report\n");
fprintf( $fgne,"\nName Year Expired\n");
$frne = fopen("RedNutExpire.txt", "w") or die("ERROR OPEN Red Nut Expire");
fprintf( $frne,"\n Red Nut Expire Report\n");
fprintf( $frne,"\nName Year Expired\n");
fscanf($fin, "%s%s%s%d", $name, $color, $core, $expire);
while( !feof($fin) )
{
//printf( "\n%s %s %s %d", $name, $color, $core, $expire);
if($color == "G") // I AM GREEN
{
// printf("\n I AM GREEN");
if($core == "N") // I AM GREEN AND NUT
{
// printf("\n I AM GREEN AND NUT");
$greenNutCount = $greenNutCount + 1;
if($expire < 2014)
{
fprintf( $fgne,"\n%-10s%7d", $name, $expire);
}
}
else // I AM GREEN AND PLAIN
{
// printf("\n I AM GREEN AND PLAIN");
$greenPlainCount = $greenPlainCount + 1;
}
}
else // I AM RED
{
// printf("\n I AM RED");
if($core == "N") // I AM RED AND NUT
{
// printf("\n I AM RED AND NUT");
$redNutCount= $redNutCount + 1;
if($expire < 2014)
{
fprintf( $frne,"\n%-10s%7d", $name, $expire);
}
}
else // I AM RED AND PLAIN
{
// printf("\n I AM RED AND PLAIN");
$redPlainCount = $redPlainCount + 1;
}
}
fscanf($fin, "%s%s%s%d", $name, $color, $core, $expire);
}
fprintf($fsum,"\nRed Nut Count: %d", $redNutCount);
fprintf($fsum,"\nGreen Nut Count: %d", $greenNutCount);
fprintf($fsum,"\nRed Plain Count: %d", $redPlainCount);
fprintf($fsum,"\nGreen Plain Count: %d", $greenPlainCount);
fclose($fin);
fclose($fsum);
fclose($fgne);
fclose($frne);
fscanf(STDIN, "%s", $buster);
?>
DESK CHECK
INCOMING DATA:
Sally R N 2009
EOF
MEMORY MAP
Line# / name / color / core / expire / redNut / greenNut / redPlain / greenPlain3 / “”
4 / “”
5 / “”
6 / 0
9 / 0
10 / 0
11 / 0
12 / 0
28 / sally / R / N / 2009
56 / 1
OUTPUT:
Summary.txt
SUMMARY REPORT
Red Nut Count: 1
Green Nut Count: 0
Red Plain Count: 0
Green Plain Count: 0
GreenNutExpire.txt
Green Nut Expire Report
Name Year Expired
RedNutExpire.txt
Red Nut Expire Report
Name Year Expired
Sally 2009
LOGIC:
29) while( !feof($fin) ) - true
32) if( “R” == "G") - false
53) if(“N” == "N") - true
57) if(2009 < 2014) - true
29) while( !feof($fin) ) - false