c programming :- an example
TRANSCRIPT
Computer
Final Review Fall Semester 2014
By: • Atit S Gaonkar 14BCE1144
• Siddharth Mohanty14BME1124
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("\n\n\n\n\n\n\t\t\t * * * * * * * * * * * * * * * * * * *");printf("\n\n\n\n\t\t\t * SHOPPING MALL BILLING SYSTEM *");printf("\n\n\n\n\t\t\t * * * * * * * * * * * * * * * * * * *");printf("\n\n\t\t\t1.Continue\n\n\t\t\t2.EXIT");printf("\n\n\t\t\tEnter Your Option : ");scanf("%d",&i);if(i==2){
system("cls"); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t THANKS YOU");printf("\n\n\n\t\t\t\t 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("\n\nPLEASE WAIT");for(f=1;f<2;f++){
Sleep(600); printf(" .");Sleep(600);printf(" .");Sleep(600);
}XYZ:
system("cls"); printf("\t\t\t ********************************\n");printf("\n\t\t\t SHOPPING MALL BILLING SYSTEM\n");printf("\n\t\t\t ********************************");
printf("\n-------------------------------------------------------------------------------");printf("\n\n\t1. ADD PRODUCT");printf("\n\n\t2. GENERATE A BILL");printf("\n\n\t3. DISPLAY A BILL");printf("\n\n\t4. DELETE A BILL");printf("\n\n\t5. EXIT");
printf("\n-------------------------------------------------------------------------------");printf("\n\nENTER CORRESPONDING KEYS TO PERFORM
OPERATION :- ");ABC:scanf("%d",&choice);switch(choice){
case 1:q=add_item();if(q==2){
system("cls"); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t THANK YOU");Sleep(1800);exit(0);
}else{
system("cls"); goto XYZ;
}break;
case 2:q=generate_bill();if(q==2){
system("cls"); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t THANK YOU");Sleep(1800);exit(0);
}else
{system("cls"); goto XYZ;
}break;
case 3:q=display_bill();if(q==2){
system("cls"); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t THANK YOU");Sleep(1800);exit(0);}
else{
system("cls"); goto XYZ;
}break;
case 4:q=delete_bill();if(q==2){
system("cls"); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t THANK YOU");Sleep(1800);exit(0);
}else{
system("cls"); goto XYZ;
}case 5:
system("cls"); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t THANK YOU");Sleep(1800);exit(0);
default:printf("\n\n\tYOU 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("\n\tENTER PRODUCT NAME :-\t");scanf("%s",ad.item_name);printf("\n\tENTER 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("\n\n\n\n\tYOUR PRODUCT WITH ID %d IS ADDED
SUCCESSFULLY....",ad.item_id);printf("\n\n\t 1. TO ADD NEW PRODUCT 2. TO EXIT...\t");printf("\n\n\tEnter 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("\n\tPRODUCT ID :- %d",ad.item_id);printf("\n\tPRODUCT NAME :- %s",ad.item_name);printf("\n\tPRODUCT PRICE :- %f",ad.price);printf("\n\n");i++;
}}fclose(fp);printf("\n\n\t 1. TO GO TO MENU PAGE \n\n\t2. 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("\n\n\tPRODUCT 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("\n\n\tPRODUCT 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("\n\n");flag=1;
}}if(flag==0){
printf("\n\n\tYOUR PRODUCT ID IS NOT FOUND.");}else{
printf("\n\n\tQUANTITY 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("\n\n\n\t 1. TO ADD MORE PRODUCT \n\n\n\t2. TO GO TO BILL
PAGE : ");scanf("%d",&f);
}
system("cls"); printf("\n\tPUT DOWN CUSTOMER INFORMATION .....");printf("\n\n\tCUSTOMER NAME :- ");scanf("%s",&bi.cust_name);time(&now);d=localtime(&now);strftime(bi.date, 15, "%d/%m/%Y", d);printf("\n\n\n\t 1. TO GENERATE A BILL \n\n\t2. 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("\n\n\tBILL IS BEING GENERATED");printf("\n\n\tPlesase Wait");for(p=0;p<3;p++){
Sleep(500);printf(" .");Sleep(500);printf(" .");Sleep(500);printf(" .");Sleep(500);system("cls");
}printf("\n\n\t\t\t ********************************\n");printf("\n\t\t\t SHOPPING MALL BILLING SYSTEM\n");printf("\n\t\t\t ********************************");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("\n\n\t1. TO GO TO MAIN MENU \n\n\t2. TO EXIT ");printf("\n\n\tEnter 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("\n\n\tPLEASE 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("\n\n\tSEARCHING");Sleep(500);printf(" .");Sleep(500);printf(" .");Sleep(500);printf(" .");Sleep(500);system("cls");
}printf("\n\n\t\t\t ********************************\n");printf("\n\t\t\t SHOPPING MALL BILLING SYSTEM\n");printf("\n\t\t\t ********************************");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("\n\n\tSORRY, YOUR BILL-ID DOES NOT MATCH");}fclose(bifp);Sleep(200);printf("\n\n\tPRESS 1 TO GO TO MAIN MENU \n\n2. 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("\n\n\tYOUR BILL HAS BEEN DELETED SUCCESSFULLY.");
}else{
printf("\n\n\tSORRY, YOUR BILL-ID DOES NOT MATCH.");}printf("\n\n\tPRESS 1. TO GO TO MAIN MENU \n\n\t2. TO EXIT :- ");scanf("%d",&q);return q;
}
Output