Master Menu - Links the Master Page
Columns . . . : Edit AMOTT/SRCFILE
SEU==>_______________________________________________________ A05
FMT C* .....C*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7
*************** Beginning of data *************************************
/* Programming Project 5 -- Functions
** This program simulates a refinery where six separate processes are read from
** a data file and monitored at each time interval. This program determines
** how many intervals to monitor, and of the 6 pressure readings in each
** interval, determines the highest, lowest, and average pressures of each
** interval. It also prints a DANGER message for overpressures and vacuums.
*/
/*===============================FUNCTIONS======================================
** vacuum_only = Prints data if the only problem is a vacuum.
** over_only = Prints data if the only problem is an overpressure.
** both = Prints data if there is a vacuum and an overpressure.
** neither = Prints data if there is no problem.
*/
/*
By Andrew Worthley
Completed on April 1, 1999 (c)
*/
/*----------------------------------------------------------------------------*/
#include
#include
void clrscr( void ) ;
int main ( void )
{
/*== Declarations ==*/
FILE *input_file ;
void vacuum_only ( int highest, int lowest, int accum, int vac, int count, int interval ) ;
void over_only ( int highest, int lowest, int accum, int over, int count, int interval ) ;
void both ( int highest, int lowest, int accum, int vac, int over, int count, int interval ) ;
void neither ( int highest, int lowest, int accum, int count, int interval ) ;
int interval = 0 ;
int reading = 0 ;
int highest = 0 ;
int lowest = 1000 ;
int accum = 0 ;
int x = 1 ;
int vac = 0 ;
int over = 0 ;
char again[1] = {'y'} ;
int count = 1 ;
int baby = 1 ;
/*== Statements ==*/
input_file = fopen("d:\Pressure.dat", "r") ;
if(input_file == NULL)
{
printf("File not found.\n") ;
return 1 ;
}
else
{
fscanf(input_file, "%i", &interval) ;
}
/* BEGIN MAIN WHILE LOOP */
while(baby == 1 && count <= interval) {
/* READ IN READING LOOP START */
highest = 0 ;
lowest = 1000 ;
vac = 0 ;
over = 0 ;
accum = 0 ;
x = 1 ;
do
{
clrscr() ;
fscanf(input_file, "%i", &reading) ;
accum += reading ;
if(reading > highest)
{
highest = reading ;
over = x ;
}
if(reading < lowest)
{
lowest = reading ;
vac = x ;
}
x++ ;
} while(x < 7) ;
accum = accum / 6 ;
/* END OF READING LOOP */
if(highest > 5000 && lowest >= 14)
{
over_only ( highest, lowest, accum, over, count, interval ) ;
}
else if(highest <= 5000 && lowest < 14)
{
vacuum_only ( highest, lowest, accum, vac, count, interval ) ;
}
else if(highest > 5000 && lowest < 14)
{
both ( highest, lowest, accum, vac, over, count, interval ) ;
}
else if(highest <= 5000 && lowest >= 14)
{
neither ( highest, lowest, accum, count, interval ) ;
}
printf("\nWould you like to see another process? (y or n)") ;
scanf("%s", again) ;
if(again[0] == 'y' || again[0] == 'Y')
{
baby = 1 ;
count++ ;
}
else
{
baby = 3 ;
}
if(count >= interval)
printf("Pressure testing complete.") ;
} /* End Main WHILE loop */
if(baby == 3)
{
printf("Pressure testing complete") ;
}
fclose(input_file) ;
return 0 ;
}
/*=== Function vacuum_only ===*/
void vacuum_only ( int highest, int lowest, int accum, int vac, int count, int interval )
{
printf("Interval %i of %i: DANGER!\n", count, interval) ;
printf("VACUUM OF %i IN PROCESS %i\n", lowest, vac) ;
printf("Highest pressure: %i\n", highest) ;
printf("Lowest pressure: %i\n", lowest) ;
printf("Average pressure: %i\n", accum) ;
}
/*=== Function over_only ===*/
void over_only ( int highest, int lowest, int accum, int over, int count, int interval )
{
printf("Interval %i of %i: DANGER!\n", count, interval) ;
printf("OVERPRESSURE OF %i IN PROCESS %i\n", highest, over) ;
printf("Highest pressure: %i\n", highest) ;
printf("Lowest pressure: %i\n", lowest) ;
printf("Average pressure: %i\n", accum) ;
}
/*=== Function both ===*/
void both ( int highest, int lowest, int accum, int vac, int over, int count, int interval )
{
printf("Interval %i of %i: DANGER!\n", count, interval) ;
printf("OVERPRESSURE OF %i IN PROCESS %i\n", highest, over) ;
printf("VACUUM OF %i IN PROCESS %i\n", lowest, vac) ;
printf("Highest pressure: %i\n", highest) ;
printf("Lowest pressure: %i\n", lowest) ;
printf("Average pressure: %i\n", accum) ;
}
/*=== Function neither ===*/
void neither ( int highest, int lowest, int accum, int count, int interval )
{
printf("Interval %i of %i:\n", count, interval) ;
printf("Highest pressure: %i\n", highest) ;
printf("Lowest pressure: %i\n", lowest) ;
printf("Average pressure: %i\n", accum) ;
}
/* End of Source */
Copyright ©1998 - 2001 J. Browning - All rights reserved.
Master Menu - Links the Master Page