Professional Documents
Culture Documents
C PROGRAMMING
Term paper of
c PROGRAMMING..
CSE :202
ACKNOWLEDGEMENT
VINOD VERMA
PAGE:3
C PROGRAMMING
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <dos.h>
#include <math.h>
#include <time.h>
#include<stdlib.h>
#include <bios.h>
void show_mouse();
int t();
void edit();
void infor();
void entry();
void display();
void search();
void search_id();
void search_name();
void del();
void deletion();
void deletion_id();
void print();
void help();
void eat();
void general();
void exit();
PAGE:4
C PROGRAMMING
void seteefect(int, int);
void graph();
void graph2();
void report();
void report2();
void report3();
void pur();
void graph1();
void design();
void bbox();
struct shop
char desc[20];
int rack;
char ch;
int cabnit;
int quantity;
float sale;
char id[6];
float total;
float unit;
float cost;
PAGE:5
C PROGRAMMING
float profit;
float bye;
int qty;
int ost;
int b;
};
FILE *ptr;
//int age;
char a[10];
void infor()
int sher;
clrscr();
textcolor(WHITE);
gotoxy(13,3);
gotoxy(2,5);
printf("\n\n1.EDIBLES.\n\n");
PAGE:6
C PROGRAMMING
printf("\n2.GENERAL ITEMS.\n\n");
printf("\n\n\n\n\nOPTION:");
sher=toupper(getch());
//
switch(sher)
case '1':
eat();
break;
case '2':
general();
break;
default:
gotoxy(8,21);
getche();
void eat()
clrscr();
PAGE:7
C PROGRAMMING
printf("***************************************************************\n");
printf("**************************************************************\n\n");
getche();
clrscr();
printf("**************************************************************\n");
printf("**************************************************************\n");
void general()
clrscr();
printf("***************************************************************\n");
printf("***************************************************************\n\n");
clrscr();
printf("***************************************************************\n");
printf("***************************************************************\n");
}
PAGE:10
C PROGRAMMING
/////////////////////////////// time ///////////////////////////
int t(void)
time_t t;
time(&t);
// clrscr();
gotoxy(15,21);
return 0;
int i=0;
if(code==0)
{ printf("%c",t[i]);
i++;
else if(code==1)
PAGE:11
C PROGRAMMING
{
{ printf("%c",t[i]);
i++;
t[i]='\0';
/******************************data entry***********************************/
void entry()
char ch;
clrscr();
ptr=fopen("shop.dat","a+b");
ch='y';
while(ch=='y')
clrscr();
design();
textcolor(14);
t();
gotoxy(14,3);
PAGE:12
C PROGRAMMING
cprintf("\xDB\xDB\xDB\xDB\xDB\xB2 PURSHASE \xB2\xDB\xDB\xDB\xDB\xDB ");
gotoxy(7,5);
ventry(temp.id,1);
//
flushall();
gotoxy(7,7);
ventry(temp.desc,0);
flushall();
gotoxy(7,9);
ventry(a,1);
temp.rack= atoi(a);
flushall();
gotoxy(7,11);
ventry(a,1);
temp.cabnit= atoi(a);
//
flushall();
PAGE:13
C PROGRAMMING
gotoxy(7,13);
///////////////////////
ventry(a,1);
temp.unit= atof(a);
flushall();
gotoxy(7,15);
ventry(a,1);
temp.sale= atof(a);
flushall();
gotoxy(7,17);
ventry(a,1);
temp.quantity= atoi(a);
flushall();
gotoxy(7,18);
cprintf("=====================================");
temp.total=temp.quantity*temp.sale;
textcolor(10);
gotoxy(10,20);
gotoxy(40,20);
fwrite(&temp,sizeof(temp),1,ptr);
textcolor(10);
gotoxy(10,23);
ch=getche();
fclose(ptr);
/*****************************data retreivel********************************/
void display()
clrscr();
ptr=fopen("shop.dat","rb");
while ((fread(&temp,sizeof(temp),1,ptr))==1)
{
PAGE:15
C PROGRAMMING
gotoxy(22,3);
gotoxy(18,5);
gotoxy(18,7);
gotoxy(18,9);
gotoxy(18,11);
gotoxy(18,13);
gotoxy(18,15);
gotoxy(18,17);
gotoxy(16,18);
printf("===================================");
gotoxy(16,20);
gotoxy(47,20);
gotoxy(20,23);
getche();
PAGE:16
C PROGRAMMING
clrscr();
fclose(ptr);
//
/*******************************data search*******************************/
void search()
int sh;
clrscr();
design();
gotoxy(17,6);
gotoxy(15,9);
gotoxy(15,11);
gotoxy(17,15);
sh=toupper(getch());
PAGE:17
C PROGRAMMING
switch(sh)
case '1':
search_id();
break;
case '2':
search_name();
break;
default:
gotoxy(18,18);
getch();
getche();
/*****************************search by id*********************************/
void search_id()
int flag=0;
char lkf[20];
PAGE:18
C PROGRAMMING
clrscr();
ptr=fopen("shop.dat","rb");
design();
gotoxy(13,4);
scanf("%s",&lkf);
while((!flag)&&(fread(&temp,sizeof(temp),1,ptr))==1)
if(strcmp(temp.id,lkf)==0)
flag=1;
if(flag)
gotoxy(18,6);
printf("Product ID : %s",temp.id);
gotoxy(18,8);
printf("Description : %s",temp.desc);
gotoxy(18,10);
printf("Rack no : %d",temp.rack);
gotoxy(18,12);
printf("Cabnit : %d",temp.cabnit);
gotoxy(18,14);
gotoxy(18,16);
PAGE:19
C PROGRAMMING
printf("Quantity : %d",temp.quantity);
gotoxy(16,17);
printf("============================");
gotoxy(18,19);
else
fclose(ptr);
/*****************************search by name******************************/
void search_name()
int flag=0;
char lkf[20];
clrscr();
ptr=fopen("shop.dat","rb");
design();
gotoxy(13,4);
scanf("%s",&lkf);
while((!flag)&&(fread(&temp,sizeof(temp),1,ptr))==1)
PAGE:20
C PROGRAMMING
{
if(strcmp(temp.desc,lkf)==0)
flag=1;
if(flag)
gotoxy(18,6);
printf("Product ID : %s",temp.id);
gotoxy(18,8);
printf("Description : %s",temp.desc);
gotoxy(18,10);
printf("Rack no : %d",temp.rack);
gotoxy(18,12);
printf("Cabnit : %d",temp.cabnit);
gotoxy(18,14);
gotoxy(18,16);
printf("Quantity : %d",temp.quantity);
gotoxy(16,17);
printf("============================");
gotoxy(18,19);
else
fclose(ptr);
/******************************data deletion*****************************/
void deletion()
int j,n,i;
char tar[30];
int count=0;
ptr = fopen("shop.dat","rb");
clrscr();
design();
gotoxy(17,10);
scanf("%s",&tar);
j=0;
while((fread(&temp,sizeof(temp),1,ptr))==1)
if((strcmp(temp.desc,tar)<0) || (strcmp(temp.desc,tar)>0))
{
PAGE:22
C PROGRAMMING
x[j] = temp;
j++;
else
count++;
if (count==0)
clrscr();
design();
gotoxy(30,10);
gotoxy(17,23);
getch();
return;
fclose(ptr);
n = j;
clrscr();
ptr=fopen("shop.dat","wb");
fwrite(&x[i],sizeof(x[i]),1,ptr);
PAGE:23
C PROGRAMMING
fclose(ptr);
clrscr();
design();
gotoxy(20,10);
gotoxy(20,12);
gotoxy(17,23);
getch();
/******************************data print*********************************/
void print()
clrscr();
putc('\n',stdprn);
fputs("\n\t\t\tREPRT OF SALES",stdprn);
putc('\n',stdprn);
fputs("===========================",stdprn);
putc('\n',stdprn);
putc('\n',stdprn);
fputs("===================================================================",std
prn);
putc('\n',stdprn);
putc('\n',stdprn);
ptr=fopen("shop.dat","rb");
while( (fread(&temp,sizeof(temp),1,stdprn))==1)
fprintf(stdprn," %s",temp.id);
fprintf(stdprn,"\t%s",temp.desc);
fprintf(stdprn,"\t%.2f",temp.sale);
fprintf(stdprn,"\t%ld\n",temp.quantity);
fprintf(stdprn,"\t%.2f",temp.total);
fclose(ptr);
/******************************help***************************************/
void help()
clrscr();
design();
textcolor(WHITE);
gotoxy(20,4);
PAGE:25
C PROGRAMMING
cprintf("\xDB\xDB\xDB\xDB\xB2 HELP ABOUT THE PROGRAM \xB2\xDB\xDB\xDB\xDB");
gotoxy(4,6);
cprintf(" [ 2 ] - ENTER RECORDS : THIS OPTION ALLOWS THE USER TO ENTER NEW ");
gotoxy(30,7);
gotoxy(30,8);
gotoxy(30,9);
gotoxy(4,11);
cprintf(" [ 3 ] - ENTER SALES : THIS OPTION ALLOWS THE USER TO SEE PREVIOUS ");
gotoxy(30,12);
cprintf("SALE RECORDS.");
gotoxy(4,14);
gotoxy(30,15);
gotoxy(4,17);
gotoxy(30,18);
gotoxy(6,23);
getche();
PAGE:26
C PROGRAMMING
clrscr();
design();
textcolor(WHITE);
gotoxy(4,5);
cprintf(" [ 6 ] - VIEW REPORT : THIS OPTION ALLOWS THE USER TO PRINT PREVIOUS");
gotoxy(30,6);
gotoxy(4,8);
cprintf(" [ 7 ] - PRINT RECORDS : THIS OPTION ALLOWS THE USER TO PRINT RECORDS");
gotoxy(30,9);
cprintf("OM PRINTER.");
gotoxy(4,11);
cprintf(" [ 8 ] - VIEW GRAPH : THIS OPTION ALLOWS THE USER TO VIEW GRAPH ");
gotoxy(30,12);
cprintf("OF QUANTITY.");
gotoxy(10,23);
getche();
/***************************main menu*************************************/
menu()
int x;
PAGE:27
C PROGRAMMING
do{
clrscr();
design();
t();
textcolor(WHITE);
gotoxy(24,3);
gotoxy(3,4);
cprintf("--------------------------------------------------------------------------");
gotoxy(35,5);
cprintf("MAIN MENU");
gotoxy(26,8);
gotoxy(26,9);
gotoxy(26,10);
gotoxy(26,11);
gotoxy(26,12);
gotoxy(26,13);
gotoxy(26,14);
gotoxy(26,16);
gotoxy(26,17);
gotoxy(26,18);
gotoxy(26,23);
//
gotoxy(47,23);
x=toupper(getch());
switch(x)
case '1':
infor();
break;
case '2':
entry();
break;
case '3':
edit();
break;
PAGE:29
C PROGRAMMING
case '4':
search();
break;
case '5':
del();
break;
case '6':
report2();
break;
case '7':
print();
break;
help();
break;
case'8':
graph1();
break;
case '9':
PAGE:30
C PROGRAMMING
display();
break;
exit(0);
break;
default:
clrscr();
design();
gotoxy(17,12);
getche();
}while((x!='e')||(x!='E'));
return x;
void main()
textbackground(14);
show_mouse();
menu();
}
PAGE:31
C PROGRAMMING
/************************************* graph ***********************************/
void graph()
int inscor=1;
char ch;
clrscr();
design();
gotoxy(20,23);
textcolor(10);
gotoxy(15,4);
textcolor(14);
gotoxy(3,5);
ptr=fopen("shop.dat","rb");
while((fread(&temp,sizeof(temp),1,ptr))==1)
bar(inscor);
fclose(ptr);
PAGE:32
C PROGRAMMING
getche();
void bar()
int j;
for(j=1;j<=temp.quantity;j++)
printf("\xDB");
printf(" %d",temp.quantity);
printf("\n");
void report()
char ch;
clrscr();
design();
gotoxy(20,23);
textcolor(GREEN);
gotoxy(25,4);
textcolor(RED);
gotoxy(4,7);
gotoxy(4,9);
PAGE:33
C PROGRAMMING
printf("======================================================================
==");
ptr=fopen("shop.dat","rb");
while((fread(&temp,sizeof(temp),1,ptr))==1)
//
printf("\t%s",temp.desc);
printf("\t\t$%.2f",temp.sale);
// printf("\t\t%d",temp.qty);
printf("\t\t%d",temp.quantity);
// printf("\t\t%d",temp.bye);
printf("\t\t $%.2f",temp.total);
getche();
clrscr();
textbackground(b);
textcolor(f);
}
PAGE:34
C PROGRAMMING
void pur()
char ch;
clrscr();
design();
show_mouse();
gotoxy(20,23);
textcolor(GREEN);
gotoxy(25,4);
textcolor(RED);
gotoxy(4,7);
gotoxy(4,9);
printf("======================================================================
==");
ptr=fopen("shop.dat","rb");
while((fread(&temp,sizeof(temp),1,ptr))==1)
//
printf("\t\t$%.2f",temp.unit);
printf("\t\t%d",temp.quantity);
printf("\t\t $%.2f",temp.cost);
getche();
void graph2()
int inscor2=1;
char ch;
clrscr();
design();
gotoxy(20,23);
textcolor(10);
gotoxy(15,4);
textcolor(14);
gotoxy(4,5);
cprintf("PRODUCT NAME");
ptr=fopen("shop.dat","rb");
PAGE:36
C PROGRAMMING
while((fread(&temp,sizeof(temp),1,ptr))==1)
bar2(inscor2);
fclose(ptr);
getche();
void bar2()
int j;
temp.profit=(temp.total-temp.cost);
//
for(j=1;j<=temp.profit;j++)
printf("\xDB");
printf(" %.1f$",temp.profit);
printf("\n");
void graph1()
PAGE:37
C PROGRAMMING
{
int sher;
clrscr();
textcolor(WHITE);
gotoxy(24,3);
gotoxy(10,5);
printf("\n\n\t\xDB\xDB\xB2 1.QUANTITY.\n\n");
printf("\n\t\xDB\xDB\xB2 2.PROFIT.\n");
printf("\n\n\n\t\t\xDB\xDB\xB2 OPTION:");
sher=toupper(getch());
switch(sher)
case '1':
graph();
break;
case '2':
graph2();
break;
default:
gotoxy(9,20);
PAGE:38
C PROGRAMMING
textcolor(RED);
getche();
void report3()
char ch;
clrscr();
design();
gotoxy(20,23);
textcolor(GREEN);
gotoxy(25,4);
textcolor(RED);
gotoxy(4,7);
gotoxy(4,9);
printf("============================================================");
ptr=fopen("shop.dat","rb");
while((fread(&temp,sizeof(temp),1,ptr))==1)
PAGE:39
C PROGRAMMING
{
printf("\t\t%s",temp.desc);
printf("\t\t%d",temp.quantity);
temp.profit=(temp.total-temp.cost);
printf("\t\t $%.2f",temp.profit);
getche();
void report2()
int sher;
clrscr();
bbox();
textcolor(WHITE);
gotoxy(21,3);
gotoxy(5,5);
gotoxy(10,7);
PAGE:40
C PROGRAMMING
printf(" ********* ENTER THE OPTION WHICH SUITS YOU. **********\n");
gotoxy(12,10);
printf("\xDB\xDB\xB2 1.SALES.");
gotoxy(12,12);
printf("\xDB\xDB\xB2 2.PURCHASE.");
gotoxy(12,14);
printf("\xDB\xDB\xB2 3.PROFIT.");
gotoxy(14,17);
printf("\xDB\xDB\xB2 OPTION:");
sher=toupper(getch());
switch(sher)
case '1':
report();
break;
case '2':
pur();
break;
case '3':
report3();
break;
PAGE:41
C PROGRAMMING
default:
gotoxy(9,20);
textcolor(RED);
getche();
void design()
int i;
clrscr();
textcolor(14);
gotoxy(2,2);
cprintf("\xC9");
gotoxy(3,2);
for(i=1;i<=74;i++)
cprintf("\xCD");
gotoxy(77,2);
cprintf("\xBB");
PAGE:42
C PROGRAMMING
gotoxy(2,3);
cprintf("\xBA");gotoxy(2,4);cprintf("\xBA");gotoxy(2,5);cprintf("\xBA");
gotoxy(2,6);cprintf("\xBA");gotoxy(2,7);cprintf("\xBA");gotoxy(2,8);cprintf("\xBA");
gotoxy(2,9);cprintf("\xBA");gotoxy(2,10);cprintf("\xBA");gotoxy(2,11);cprintf("\xBA");gotoxy(2,12);cpr
intf("\xBA");
gotoxy(2,13);cprintf("\xBA");gotoxy(2,14);cprintf("\xBA");gotoxy(2,15);cprintf("\xBA");gotoxy(2,16);c
printf("\xBA");
gotoxy(2,17);cprintf("\xBA");gotoxy(2,18);cprintf("\xBA");gotoxy(2,22);cprintf("\xCC");
gotoxy(2,19);cprintf("\xBA");gotoxy(2,20);cprintf("\xBA");gotoxy(2,21);cprintf("\xBA");gotoxy(2,24);c
printf("\xC8");
gotoxy(2,23);cprintf("\xBA");
gotoxy(3,24);
for(i=1;i<=74;i++)
cprintf("\xCD");
gotoxy(77,18);cprintf("\xBA");gotoxy(77,19);cprintf("\xBA");gotoxy(77,20);cprintf("\xBA");gotoxy(77,
21);cprintf("\xBA");gotoxy(77,24);cprintf("\xBC");
gotoxy(77,23);
cprintf("\xBA");
gotoxy(3,22);
for(i=1;i<=74;i++)
cprintf("\xCD");
gotoxy(77,22);
cprintf("\xB9");
//*****************
PAGE:43
C PROGRAMMING
gotoxy(77,3);
cprintf("\xBA");gotoxy(77,4);cprintf("\xBA");gotoxy(77,5);cprintf("\xBA");
gotoxy(77,6);cprintf("\xBA");gotoxy(77,7);cprintf("\xBA");gotoxy(77,8);cprintf("\xBA");
gotoxy(77,9);cprintf("\xBA");gotoxy(77,10);cprintf("\xBA");gotoxy(77,11);cprintf("\xBA");gotoxy(77,1
2);cprintf("\xBA");
gotoxy(77,13);cprintf("\xBA");gotoxy(77,14);cprintf("\xBA");gotoxy(77,15);cprintf("\xBA");gotoxy(77,
16);cprintf("\xBA");
gotoxy(77,17);cprintf("\xBA");
textcolor(RED);
//
void bbox()
int c,r;
for(c=1;c<=79;c++)
gotoxy(c,1);
printf("ß");
gotoxy(c,25);
printf("ß");
for(r=1;r<=24;r++)
gotoxy(1,r);
PAGE:44
C PROGRAMMING
printf("Û");
gotoxy(79,r);
printf("Û");
void deletion_id()
int j,n,i;
char tar[30];
int count=0;
ptr = fopen("shop.dat","rb");
clrscr();
design();
gotoxy(15,8);
scanf("%s",&tar);
j=0;
while((fread(&temp,sizeof(temp),1,ptr))==1)
if((strcmp(temp.id,tar)<0) || (strcmp(temp.id,tar)>0))
PAGE:45
C PROGRAMMING
{
x[j] = temp;
j++;
else
count++;
if (count==0)
clrscr();
design();
gotoxy(30,10);
gotoxy(17,23);
getch();
return;
fclose(ptr);
n = j;
clrscr();
ptr=fopen("shop.dat","wb");
fclose(ptr);
clrscr();
design();
gotoxy(15,10);
gotoxy(15,12);
gotoxy(17,23);
getch();
void del()
int sh;
clrscr();
design();
gotoxy(17,6);
gotoxy(16,9);
gotoxy(16,11);
PAGE:47
C PROGRAMMING
printf("[ 2 ] - Delete by Description ");
gotoxy(18,15);
sh=toupper(getch());
switch(sh)
case '1':
deletion_id();
break;
case '2':
deletion();
break;
default:
gotoxy(18,18);
gotoxy(17,23);
getch();
getche();
}
PAGE:48
C PROGRAMMING
///////////////////////////////////// update record //////////////////////
void edit()
int j,n,i,a;
float b;
char tar[30],ch;
int count=0;
ch='y';
while(ch=='y')
ptr = fopen("shop.dat","rb");
clrscr();
design();
gotoxy(15,9);
scanf("%s",&tar);
j=0;
while((fread(&temp,sizeof(temp),1,ptr))==1)
if((strcmp(temp.id,tar)<0) || (strcmp(temp.id,tar)>0))
x[j] = temp;
j++;
}
PAGE:49
C PROGRAMMING
else
design();
gotoxy(8,7);
gotoxy(8,9);
gotoxy(8,11);
gotoxy(8,13);
scanf("%d",&a);
x[j]=temp;
x[j].quantity=(x[j].quantity-a);
x[j].total=(x[j].quantity*temp.sale);
x[j].cost=(x[j].quantity*temp.unit);
x[j].bye=(x[j].sale*a);
b=x[j].bye;
x[j].qty=a;
j++;
count++;
if (count==0)
{
PAGE:50
C PROGRAMMING
clrscr();
design();
gotoxy(33,10);
getch();
return;
fclose(ptr);
n = j;
clrscr();
ptr=fopen("shop.dat","wb");
fwrite(&x[i],sizeof(x[i]),1,ptr);
fclose(ptr);
clrscr();
design();
gotoxy(8,9);
gotoxy(8,11);
getch();
printf("more enteries=(y/n)");
ch=getche();
}
PAGE:51
C PROGRAMMING
void show_mouse(void)
in.x.ax = 0x1;
References
E –Balagurusamy
Ashoke N Kamthane
www.planet-source-code.com/
www.codeproject.com/