Site hosted by Angelfire.com: Build your free website today!
Master Menu - Links the Master Page


Columns . . . :                     Edit                         GOLFP/SRCFILE
 SEU==>_______________________________________________________             C03
 FMT C* .....C*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************

 /* Programming Projects 3 © - TEXT FILE INPUT, CALCULATIONS
	   Purpose: Sort a class list and determine the Course
                    ID & class sizes, Smallest & largest Class
		    & Average Class size
             Input: courses.dat	
        Written By: Browning
	      Date: 2/18/99
 */

	#include <stdio.h>

int main (void)

{
	/*Declarations*/
	
	FILE *input_file;

	int testEOF;
	int class_number;
	int student_number;            
	int x = 0;                     /*number of files processed*/
	int students = 0;              /*accumulates total students*/
	int average_class_size = 0;
	int largest_class = 0;         /*class with most students*/
	int smallest_class;            /*class with least students*/
	int Lclass_number = 0;         /*largest class room number*/
	int Sclass_number = 0;         /*smallest class room number*/

input_file = fopen("A:\courses.dat","r");

	if (input_file == NULL)
		{
		printf("\nFile not found");
		return 1;
		}
	else
	 {
	 testEOF = fscanf(input_file, "%i%i", &class_number, &student_number);
	        {
	  while (testEOF != EOF)
		{
		 students += student_number ;     /*accumulate for average students*/
		 x ++ ;
		if (student_number >= largest_class) /*determine largest class size*/
		  {
		  largest_class = student_number ;
		  Lclass_number = class_number;
		  }
	  else if (student_number < smallest_class) /*determine smallest class size*/
		  {
		  smallest_class = student_number ;
		  Sclass_number = class_number ;
		  }
 testEOF = fscanf(input_file, "%i%i", &class_number, &student_number);
	 } /*test for end of file*/
		  average_class_size = students / x ;  /*calculate average students*/

		  printf("\n\nThe largest class is #%i with %i students", Lclass_number, largest_class);
		  printf("\nThe smallest class is #%i with %i students", Sclass_number, smallest_class);
		  printf("\nThe average class size is: %i", average_class_size) ;
			}   /* print the results of the fopen courses.dat */
		}
fclose(input_file);   /*close courses.dat*/
return 0 ;
}


Copyright ©1998 - 2001 J. Browning - All rights reserved.
Master Menu - Links the Master Page