#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#define MAX=10;
void war_func();
void enter_view();
void shows();
int date();
void screen();
void start();
void add();
void del();
void empty();
void search();
void modify();
void input();
void view();
void rate1();
void rate2();
void rate3();
int duplicate(unsigned long int);
void getinput(float*);
void getint(int *y);
void getprh(int *p);
void getld(unsigned long *p);
int i,j;
float rate;
char ch;
struct add
{
unsigned long int car_id;
int day;
int mon;
int year;
float sum_rate;
float quantity;
int fuel;
}
y;
struct
{ float ch1,ch2,ch3;
}
z;
struct date d;
main()
{
window(1,1,80,25);
textbackground(WHITE);
clrscr();
window(5,3,75,17);
textbackground(BLACK);
clrscr();
window(7,4,73,16);
textbackground(WHITE);
textcolor(4);
clrscr();
gotoxy(2,1);
printf("\t\t [ Gas-Station Management System ]");
gotoxy(2,2);
printf("\n\t\t² First Enter Daily Prices for Fuels ¯¯¯ ²\n");
printf("\n\n\n\n\n\n\n\tPress any key to Continue.........");
getch();
window(1,1,80,25);
textbackground(15);
{ rate1();
rate2();
rate3();
}
start();
return 0;
}
void start()
{ do
{ window(1,1,80,25);
textbackground(WHITE);
clrscr();
window(5,3,75,17);
textbackground(BLACK);
clrscr();
window(7,4,73,16);
textbackground(WHITE);
textcolor(4);
clrscr();
gotoxy(2,1);
printf(" [ Gas-Station Management System ]");
gotoxy(2,2);
printf(" ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±\n");
printf("\t ² ²\n");
printf("\t1.² Enter a new Bill ¯¯¯ ²\n");
printf("\t2.² View recorded Bills ¯¯¯ ²\n");
printf("\t3.² Modify any Bill ¯¯¯ ²\n");
printf("\t4.² Search for Bills ¯¯¯ ²\n");
printf("\t5.² Delete recorded Bills ¯¯¯ ²\n");
printf("\t6.² Change daily prices ¯¯¯ ²\n");
printf("\t7.² Exit program ¯¯¯ ²\n");
printf("\t ²±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±\n");
printf("\t \t Please Enter a number from the above menu: ");
getint(&i);
window(1,1,80,25);
textbackground(15);
if(i>7||i==0)
{ war_func();
clrscr();
}
else if(i==5)
{ del();
}
else if(i==3)
{ modify();
}
else if(i==4)
{ search();
}
else if(i==1)
{ input();
}
else if(i==6)
{ main();
} else if(i==2)
{ enter_view();
} } while(i!=7);
clrscr();
printf("\n\n\n\n\n\n\n\n\tAuthor : www.sourcecodernp.blogspot.com\n");
printf("\tProject : Gas-station Management System\n");
printf("\tLanguage : C\n");
printf("\tPurpose : CIE IGCSE Computer-Studies Coursework\n\n\n\n");
printf("\n\n\n\t\tEXITING IN 3 SECONDS...");
delay(3500);
// return 0;
}
void war_func()
{ clrscr();
window(5,3,75,17);
textbackground(BLACK);
clrscr();
window(7,4,73,16);
textbackground(WHITE);
textcolor(4);
clrscr();
gotoxy(12,5);
printf("Warning! Invalid Input...Press any key!");
getch();
clrscr();
}
void del()
{ FILE *fp;
unsigned long car_id1;
screen();
fp=fopen("Bills.rec","rb+");
gotoxy(2,2);
cprintf("Enter Receipt number for Deletion: ");
getld(&car_id1);
while(fread(&y,sizeof(y),1,fp) && car_id1!=y.car_id );
if((car_id1==y.car_id)&&(y.car_id!=0))
{ shows();
do
{ gotoxy(2,6); printf("Delete this record (Y/N) : ");
fflush(stdin);
ch=toupper(getch());
} while(ch!='Y'&& ch!='N');
if(ch=='Y')
{ empty();
fseek(fp,ftell(fp)-sizeof(y),0);
fwrite(&y,sizeof(y),1,fp);
clrscr();
gotoxy(22,3);
printf("Record has been Deleted.");
gotoxy(20,6);
printf("Press any key to continue....");
getch();
window(1,1,80,25);
textbackground(WHITE);
clrscr();
fclose(fp); }
else if (ch=='N')
{ fclose(fp);
window(1,1,80,25);
textbackground(WHITE);
clrscr();
start();
} } else
{ gotoxy(2,7);
printf("Record not found..");
getch();
window(1,1,80,25);
textbackground(WHITE);
clrscr();
}
fclose(fp);
}
void view()
{ FILE *fp;
clrscr();
fp=fopen("Bills.rec","rb");
while(fread(&y,sizeof(y),1,fp)!=NULL)
{
if((y.day!=0)&&(y.car_id!=0))
{
do
{ screen();
gotoxy(2,4); printf(" ");
shows();
gotoxy(2,4); printf("Press "" Y "" to view next record-------¯¯");
gotoxy(2,6); printf("Continue (Y/N) : ");
ch=toupper(getch());
} while(ch!='Y'&& ch!='N');
if(ch== 'N')
{ fclose(fp);
enter_view();
} } }
fclose(fp);
}
void modify()
{ FILE *fp;
unsigned long car_id1;
clrscr();
window(4,4,74,12);
textbackground(BLACK);
clrscr();
window(5,5,73,11);
textbackground(WHITE);
clrscr();
fp=fopen("Bills.rec","rb+");
gotoxy(2,2); cprintf("Enter Receipt number to modify: ");
getld( &car_id1 );
while( fread(&y,sizeof(y),1,fp) && car_id1!=y.car_id );
if((car_id1==y.car_id) &&(y.car_id!=0))
{ shows();
do
{ gotoxy(2,7);
printf("Continue to modify (Y/N) : ");
fflush(stdin);
ch=toupper(getch());
} while(ch!='Y'&& ch!='N');
if(ch=='Y')
{
window(1,1,80,25);
clrscr();
textbackground(WHITE);
clrscr();
window(5,3,75,17);
textbackground(BLACK);
clrscr();
window(7,4,73,16);
textbackground(WHITE);
textcolor(4);
clrscr();
gotoxy(18,1);
printf(" Modify Record MENU ");
gotoxy(1,2);
printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
gotoxy(3,3);
printf("Receipt Number: %ld",y.car_id);
getdate(&d);
gotoxy(35,3);
printf("Date (DD M YYYY): %d %d %d ",d.da_day,d.da_mon,d.da_year);
y.day = d.da_day;
y.mon = d.da_mon;
y.year= d.da_year;
gotoxy(1,4); printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
do
{ gotoxy(3,5);
printf("Enter Quantity (Litres): ");
getinput(&y.quantity);
} while(y.quantity==0);
gotoxy(3,7);
printf("Enter fuel type:");
gotoxy(3,8);
printf("Press 1: Petrol or 2: Diesel or 3: CNG: ");
getprh(&y.fuel);
gotoxy(2,8); printf(" ");
switch(y.fuel)
{ case 1:
gotoxy(20,7);
printf("Petrol ");
rate=z.ch1;
break;
case 2:
gotoxy(20,7);
printf("Diesel ");
rate=z.ch2;
break;
case 3:
gotoxy(20,7);
printf("CNG");
rate=z.ch3;
break;
} y.sum_rate=rate*y.quantity;
gotoxy(1,8);
printf("-------------------------------------------------------------------");
gotoxy(20,9);
printf("Payment Bill in Rupees: %2.2f\n ",y.sum_rate);
gotoxy(1,11);
printf("±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±");
gotoxy(5,13);
printf("Record Modified--------->");
gotoxy(35,13);
printf("Press any key to continue...");
fseek(fp,ftell(fp)-sizeof(y),0);
fwrite(&y,sizeof(y),1,fp);
fclose(fp);
getch();
window(1,1,80,25);
textbackground(WHITE);
}
else if (ch=='N');
{ fclose(fp);
window(1,1,80,25);
textbackground(WHITE);
start();
}} else
{ gotoxy(2,7);
printf("Record not found..");
getch();
window(1,1,80,25);
textbackground(WHITE);
clrscr();
} }
void search()
{
FILE *fp;
unsigned long car_id1;
screen();
fp=fopen("Bills.rec","rb");
gotoxy(2,2);
cprintf("Enter Receipt number for search: ");
getld(&car_id1);
while(fread(&y,sizeof(y),1,fp) && car_id1!=y.car_id );
if((car_id1==y.car_id)&&(y.car_id!=0))
{ shows();
getch();
window(1,1,80,25);
textbackground(WHITE);
}
else
{
gotoxy(2,7);
printf("Record not found..");
getch();
window(1,1,80,25);
textbackground(WHITE);
clrscr();
fclose(fp);
}
}
void add()
{ unsigned long temp;
int getinp;
clrscr();
textbackground(WHITE);
clrscr();
window(5,3,75,17);
textbackground(BLACK);
clrscr();
window(7,4,73,16);
textbackground(WHITE);
textcolor(4);
clrscr();
gotoxy(19,1);
printf(" [ ADD Record MENU ] ");
gotoxy(1,2);
printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
do{ gotoxy(3,3);
printf(" ");
gotoxy(3,3);
printf("Receipt Number: ");
getld(&temp);
gotoxy(3,5);
printf("Already Exists ! ");
} while(duplicate(temp));
y.car_id = temp;
getdate(&d);
gotoxy(35,3);
printf("Date (DD M YYYY): %d %d %d ",d.da_day,d.da_mon,d.da_year);
y.day = d.da_day;
y.mon = d.da_mon;
y.year= d.da_year;
gotoxy(1,4);
printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
do
{
gotoxy(3,5);
printf("Enter Quantity (Litres): ");
scanf("%d",&y.quantity);
}
while(y.quantity==0);
gotoxy(3,7);
printf("Enter fuel type:");
gotoxy(3,8);
printf("Press 1: Petrol or 2: Diesel or 3: CNG: ");
getprh(&y.fuel);
gotoxy(2,8);
printf(" ");
switch(y.fuel)
{
case 1:
gotoxy(20,7);
printf("Petrol ");
rate=z.ch1;
break;
case 2:
gotoxy(20,7);
printf("Diesel ");
rate=z.ch2;
break;
case 3:
gotoxy(20,7);
printf("CNG");
rate=z.ch3;
break;
default:
gotoxy(20,7);war_func();
break;
} y.sum_rate=rate*y.quantity;
gotoxy(1,8);
printf("-------------------------------------------------------------------");
gotoxy(20,9);
printf("Payment Bill in Rupees: %2.2f ",y.sum_rate);
gotoxy(1,10);
printf("±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±");
}
void input()
{
FILE *fp;
char ch;
do {
fp=fopen("Bills.rec","ab");
add();
fwrite(&y,sizeof(y),1,fp);
gotoxy(22,12);
printf("ADD more records (Y/N): ");
fclose(fp);
ch=toupper(getch());
} while (ch=='Y');
}
void rate1()
{ screen();
gotoxy(5,2);
printf("Enter the daily amount for Petrol: ");
getinput(&z.ch1);
} void rate2()
{
gotoxy(5,4);
printf("Enter the daily amount for Diesel: ");
getinput(&z.ch2);
}
void rate3()
{
gotoxy(5,6);
printf("Enter the daily amount for CNG: ");
getinput(&z.ch3);
window(1,1,80,25);
textbackground(WHITE);
clrscr();
}
void getinput(float *y)
{
char x[10];
int n=0;
do
{
do{ ch=getch();
if(((ch>='0'&&ch<='9')||(ch=='.')) &&(n<10))
{ x[n]=ch;
n++;
printf("%c",ch);
}
else if(ch==8&&n>0)
{
printf("%c%c%c",8,32,8);
n--;
}} while( ch!=13 && n<10 );
x[n]='\0';
*y=atof(x);
} while(ch!=13);
}
void getint(int *u)
{ char x[10];
int n=0;
do{
do{
ch=getch();
if(((ch>='1'&&ch<='7')||(ch=='.')) &&(n<10-4))
{
x[n]=ch;
n++;
printf("%c",ch);
}
else if(ch==8&&n>0)
{ printf("%c%c%c",8,32,8);
n--; }
} while(ch!=13&&n<10);
x[n]='\0';
*u=atoi(x);
} while(ch!=13);
}
void getprh(int *p)
{ char x[10];
int n=0;
do{
do{ ch=toupper(getch());
if((ch=='1'|| ch=='2'|| ch=='3') &&(n<10-4))
{ x[n]=ch;
n++;
printf("%c",ch);
} else
if(ch==8&&n>0)
{ printf("%c%c%c",8,32,8);
n--;
} } while(ch!=13&&n<10);
x[n]='\0';
*p=atoi(x);
} while(ch!=13);
}
void getld(unsigned long *p)
{
char x[10];
int n=0;
do{
do{
ch=toupper(getch());
if((ch>='0'&& ch<='9') &&(n<10))
{ x[n]=ch;
n++;
printf("%c",ch);
}
else
if(ch==8&&n>0)
{ printf("%c%c%c",8,32,8);
n--; }
} while(ch!=13&&n<10);
x[n]='\0';
*p=atol(x);
}while(ch!=13);
}
void empty()
{ y.car_id=0;
y.fuel=0;
y.day=0;
y.mon=0;
y.year=0;
y.sum_rate=0;
y.quantity=0;
} void enter_view()
{ int u;
screen();
gotoxy(3,2);
printf("[1] View the records ¯¯¯");
gotoxy(3,4);
printf("[2] Go to main menu ¯¯¯ ");
gotoxy(10,6);
printf("Enter your choice : ");
getint(&u);
if(u==1)
view();
if(u==2)
{ window(1,1,80,25);
textbackground(WHITE);
clrscr();
start();
}
}int duplicate(unsigned long int rno)
{
FILE *fp;
fp=fopen("Bills.rec","rb");
while(fread(&y, sizeof(y), 1, fp) && rno != y.car_id);
fclose(fp);
if((rno == y.car_id)||(rno==0))
return 1;
else
return 0;
}
void shows()
{
gotoxy(2,2);
printf(" ");
gotoxy(2,4);
printf("Record found------------------------¯¯\n");
gotoxy(41,1);
printf("±±±±±±±±±±±±±±±±±±±±±±±±±±±±");
gotoxy(41,2);
printf("Receipt #: %ld",y.car_id);
gotoxy(41,3);
printf("Quantity : %2.2f",y.quantity);
printf(" litres");
gotoxy(41,4);
printf("Payment : %2.2f",y.sum_rate);
printf(" Rs");
gotoxy(41,5);
printf(" Fuel type: %d",y.fuel);
if(y.fuel==1)
{
gotoxy(53,5);
printf(" Petrol");
}
else if(y.fuel==2)
{
gotoxy(53,5);
printf(" Diesel"); }
else
{ gotoxy(53,5);
printf(" CNG");
} gotoxy(41,6);
printf("Date : %d-%d-%d", y.day,y.mon,y.year);
gotoxy(41,7);
printf("±±±±±±±±±±±±±±±±±±±±±±±±±±±±");
}
void screen()
{
window(1,1,80,25);
textbackground(WHITE);
clrscr();
window(4,4,74,12);
textbackground(BLACK);
clrscr();
window(5,5,73,11);
textcolor(4);
textbackground(WHITE);
clrscr();
}
#include<conio.h>
#include<dos.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#define MAX=10;
void war_func();
void enter_view();
void shows();
int date();
void screen();
void start();
void add();
void del();
void empty();
void search();
void modify();
void input();
void view();
void rate1();
void rate2();
void rate3();
int duplicate(unsigned long int);
void getinput(float*);
void getint(int *y);
void getprh(int *p);
void getld(unsigned long *p);
int i,j;
float rate;
char ch;
struct add
{
unsigned long int car_id;
int day;
int mon;
int year;
float sum_rate;
float quantity;
int fuel;
}
y;
struct
{ float ch1,ch2,ch3;
}
z;
struct date d;
main()
{
window(1,1,80,25);
textbackground(WHITE);
clrscr();
window(5,3,75,17);
textbackground(BLACK);
clrscr();
window(7,4,73,16);
textbackground(WHITE);
textcolor(4);
clrscr();
gotoxy(2,1);
printf("\t\t [ Gas-Station Management System ]");
gotoxy(2,2);
printf("\n\t\t² First Enter Daily Prices for Fuels ¯¯¯ ²\n");
printf("\n\n\n\n\n\n\n\tPress any key to Continue.........");
getch();
window(1,1,80,25);
textbackground(15);
{ rate1();
rate2();
rate3();
}
start();
return 0;
}
void start()
{ do
{ window(1,1,80,25);
textbackground(WHITE);
clrscr();
window(5,3,75,17);
textbackground(BLACK);
clrscr();
window(7,4,73,16);
textbackground(WHITE);
textcolor(4);
clrscr();
gotoxy(2,1);
printf(" [ Gas-Station Management System ]");
gotoxy(2,2);
printf(" ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±\n");
printf("\t ² ²\n");
printf("\t1.² Enter a new Bill ¯¯¯ ²\n");
printf("\t2.² View recorded Bills ¯¯¯ ²\n");
printf("\t3.² Modify any Bill ¯¯¯ ²\n");
printf("\t4.² Search for Bills ¯¯¯ ²\n");
printf("\t5.² Delete recorded Bills ¯¯¯ ²\n");
printf("\t6.² Change daily prices ¯¯¯ ²\n");
printf("\t7.² Exit program ¯¯¯ ²\n");
printf("\t ²±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±\n");
printf("\t \t Please Enter a number from the above menu: ");
getint(&i);
window(1,1,80,25);
textbackground(15);
if(i>7||i==0)
{ war_func();
clrscr();
}
else if(i==5)
{ del();
}
else if(i==3)
{ modify();
}
else if(i==4)
{ search();
}
else if(i==1)
{ input();
}
else if(i==6)
{ main();
} else if(i==2)
{ enter_view();
} } while(i!=7);
clrscr();
printf("\n\n\n\n\n\n\n\n\tAuthor : www.sourcecodernp.blogspot.com\n");
printf("\tProject : Gas-station Management System\n");
printf("\tLanguage : C\n");
printf("\tPurpose : CIE IGCSE Computer-Studies Coursework\n\n\n\n");
printf("\n\n\n\t\tEXITING IN 3 SECONDS...");
delay(3500);
// return 0;
}
void war_func()
{ clrscr();
window(5,3,75,17);
textbackground(BLACK);
clrscr();
window(7,4,73,16);
textbackground(WHITE);
textcolor(4);
clrscr();
gotoxy(12,5);
printf("Warning! Invalid Input...Press any key!");
getch();
clrscr();
}
void del()
{ FILE *fp;
unsigned long car_id1;
screen();
fp=fopen("Bills.rec","rb+");
gotoxy(2,2);
cprintf("Enter Receipt number for Deletion: ");
getld(&car_id1);
while(fread(&y,sizeof(y),1,fp) && car_id1!=y.car_id );
if((car_id1==y.car_id)&&(y.car_id!=0))
{ shows();
do
{ gotoxy(2,6); printf("Delete this record (Y/N) : ");
fflush(stdin);
ch=toupper(getch());
} while(ch!='Y'&& ch!='N');
if(ch=='Y')
{ empty();
fseek(fp,ftell(fp)-sizeof(y),0);
fwrite(&y,sizeof(y),1,fp);
clrscr();
gotoxy(22,3);
printf("Record has been Deleted.");
gotoxy(20,6);
printf("Press any key to continue....");
getch();
window(1,1,80,25);
textbackground(WHITE);
clrscr();
fclose(fp); }
else if (ch=='N')
{ fclose(fp);
window(1,1,80,25);
textbackground(WHITE);
clrscr();
start();
} } else
{ gotoxy(2,7);
printf("Record not found..");
getch();
window(1,1,80,25);
textbackground(WHITE);
clrscr();
}
fclose(fp);
}
void view()
{ FILE *fp;
clrscr();
fp=fopen("Bills.rec","rb");
while(fread(&y,sizeof(y),1,fp)!=NULL)
{
if((y.day!=0)&&(y.car_id!=0))
{
do
{ screen();
gotoxy(2,4); printf(" ");
shows();
gotoxy(2,4); printf("Press "" Y "" to view next record-------¯¯");
gotoxy(2,6); printf("Continue (Y/N) : ");
ch=toupper(getch());
} while(ch!='Y'&& ch!='N');
if(ch== 'N')
{ fclose(fp);
enter_view();
} } }
fclose(fp);
}
void modify()
{ FILE *fp;
unsigned long car_id1;
clrscr();
window(4,4,74,12);
textbackground(BLACK);
clrscr();
window(5,5,73,11);
textbackground(WHITE);
clrscr();
fp=fopen("Bills.rec","rb+");
gotoxy(2,2); cprintf("Enter Receipt number to modify: ");
getld( &car_id1 );
while( fread(&y,sizeof(y),1,fp) && car_id1!=y.car_id );
if((car_id1==y.car_id) &&(y.car_id!=0))
{ shows();
do
{ gotoxy(2,7);
printf("Continue to modify (Y/N) : ");
fflush(stdin);
ch=toupper(getch());
} while(ch!='Y'&& ch!='N');
if(ch=='Y')
{
window(1,1,80,25);
clrscr();
textbackground(WHITE);
clrscr();
window(5,3,75,17);
textbackground(BLACK);
clrscr();
window(7,4,73,16);
textbackground(WHITE);
textcolor(4);
clrscr();
gotoxy(18,1);
printf(" Modify Record MENU ");
gotoxy(1,2);
printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
gotoxy(3,3);
printf("Receipt Number: %ld",y.car_id);
getdate(&d);
gotoxy(35,3);
printf("Date (DD M YYYY): %d %d %d ",d.da_day,d.da_mon,d.da_year);
y.day = d.da_day;
y.mon = d.da_mon;
y.year= d.da_year;
gotoxy(1,4); printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
do
{ gotoxy(3,5);
printf("Enter Quantity (Litres): ");
getinput(&y.quantity);
} while(y.quantity==0);
gotoxy(3,7);
printf("Enter fuel type:");
gotoxy(3,8);
printf("Press 1: Petrol or 2: Diesel or 3: CNG: ");
getprh(&y.fuel);
gotoxy(2,8); printf(" ");
switch(y.fuel)
{ case 1:
gotoxy(20,7);
printf("Petrol ");
rate=z.ch1;
break;
case 2:
gotoxy(20,7);
printf("Diesel ");
rate=z.ch2;
break;
case 3:
gotoxy(20,7);
printf("CNG");
rate=z.ch3;
break;
} y.sum_rate=rate*y.quantity;
gotoxy(1,8);
printf("-------------------------------------------------------------------");
gotoxy(20,9);
printf("Payment Bill in Rupees: %2.2f\n ",y.sum_rate);
gotoxy(1,11);
printf("±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±");
gotoxy(5,13);
printf("Record Modified--------->");
gotoxy(35,13);
printf("Press any key to continue...");
fseek(fp,ftell(fp)-sizeof(y),0);
fwrite(&y,sizeof(y),1,fp);
fclose(fp);
getch();
window(1,1,80,25);
textbackground(WHITE);
}
else if (ch=='N');
{ fclose(fp);
window(1,1,80,25);
textbackground(WHITE);
start();
}} else
{ gotoxy(2,7);
printf("Record not found..");
getch();
window(1,1,80,25);
textbackground(WHITE);
clrscr();
} }
void search()
{
FILE *fp;
unsigned long car_id1;
screen();
fp=fopen("Bills.rec","rb");
gotoxy(2,2);
cprintf("Enter Receipt number for search: ");
getld(&car_id1);
while(fread(&y,sizeof(y),1,fp) && car_id1!=y.car_id );
if((car_id1==y.car_id)&&(y.car_id!=0))
{ shows();
getch();
window(1,1,80,25);
textbackground(WHITE);
}
else
{
gotoxy(2,7);
printf("Record not found..");
getch();
window(1,1,80,25);
textbackground(WHITE);
clrscr();
fclose(fp);
}
}
void add()
{ unsigned long temp;
int getinp;
clrscr();
textbackground(WHITE);
clrscr();
window(5,3,75,17);
textbackground(BLACK);
clrscr();
window(7,4,73,16);
textbackground(WHITE);
textcolor(4);
clrscr();
gotoxy(19,1);
printf(" [ ADD Record MENU ] ");
gotoxy(1,2);
printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
do{ gotoxy(3,3);
printf(" ");
gotoxy(3,3);
printf("Receipt Number: ");
getld(&temp);
gotoxy(3,5);
printf("Already Exists ! ");
} while(duplicate(temp));
y.car_id = temp;
getdate(&d);
gotoxy(35,3);
printf("Date (DD M YYYY): %d %d %d ",d.da_day,d.da_mon,d.da_year);
y.day = d.da_day;
y.mon = d.da_mon;
y.year= d.da_year;
gotoxy(1,4);
printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
do
{
gotoxy(3,5);
printf("Enter Quantity (Litres): ");
scanf("%d",&y.quantity);
}
while(y.quantity==0);
gotoxy(3,7);
printf("Enter fuel type:");
gotoxy(3,8);
printf("Press 1: Petrol or 2: Diesel or 3: CNG: ");
getprh(&y.fuel);
gotoxy(2,8);
printf(" ");
switch(y.fuel)
{
case 1:
gotoxy(20,7);
printf("Petrol ");
rate=z.ch1;
break;
case 2:
gotoxy(20,7);
printf("Diesel ");
rate=z.ch2;
break;
case 3:
gotoxy(20,7);
printf("CNG");
rate=z.ch3;
break;
default:
gotoxy(20,7);war_func();
break;
} y.sum_rate=rate*y.quantity;
gotoxy(1,8);
printf("-------------------------------------------------------------------");
gotoxy(20,9);
printf("Payment Bill in Rupees: %2.2f ",y.sum_rate);
gotoxy(1,10);
printf("±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±");
}
void input()
{
FILE *fp;
char ch;
do {
fp=fopen("Bills.rec","ab");
add();
fwrite(&y,sizeof(y),1,fp);
gotoxy(22,12);
printf("ADD more records (Y/N): ");
fclose(fp);
ch=toupper(getch());
} while (ch=='Y');
}
void rate1()
{ screen();
gotoxy(5,2);
printf("Enter the daily amount for Petrol: ");
getinput(&z.ch1);
} void rate2()
{
gotoxy(5,4);
printf("Enter the daily amount for Diesel: ");
getinput(&z.ch2);
}
void rate3()
{
gotoxy(5,6);
printf("Enter the daily amount for CNG: ");
getinput(&z.ch3);
window(1,1,80,25);
textbackground(WHITE);
clrscr();
}
void getinput(float *y)
{
char x[10];
int n=0;
do
{
do{ ch=getch();
if(((ch>='0'&&ch<='9')||(ch=='.')) &&(n<10))
{ x[n]=ch;
n++;
printf("%c",ch);
}
else if(ch==8&&n>0)
{
printf("%c%c%c",8,32,8);
n--;
}} while( ch!=13 && n<10 );
x[n]='\0';
*y=atof(x);
} while(ch!=13);
}
void getint(int *u)
{ char x[10];
int n=0;
do{
do{
ch=getch();
if(((ch>='1'&&ch<='7')||(ch=='.')) &&(n<10-4))
{
x[n]=ch;
n++;
printf("%c",ch);
}
else if(ch==8&&n>0)
{ printf("%c%c%c",8,32,8);
n--; }
} while(ch!=13&&n<10);
x[n]='\0';
*u=atoi(x);
} while(ch!=13);
}
void getprh(int *p)
{ char x[10];
int n=0;
do{
do{ ch=toupper(getch());
if((ch=='1'|| ch=='2'|| ch=='3') &&(n<10-4))
{ x[n]=ch;
n++;
printf("%c",ch);
} else
if(ch==8&&n>0)
{ printf("%c%c%c",8,32,8);
n--;
} } while(ch!=13&&n<10);
x[n]='\0';
*p=atoi(x);
} while(ch!=13);
}
void getld(unsigned long *p)
{
char x[10];
int n=0;
do{
do{
ch=toupper(getch());
if((ch>='0'&& ch<='9') &&(n<10))
{ x[n]=ch;
n++;
printf("%c",ch);
}
else
if(ch==8&&n>0)
{ printf("%c%c%c",8,32,8);
n--; }
} while(ch!=13&&n<10);
x[n]='\0';
*p=atol(x);
}while(ch!=13);
}
void empty()
{ y.car_id=0;
y.fuel=0;
y.day=0;
y.mon=0;
y.year=0;
y.sum_rate=0;
y.quantity=0;
} void enter_view()
{ int u;
screen();
gotoxy(3,2);
printf("[1] View the records ¯¯¯");
gotoxy(3,4);
printf("[2] Go to main menu ¯¯¯ ");
gotoxy(10,6);
printf("Enter your choice : ");
getint(&u);
if(u==1)
view();
if(u==2)
{ window(1,1,80,25);
textbackground(WHITE);
clrscr();
start();
}
}int duplicate(unsigned long int rno)
{
FILE *fp;
fp=fopen("Bills.rec","rb");
while(fread(&y, sizeof(y), 1, fp) && rno != y.car_id);
fclose(fp);
if((rno == y.car_id)||(rno==0))
return 1;
else
return 0;
}
void shows()
{
gotoxy(2,2);
printf(" ");
gotoxy(2,4);
printf("Record found------------------------¯¯\n");
gotoxy(41,1);
printf("±±±±±±±±±±±±±±±±±±±±±±±±±±±±");
gotoxy(41,2);
printf("Receipt #: %ld",y.car_id);
gotoxy(41,3);
printf("Quantity : %2.2f",y.quantity);
printf(" litres");
gotoxy(41,4);
printf("Payment : %2.2f",y.sum_rate);
printf(" Rs");
gotoxy(41,5);
printf(" Fuel type: %d",y.fuel);
if(y.fuel==1)
{
gotoxy(53,5);
printf(" Petrol");
}
else if(y.fuel==2)
{
gotoxy(53,5);
printf(" Diesel"); }
else
{ gotoxy(53,5);
printf(" CNG");
} gotoxy(41,6);
printf("Date : %d-%d-%d", y.day,y.mon,y.year);
gotoxy(41,7);
printf("±±±±±±±±±±±±±±±±±±±±±±±±±±±±");
}
void screen()
{
window(1,1,80,25);
textbackground(WHITE);
clrscr();
window(4,4,74,12);
textbackground(BLACK);
clrscr();
window(5,5,73,11);
textcolor(4);
textbackground(WHITE);
clrscr();
}
OUTPUT
No comments:
Post a Comment