Computer
Final Review
Fall Semester 2014
By:
• Atit S Gaonkar
14BCE1144
• Siddharth Mohanty
14BME1124
Code
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
#include<ctype.h>
#include<dos.h>
#include<string.h>
#include<time.h>
#include<math.h>
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
struct AddItem
{
int item_id;
char item_name[50];
float price;
};
struct Bill
{
int bill_id;
char cust_name[50];
char item_name[10][50];
float quant[10];
float total;
float price[10];
char date[15];
int n;
};
FILE *fp,*fp1,*bifp,*bifp1;
struct AddItem ad;
struct Bill bi;
int add_item();
int generate_bill();
int delete_bill();
int display_bill();
int q=0;
main()
{
int i=1;
system("cls");
printf("nnnnnnttt * * * * * * * * * * * * * * * * * * *");
printf("nnnnttt * SHOPPING MALL BILLING SYSTEM *");
printf("nnnnttt * * * * * * * * * * * * * * * * * * *");
printf("nnttt1.Continuennttt2.EXIT");
printf("nntttEnter Your Option : ");
scanf("%d",&i);
if(i==2)
{
system("cls");
printf("nnnnnnnnnntttt THANKS YOU");
printf("nnntttt Exiting In 3 Secs");
for(int f=1;f<4;f++)
{
printf(" .");
Sleep(600);
printf(" .");
Sleep(600);
printf(" .");
Sleep(600);
system("cls");
exit(0);
}
}
else
{
int f=1,choice;
system("cls");
printf("nnPLEASE WAIT");
for(f=1;f<2;f++)
{
Sleep(600); printf(" .");
Sleep(600);
printf(" .");
Sleep(600);
}
XYZ:
system("cls");
printf("ttt ********************************n");
printf("nttt SHOPPING MALL BILLING SYSTEMn");
printf("nttt ********************************");
printf("n-------------------------------------------------------------------------------");
printf("nnt1. ADD PRODUCT");
printf("nnt2. GENERATE A BILL");
printf("nnt3. DISPLAY A BILL");
printf("nnt4. DELETE A BILL");
printf("nnt5. EXIT");
printf("n-------------------------------------------------------------------------------");
printf("nnENTER CORRESPONDING KEYS TO PERFORM
OPERATION :- ");
ABC:
scanf("%d",&choice);
switch(choice)
{
case 1:
q=add_item();
if(q==2)
{
system("cls");
printf("nnnnnnnnnntttt THANK YOU");
Sleep(1800);
exit(0);
}
else
{
system("cls");
goto XYZ;
}
break;
case 2:
q=generate_bill();
if(q==2)
{
system("cls");
printf("nnnnnnnnnntttt THANK YOU");
Sleep(1800);
exit(0);
}
else
{
system("cls");
goto XYZ;
}
break;
case 3:
q=display_bill();
if(q==2)
{
system("cls");
printf("nnnnnnnnnntttt THANK YOU");
Sleep(1800);
exit(0);}
else
{
system("cls");
goto XYZ;
}
break;
case 4:
q=delete_bill();
if(q==2)
{
system("cls");
printf("nnnnnnnnnntttt THANK YOU");
Sleep(1800);
exit(0);
}
else
{
system("cls");
goto XYZ;
}
case 5:
system("cls");
printf("nnnnnnnnnntttt THANK YOU");
Sleep(1800);
exit(0);
default:
printf("nntYOU ENTERED A WRONG
VALUE.PLEASE TRY AGAIN : ");
goto ABC;
}
}
getch();
}
int add_item()
{
int f=1,id=0,p[10],i=0,h=0,t=0;
fp=fopen("Products.txt","a");
fclose(fp);
system("cls");
while(f==1)
{
system("cls");
fp=fopen("Products.txt","r");
while((fread(&ad,sizeof(ad),1,fp))==1)
{
id=ad.item_id;
}
fclose(fp);
printf("ntENTER PRODUCT NAME :-t");
scanf("%s",ad.item_name);
printf("ntENTER PRODUCT PRICE :-t");
scanf("%f",&ad.price);
id++;
p[i]=id;
i++;
ad.item_id=id;
fp=fopen("Products.txt","a");
fwrite(&ad,sizeof(ad),1,fp);
fclose(fp);
printf("nnnntYOUR PRODUCT WITH ID %d IS ADDED
SUCCESSFULLY....",ad.item_id);
printf("nnt 1. TO ADD NEW PRODUCT 2. TO EXIT...t");
printf("nntEnter Your Choice : ");
scanf("%d",&f);
if(f!=1)
{
break;
}
}
system("cls");
i=0;
fp=fopen("Products.txt","r");
while((fread(&ad,sizeof(ad),1,fp))==1)
{
if(p[i]==ad.item_id)
{
printf("ntPRODUCT ID :- %d",ad.item_id);
printf("ntPRODUCT NAME :- %s",ad.item_name);
printf("ntPRODUCT PRICE :- %f",ad.price);
printf("nn");
i++;
}
}
fclose(fp);
printf("nnt 1. TO GO TO MENU PAGE nnt2. TO EXIT :-t");
scanf("%d",&q);
return q;
}
int generate_bill()
{
time_t now;
struct tm *d;
int w=0;
int item_id,f=1,i=0,n=0,p=0,bill_id=0,k=1,j=0;
float total=0,quant=0;
bifp=fopen("GBill.txt","a");
fclose(bifp);
while(f==1)
{
int flag=0;
system("cls");
if(j==0)
{
bifp=fopen("GBill.txt","r");
while((fread(&bi,sizeof(bi),1,bifp))==1)
{
bill_id=bi.bill_id;
}
bill_id++;
bi.bill_id=bill_id;
fclose(bifp);
j++;
}
printf("tNOTE :- JUST ENTER PRODUCT ID OF BUYING PRODUCTS
TO CALCULATE BILL");
printf("nntPRODUCT ID :-t");
scanf("%d",&item_id);
fp=fopen("Products.txt","r");
while((fread(&ad,sizeof(ad),1,fp))==1)
{
if(item_id==ad.item_id)
{
printf("nntPRODUCT NAME :- %s",ad.item_name);
strcpy(bi.item_name[i],ad.item_name);
printf("tPRODUCT PRICE :- %f",ad.price);
bi.price[i]=ad.price;
printf("nn");
flag=1;
}
}
if(flag==0)
{
printf("nntYOUR PRODUCT ID IS NOT FOUND.");
}
else
{
printf("nntQUANTITY OF PRODUCT :-t");
scanf("%f",&quant);
bi.quant[i]=quant;
total=total+quant*ad.price;
bi.total=total;
flag=0;
bi.n=i;
n=i;
i++;
}
fclose(fp);
printf("nnnt 1. TO ADD MORE PRODUCT nnnt2. TO GO TO BILL
PAGE : ");
scanf("%d",&f);
}
system("cls");
printf("ntPUT DOWN CUSTOMER INFORMATION .....");
printf("nntCUSTOMER NAME :- ");
scanf("%s",&bi.cust_name);
time(&now);
d=localtime(&now);
strftime(bi.date, 15, "%d/%m/%Y", d);
printf("nnnt 1. TO GENERATE A BILL nnt2. TO GO TO MAIN MENU : ");
scanf("%d",&p);
if(p!=1)
{
return p;
}
else
{
i=0;
bifp=fopen("GBill.txt","a");
fwrite(&bi,sizeof(bi),1,bifp);
fclose(bifp);
system("cls");
printf("nntBILL IS BEING GENERATED");
printf("nntPlesase Wait");
for(p=0;p<3;p++)
{
Sleep(500);
printf(" .");
Sleep(500);
printf(" .");
Sleep(500);
printf(" .");
Sleep(500);
system("cls");
}
printf("nnttt ********************************n");
printf("nttt SHOPPING MALL BILLING SYSTEMn");
printf("nttt ********************************");
printf("n----------------------------------------------------");
gotoxy(2,5);
printf("CUSTOMER NAME : %s",bi.cust_name);
gotoxy(36,5);
printf("BILL ID : %d",bi.bill_id);
gotoxy(62,5);
printf("DATE : %s",bi.date);
printf("n----------------------------------------------------");
gotoxy(4,7);
printf("SrNo.");
gotoxy(12,7);
printf("ITEM NAME");
gotoxy(32,7);
printf("PRICE");
gotoxy(53,7);
printf("QUANTITY");
gotoxy(70,7);
printf("TOTAL");
total=0;
for(i=0;i<=n;i++)
{
Sleep(200);
gotoxy(5,w+9);
printf("%d",i+1);
gotoxy(14,w+9);
printf("%s",bi.item_name[i]);
gotoxy(31,w+9);
printf("%f",bi.price[i]);
gotoxy(53,w+9);
printf("%f",bi.quant[i]);
gotoxy(68,w+9);
printf("%f",bi.price[i]*bi.quant[i]);
total=total+(bi.price[i]*bi.quant[i]);
w=w+2;
}
Sleep(200);
printf("n-----------------------------------------------------");
gotoxy(14,w+9);
printf("TOTAL");
gotoxy(66,w+9);
printf("%f Rs",total);
printf("n-------------------------------------------------------");
Sleep(200);
printf("nnt1. TO GO TO MAIN MENU nnt2. TO EXIT ");
printf("nntEnter Your Choice : ");
scanf("%d",&q);
return q;
}
}
int display_bill()
{
int w=0,p=0;
int item_id,f=0,i=0,bill_id=0;
float total;
system("cls");
printf("nntPLEASE ENTER YOUR BILL-ID :- ");
scanf("%d",&bill_id);
bifp=fopen("GBill.txt","a");
fclose(bifp);
bifp=fopen("GBill.txt","r");
while((fread(&bi,sizeof(bi),1,bifp))==1)
{
if(bill_id==bi.bill_id)
{
f=1;
system("cls");
for(p=0;p<3;p++)
{
printf("nntSEARCHING");
Sleep(500);
printf(" .");
Sleep(500);
printf(" .");
Sleep(500);
printf(" .");
Sleep(500);
system("cls");
}
printf("nnttt ********************************n");
printf("nttt SHOPPING MALL BILLING SYSTEMn");
printf("nttt ********************************");
printf("n-------------------------------------------------------------");
gotoxy(2,5);
printf("CUSTOMER NAME : %s",bi.cust_name);
gotoxy(36,5);
printf("BILL ID : %d",bi.bill_id);
gotoxy(62,5);
printf("DATE : %s",bi.date);
printf("n-----------------------------------------------------------");
gotoxy(4,7);
printf("SrNo.");
gotoxy(12,7);
printf("ITEM NAME");
gotoxy(32,7);
printf("PRICE");
gotoxy(53,7);
printf("QUANTITY");
gotoxy(70,7);
printf("TOTAL");
total=0;
for(i=0;i<=bi.n;i++)
{
Sleep(200);
gotoxy(5,w+9);
printf("%d",i+1);
gotoxy(14,w+9);
printf("%s",bi.item_name[i]);
gotoxy(31,w+9);
printf("%f",bi.price[i]);
gotoxy(53,w+9);
printf("%f",bi.quant[i]);
gotoxy(68,w+9);
printf("%f",bi.price[i]*bi.quant[i]);
total=total+(bi.price[i]*bi.quant[i]);
w=w+2;
}
Sleep(200);
printf("n-------------------------------------------------------------");
gotoxy(14,w+9);
printf("TOTAL");
gotoxy(66,w+9);
printf("%f Rs",total);
printf("n-------------------------------------------------------------");
break;
}
}
if(f==0)
{
printf("nntSORRY, YOUR BILL-ID DOES NOT MATCH");
}
fclose(bifp);
Sleep(200);
printf("nntPRESS 1 TO GO TO MAIN MENU nn2. TO EXIT :- ");
scanf("%d",&q);
return q;
}
int delete_bill()
{
int item_id,f=0,i=0,bill_id=0;
system("cls");
bifp=fopen("GBill.txt","w");
fclose(bifp);
printf("nPLEASE ENTER YOUR BILL-ID :- ");
scanf("%d",&bill_id);
bifp=fopen("GBill.txt","r");
while(fread(&bi,sizeof(bi),1,bifp)==1)
{
if(bi.bill_id==bill_id)
{
f=1;
break;
}
}
fclose(bifp);
if(f==1)
{
bifp=fopen("GBill.txt","r");
bifp1=fopen("GBill_1.txt","w");
while((fread(&bi,sizeof(bi),1,bifp))==1)
{
fwrite(&bi,sizeof(bi),1,bifp1);
}
fclose(bifp);
fclose(bifp1);
bifp=fopen("GBill.txt","w");
bifp1=fopen("GBill_1.txt","r");
while((fread(&bi,sizeof(bi),1,bifp1))==1)
{
if(bi.bill_id!=bill_id)
{
fwrite(&bi,sizeof(bi),1,bifp);
}
}
fclose(bifp1);
fclose(bifp);
printf("nntYOUR BILL HAS BEEN DELETED SUCCESSFULLY.");
}
else
{
printf("nntSORRY, YOUR BILL-ID DOES NOT MATCH.");
}
printf("nntPRESS 1. TO GO TO MAIN MENU nnt2. TO EXIT :- ");
scanf("%d",&q);
return q;
}
Output
C Programming :- An Example
C Programming :- An Example
C Programming :- An Example
C Programming :- An Example
C Programming :- An Example
C Programming :- An Example

C Programming :- An Example