Code:
/*502796P4 - Final Report*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
//#define COMPUTEACH
#define UPDATED "502796nf.dat"
#define MAST_SIZE sizeof(struct MASTER_REC)
void printHeaders(void);
FILE *fp,*u_ptr;
struct MASTER_REC{
char cust_code[6];
char cust_name[21];
char cust_addr[61];
float cust_bal;
long credit_limit;
int year,month,day;
};
#ifdef COMPUTEACH
#define PRINTER "PRN"
#define MAXLINES 30
#include "printer.h"
#else
#define PRINTER "Final Report.dat"
#define MAXLINES 50
#endif
void main()
{
int over=0,recs=0,lines=0;
float TotalVal=0,TotalBal=0;
struct MASTER_REC cust;
double value=0;
#ifdef COMPUTEACH
reset(fp);
set_graph(fp);
#endif
/*Open disk file (New master file)*/
if ((u_ptr = fopen(UPDATED,"rb")) == NULL)
{
fprintf(stdout,"\nError in opening new master");
exit(1);
}
/*Open printer file (This is for The report)*/
if ((fp = fopen(PRINTER,"w")) == NULL)
{
fprintf(stdout,"\nError in opening printer file");
exit(1);
}
printHeaders();
fread(&cust,MAST_SIZE,1,u_ptr);
recs++;
while (!feof(u_ptr))
{
if (cust.cust_bal > cust.credit_limit)
value = cust.cust_bal - cust.credit_limit;
else
value = 0;
if (value > 0)
{
fprintf(fp,"\n %s",cust.cust_code);
fprintf(fp," %10.2f",value);
TotalVal = TotalVal + value; //Show limit value
over++;
}
lines++;
if (lines>MAXLINES)
{
fputc('\f\n', fp);
lines=0;
printHeaders();
}
recs++;
TotalBal = TotalBal + cust.cust_bal;
fread(&cust,MAST_SIZE,1,u_ptr);
}
fprintf(fp,"\n\nRecords processed > %d\n", recs);
fprintf(fp,"Records over Credit limit > %d\n", over);
fprintf(fp,"Excess Credit > %.2f\n",TotalVal);
fprintf(fp,"Grand total balance > %.2f\n",TotalBal);
fclose(fp);
fclose(u_ptr);
}
void printHeaders()
{
#ifdef COMPUTEACH
bold (fp,ON);
#endif
fprintf(fp,"\n%s %s\t\tZenith Paints",__TIME__,__DATE__);
fprintf(fp,"\n\t\t Customers who exceed credit limit\n");
fprintf(fp," Customer Excess Balance\n");
fprintf(fp," Code\n");
#ifdef COMPUTEACH
bold (fp,OFF);
#endif
}