This is the program. Re-using the tuition calculations from Lab1, and write a program to do the following:
Read student classifications and numbers of units from the data file LAB2IN.TXT. (No error
checking of data read from input file is required.) Then write each student's resulting tuition to a
second data output file, LAB2OUT.TXT.
As each tuition is computed, save it in one of two arrays for further processing at the end of the
program. The first array will hold the tuition paid by undergraduate students, and the second will
hold the tuition paid by graduate students. There will be no more than 100 students of either
type, and there may be only one type in the file.
After ALL of the tuitions have been computed, use the data in the arrays to calculate the low, high,
and average tuition paid by undergraduate students and the low, high, and average taxes paid by
graduate students (Do NOT compute the sums or any other part of the low, high, and averages until
AFTER all tuitions have been computed and placed in the arrays). Display the results to the
screen, along with a count of the type of student, as follows (same format for graduate students):
For 21 undergraduate students:
Lowest tuition paid = $ 750.00
Highest tuition paid = $ 5100.00
Average tuition paid = $ 4566.12
Break the program into functions. Include at least the following functions:
Read one student’s classification
Compute one tuition Compute the low/high/average tuition paid
Write one result to the file Display the low/high/average tuition paid
Input: File LAB2IN.TXT format is one line per tuition paying student, as follows:
Classification: character (uppercase U or G)
Units: positive integer
Sample Lines: U 20
G 9
NOTE: You will have to create your own sample data file to test this program, but
you instructor will use one of his/her own creation
The first issues is with the funcation. Not to sure how i would set them up. I'm use to pascal where i can write a funcation and it does that and its call from the main program. But Im a little lost on this one. becasue what I have written dose not look right.
/*****************************************
File Name: Tmitchellwk2
Description: Calcutaing tuition based on Classification and number of
credits
Date: 7/18/06
Desinger: Tabatha Mithcell
Functions: Input, output
*****************************************/#include <stdio.h>
main ()
{
#define flatfeeone 500.00 /*flat rate for up to 6 credits*/
#define Flatfeeu 450.00 /*rate for undergrad rate for 6 to 12
credits*/
#define Flatfeeg 750.00 /*rate for graduate for 6 to 12 credits*/
#define flatunit 250.00 /*rate for fee per credit up to 6 credits*/
#define Flatunitu 245.00 /*rate for undergrate for 6-12 credits*/
#define Flatunitg 285.00 /*rate for graduate for 6-12 credits*/
#define Flatpuu 270.00 /*rate for undgrade for 12-18 credits*/
#define Flatgu 340.00 /*rate for graduate for 12-18 credit*/
#define Flatu 5100.00 /*rate for undgrade for 18 or more credits*/
#define Flatg 6400.00 /*rate for graduate for 18 or more credits*/
int credits; /*number of credits the person is taking*/
int datain; /*funstion to get data from file.
char status; /*Student status (G,g-Grad or U,u-Undergrad)*/
FILE *indate, *outdata; //Input file
Function Datain;
indata = fopen ("C.\\LAB2IN.txt", "r");
if (fopen == Null)
printf ("Error openeing file\n);
else
print ("Status and Grades read from file:\n");
while (fscan (fin, "%c", &status) != EOF){//READ ONE STATUS
print ("t%c\n", status);
if ( (status == 'g') || (status == 'G') ) //stating the calculations for grad
{
if ( (credits > 0) && (credits <= 6) )
cost = flatfeeone + (credits * flatunit);
if ((credits > 6) && (credits <= 12))
cost = Flatfeeg + (credits *Flatunitg);
if ((credits > 12) && (credits <=18))
cost = Flatgu * credits;
if (credits > 18)
cost = Flatg;
}
else if ((status == 'u') || (status == 'U')) //starting the calculations for undergrad
{
if ( (credits > 0) && (credits <= 6))
cost = flatfeeone + (credits * flatunit);
if ( (credits > 6) && (credits <= 12))
cost = Flatfeeu + (credits *Flatunitu);
if ( (credits > 12 ) && (credits <= 18))
cost = Flatpuu * credits;
if (credits > 18)
cost = Flatu;
}
datain;
getchar();
getchar();
return 0;
}