C programming helps us in finding the solution of the problems by the computer language, by preparing the C program codes. As same in this program of the address book we have given a statement in the execution screen to enter the address of the employee or any personal address. In this program I used structures and if-else loops with the help of switch case and for loops.
This program is widely used in many factories or in government management system like railways, airlines reservation ,and also in some sort of banks.
This program helps us to do many further aspects in the future.~~~~!!!!!!
Advantages:--
There are many advantages of this system whose name is Gas Agency management System This system is use in many Government System without of this system no one can use gas cylinders in their home… as we all know that gas is very important in our homes withouts of this no one can eat food….
System Requirements:--
For this program this system requires following things:--
1. First of all we require C software….
2. Then we require 32 bit screen resolution….
3. Then we require Compiler….
4. We also require window Xp….
Introduction of gas agency management system
We can make this gas management system in C language by using three or more than three header files or many data types such as:
1. #include
2. #include
3. #include
4. #include
a. Strrev();
b. Strlen();
c. Strupr();
d. Strlwr();
e. And many mores……
Source code
#include
#include
#include
#include
#include
#include
void war_func(); //For the Display of warning on the screen
void enter_view(); //For the Display of View Record Menu
void shows(); //For Display of record in the program
int date(); //Declaration of fucntion for displaying Date
void screen(); //Display the screen and background colors
void start(); //Used to display main menu after entering rates
void add(); //UFD for adding a new Bill record
void del(); //UDF for Deleting an existing record
void empty(); //Used for deletion of records
void search(); //UDF for searching an existing record
void modify(); //UDF for modifying an existing bill record
void input(); //Function for taking input while adding a record
void view(); //Fuction for viewing recrods
void rate1(),rate2(),rate3(); // Fucntions for Fixing the rates of fuel types
int duplicate(unsigned long int); //Checks the Duplication of Receipt Number
void getinput(float *x); //Checks the input for all Decimal values entered while input
void getint(int *y); //Checks the input of integer type (MENU OPTIONS)
void getprh(int *p); //Checks the input of interger type for Fuel types
void getld(unsigned long *p); //Checks the length and validity of input of type long (Receipt Number)
int i,j; //Declaration of variables of type interger
float rate; //Float declaration for rates of fuels
char ch; //Global declaration of ch for use in fucntions
struct add //Declaration of Add structure used in Add module
{ unsigned long int car_id; //Receipt ID for adding (4 bytes)
int day;
int mon;
int year;
float sum_rate;
float quantity;
int fuel;
}
y;
struct //Declaration of structure for Fuel prices
{ float ch1,ch2,ch3; //Three float type variables for keeping fuel price inputs
} z;
struct date d; //Default Date Structure for displaying Date
main() //Start of Main Fucntion
{ 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();
} //End of main
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"); //---->>Display of main menu
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(); /*Calling Fucntion to show Warning*/
clrscr();
}
else if(i==5)
{ del(); /*Calling Delete function to perform deletion of records*/
}
else if(i==3)
{ modify(); /*Calling Modify function to perform Modificaiton in records*/
}
else if(i==4)
{ search(); /*Calling Search function to perform searching*/
}
else if(i==1)
{ input(); /*Calling input function to perform addition of records*/
}
else if(i==6)
{ main();
} else if(i==2)
{ enter_view(); //Calling Menu for View function
} } while(i!=7); //Exit when we press 7
clrscr();
printf("\n\n\n\n\n\n\n\n\tAuthor : Anchit rubin Kumar Giri\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() //Start of warning function
{ clrscr();
window(5,3,75,17);
textbackground(BLACK);
clrscr(); //----------->>Setting Background colors
window(7,4,73,16);
textbackground(WHITE);
textcolor(4);
clrscr();
gotoxy(12,5); printf("Warning! Invalid Input...Press any key!");
getch();
clrscr();
}
void del() //Start of Delete Module
{ 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);
} //End of Delete Module
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);
} //End of view Module
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; //fix the rate with its type
} 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();
} } //End of Modify Module
void search() //Start of Search Module
{
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);
}
} //END of Search Module
void add() //Start of add Module
{ unsigned long temp;
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): ");
getinp ut(&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')
} //END of Input Module
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();
} //End of All rate fucntions
void getinput(float *y)
{
char x[MAX];
int n=0;
do
{
Do { ch=getch();
if(((ch>='0'&&ch<='9')||(ch=='.')) &&(n
n++;
printf("%c",ch);
}
else if(ch==8&&n>0)
{
printf("%c%c%c",8,32,8);
n--;
}} while( ch!=13 && n
*y=atof(x);
} while(ch!=13);
} //End of float validity check
void getint(int *u)
{ char x[MAX];
int n=0;
do{
do{
ch=getch();
if(((ch>='1'&&ch<='7')||(ch=='.')) &&(n
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
*u=atoi(x);
} while(ch!=13);
} //End of integer value check
void getprh(int *p)
{ char x[MAX];
int n=0;
do{
do{ ch=toupper(getch());
if((ch=='1'|| ch=='2'|| ch=='3') &&(n
n++;
printf("%c",ch);
} else
if(ch==8&&n>0)
{ printf("%c%c%c",8,32,8);
n--;
} } while(ch!=13&&n
*p=atoi(x);
} while(ch!=13);
} //End of integer input check # 2
void getld(unsigned long *p)
{
char x[MAX];
int n=0;
do{
do{
ch=toupper(getch());
if((ch>='0'&& ch<='9') &&(n
n++;
printf("%c",ch);
}
else
if(ch==8&&n>0)
{ printf("%c%c%c",8,32,8);
n--; }
} while(ch!=13&&n
*p=atol(x);
}while(ch!=13);
} //End of long int check
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();
}
No comments:
Post a Comment