共有回帖数 0 个
-
#include conio.h
#define LEN sizeof(struct cang)
#define NULL 0
struct cang
{
int num;/*编号*/
int sm; /*数量*/
int dj; /*单价*/
int hj; /*合计*/
struct cang *next;
};
void print(struct cang *head);
/**链表的创建**/
struct cang *create()
{
struct cang *head,*tail,*p;
int i=3;
setform();
head=tail=NULL;
p=(struct cang *) malloc (LEN);
gotoxy(3,3);
scanf("%dt%dt%dt%d",&p-num,&p-sm,&p-dj,&p-hj);
while(p-num!=0)
{
i=i+2;
if(head==NULL)
head=tail=p;
else
tail=tail-next;
tail-next=p;
p=(struct cang *) malloc (LEN);
gotoxy(3,i);
scanf("%dt%dt%dt%d",&p-num,&p-sm,&p-dj,&p-hj);
}
clrscr();
return head;
}
/**链表的创建***/
/**********************/
setform()
{
gotoxy(1,1);
printf("编号");
gotoxy(9,1);
printf("数量");
gotoxy(17,1);
printf("单价");
gotoxy(25,1);
printf("合计价格");
}
/********************/
/**** 链表输出 **/
void print(struct cang *head)
{
int i=3;
while(head)
{
setform();
gotoxy(1,i);
printf("%dt%dt%dt%d",head-num,head-sm,head-dj,head-hj);
head=head-next;
printf("n");
i=i+2;
}
}
/**** 链表输出 **/
/**连表的删除**/
struct cang *del(struct cang *head,int num)
{
struct cang *p2,*p;
p=head;
while(num !=p- num && p-next!=NULL)
{
p2=p; p=p-next; }
if(p-num==num)
{if(p==head) head=p-next;
else
p2-next=p-next;
}
return head;
}
/*链表的删除*/
/*链表的插入*/
struct cang *insert(struct cang *head,struct cang *cku)
{
struct cang *p0,*p1,*p2;
p1=head; p0=cku;
if(head==NULL) {head=p0; p0-next=NULL;}
else
{
while ((p0-num p1-num) &&( p1 -next != NULL))
{p2=p1; p1=p1-next;}
if(p0-num=p1-num)
{if(p1==head) {head=p0;}
else p2-next=p0;
p0-next=p1;}
else
{p1-next=p0; p0-next=NULL;}
}
return head;
}
/*链表的插入*/
/*链表的查询*/
struct cang *look(struct cang *head,int num)
{
struct cang *p;
while((p-num!=num) && (p-next!=NULL) )
{p=p-next;}
if(p-num==num)
return p;
else return NULL;
}
/*链表的查询*/
/*******主函数*********/
main()
{
int r=0,num1,num2;
struct cang *head,*cku,*cx;
char *s[]={"1.",
"2.",
"3.",
"4.",
"5.",
"6.",
"7."};
/* char *options[]={" 1.","2."," 3.","4."};*/
textbackground(BLUE);
clrscr();
head=NULL;
okdialog(20,7,60,15,BLACK,WHITE,
" WELCOME!",
" Welcome to my first c program.",
" QQ:136069699 ",
" email:limoer2003@yahoo.com.cn ",
" Press OK Enter");
do{
textbackground(CYAN);
textcolor(BLACK);
clrscr();
r=showmainmenu(25,5,55,20,WHITE,BLUE,s,7,r);
switch(r)
{
case 0: clrscr(); head=create(); break;
case 1:
{ clrscr();
gotoxy(50,2);
printf("请输入你想放入的物品信息");
setform();
gotoxy(1,3); scanf("%d",&cku-num);
gotoxy(9,3); scanf("%d",&cku-sm);
gotoxy(17,3); scanf("%d",&cku-dj);
gotoxy(25,3); scanf("%d",&cku-hj);
head=insert(head,cku);
break;}
case 2:
{
clrscr(); printf("请输入你想删除的物品编号:");
scanf("%d",&num1); clrscr();
head=del(head,num1) ;
break;
}
case 3: {
clrscr();
if(head==NULL)
{gotoxy(30,10);
printf("现在仓库没有存货");}
else
{print(head); }
getch(); break;
}
case 4: {
clrscr() ; printf("请输入想查询的物品编号:n"); scanf("%d",&num2);
clrscr(); cx=look(head,num2);
if(cx==NULL) {printf("没有你想要查询的物品");}
else
{ setform(); gotoxy(1,3); printf("%d",cx-num);
gotoxy(9,3); printf("%d",cx-sm);
gotoxy(17,3); printf("%d",cx-dj);
gotoxy(25,3); printf("%d",cx-hj);
}
getch();
break;}
case 5: ok(10,3,70,21,BLACK,WHITE);
getch();
break;
case 6: break;
}
}while(!(r==6));
}
/*******主函数*********/
/*************输入显示框******/
inputbox(int x1,int y1,int x2,int y2,int n, char color, char backcolor,char ch,char *string,char * si)
/* n the longest input number */
/* ch if ch equal space show character that you just input esle show ch*/
/* string the tip off before input bar*/
/* si retrun what you just input*/
{
int i,sl;
char ct,k=0;
unsigned char buf[4096],c;
gettext(x1,y1,x2,y2,buf);
dbox(x1,y1,x2,y2,color,backcolor);
gotoxy(x1+1,y1+1);
cprintf("%s",string);
sl=strlen(string);
textcolor(BLACK);
textbackground(CYAN);
gotoxy(x1+sl+1,y1+1);
for(i=0;in;i++) cprintf(" ");
gotoxy(x1+sl+1,y1+1);
for(i=0;i21;i++) si=0;
do{
c=getch();
if (c!=8&&kn&&((c=97&&c=122) ||(c=48&&c=57 )))
{
gotoxy(x1+sl+1+k,y1+1);
if (ch==32) putch©;
else putch(ch);
si[k]=c;k++;
}
if(c==8) if(k0){ k--; gotoxy(x1+sl+1+k,y1+1); putch(' '); gotoxy(x1+sl+1+k,y1+1); }
if (c==27) {k=0; gotoxy(x1+sl+1,y1+1);for(i=0;in;i++) cprintf(" "); gotoxy(x1+sl+1,y1+1);for(i=0;i21;i++) si=0;}
}while(c!=13);
si[k]=' ';
puttext(x1,y1,x2,y2,buf);
}
/************输入显示框**********************/
/*************双线显示框**********/
dbox(int x1,int y1,int x2,int y2, char color, char backcolor)
{
int x,y,i,j;
x=x2-x1;y=y2-y1;
textcolor(color);
textbackground(backcolor);
for(i=0;i=x;i++)
{
for(j=0;j=y;j++)
{
if (i==0||i==x||j==0||j==y)
{
if(i==0||i==x ) {gotoxy(x1+i,y1+j); cprintf("%c",186);}
if(j==0||j==y ) {gotoxy(x1+i,y1+j); cprintf("%c",205);}
}
else
{ gotoxy(x1+i,y1+j); cprintf(" "); }
}/*for j*/
}/*for I*/
gotoxy(x1,y1); cprintf("%c",201);
gotoxy(x1,y2); cprintf("%c",200);
gotoxy(x2,y1); cprintf("%c",187);
gotoxy(x2,y2); cprintf("%c",188);
}
/*************双线框**********/
/*************单线框**********/
box(int x1,int y1,int x2,int y2, char color, char backcolor)
{
int x,y,i,j;
x=x2-x1;y=y2-y1;
textcolor(color);
textbackground(backcolor);
for(i=0;i=x;i++)
{
for(j=0;j=y;j++)
{
if (i==0||i==x||j==0||j==y)
{
if(i==0||i==x) {gotoxy(x1+i,y1+j); cprintf("%c",179);}
if(j==0||j==y) {gotoxy(x1+i,y1+j); cprintf("%c",196);}
}
else
{ gotoxy(x1+i,y1+j); cprintf(" "); }
} /*for j*/
} /*for I*/
gotoxy(x1,y1); cprintf("%c",218);
gotoxy(x2,y1); cprintf("%c",191);
gotoxy(x1,y2); cprintf("%c",192);
gotoxy(x2,y2); cprintf("%c",217);
}
/*************单线框**********/
/*************信息提示框 **********/
int message(int x1,int y1,int x2,int y2, int n,int color,int backcolor,char *s,char *s1,char *s2,char *s3,char *s4)
/* show message dialog*/
/* n is a number you want choose when show the dialog*/
/* s,s1,s2,s3,s4 is the string what you want display in dialog */
{
int x,y,i,j;
unsigned char c,buf[4096];
gettext(x1,y1,x2,y2,buf);
dbox(x1,y1,x2,y2,color,backcolor);
textcolor(color);
textbackground(backcolor);
gotoxy(x1+1,y1+1); printf("%s",s);
gotoxy(x1+1,y1+2); printf("%s",s1);
gotoxy(x1+1,y1+3); printf("%s",s2);
gotoxy(x1+1,y1+4); printf("%s",s3);
gotoxy(x1+1,y1+5); printf("%s",s4);
textbackground(WHITE);
textcolor(BLACK);
do
{
if (n==1) { gotoxy(x1+4,y2-1); cprintf("[ Y ]"); gotoxy(x2-8,y2-1); cprintf(" N "); }
if (n==0) { gotoxy(x1+4,y2-1); cprintf(" Y "); gotoxy(x2-8,y2-1); cprintf("[ N ]"); }
c=getch();
if (c==75||c==77) {n++;n=n%2; }
}while(!(c==13));
puttext(x1,y1,x2,y2,buf);
return n;
}
/*************信息提示框**********/
/*************OK信息**********/
int ok(int x1,int y1,int x2,int y2,int color,int backcolor)
/* show OK dialog*/
/* s,s1,s2,s3,s4 is the string what you want display in dialog */
{
int x,y,i,j;
unsigned char c,buf[4096];
gettext(x1,y1,x2,y2,buf);
dbox(x1,y1,x2,y2,color,backcolor);
textcolor(color);
textbackground(backcolor);
gotoxy(11,5); printf("由于本人还处于菜鸟阶段,刚刚看完了链表,有很多问题不能解决");
gotoxy(11,7); printf(" 1.编号0是入库结束的标志");
gotoxy(11,9); printf(" 2.本程序还存在8个警告");
gotoxy(11,11); printf(" 3.首次入库部分需要用TABLE键盘");
gotoxy(11,13); printf(" 4.本人从未进过仓库,不了解需求功能,希望大家能帮我修正");
gotoxy(11,17); printf(" 作者:李摩尔");
gotoxy(11,19); printf(" 时间:2007.2.1 0.55分");
gotoxy((x2-x1)/2-4+x1,y2-1); cprintf("[ OK ]");
textbackground(WHITE);
textcolor(BLACK);
messageline(24,BLACK,WHITE,"Welcome to use the program. If there are any bug,please to be associate with author QQ:136069699");
do
{
c=getch();
}while(c!=13);
puttext(x1,y1,x2,y2,buf);
}
/*************OK信息框**********/
/*************OK显示框**********/
int okdialog(int x1,int y1,int x2,int y2,int color,int backcolor, char *s,char *s1,char *s2,char *s3,char *s4)
/* show OK dialog*/
/* s,s1,s2,s3,s4 is the string what you want display in dialog */
{
int x,y,i,j;
unsigned char c,buf[4096];
gettext(x1,y1,x2,y2,buf);
dbox(x1,y1,x2,y2,color,backcolor);
textcolor(color);
textbackground(backcolor);
gotoxy(x1+2,y1+1); printf("%s",s);
gotoxy(x1+2,y1+2); printf("%s",s1);
gotoxy(x1+2,y1+3); printf("%s",s2);
gotoxy(x1+2,y1+4); printf("%s",s3);
gotoxy(x1+2,y1+5); printf("%s",s4);
gotoxy((x2-x1)/2-4+x1,y2-1); cprintf("[ OK ]");
textbackground(WHITE);
textcolor(BLACK);
messageline(24,BLACK,WHITE,"Welcome to use the program. If there are any bug,please to be associate with author QQ:136069699");
do
{
c=getch();
}while(c!=13);
puttext(x1,y1,x2,y2,buf);
}
/*************OK显示框**********/
/*******************主菜单**************/
int showmainmenu( int x1,int y1,int x2,int y2,int color,int backcolor,char **s,int n,int r)
/*show a menu*/
/* r is a number you want choose when show the dialog*/
/* n is a number of line you want show string in box*/
{
int x,y,i,j,k,old_r,old_x,old_y;
unsigned char c;
textbackground(BLUE);
textcolor(WHITE);
dbox(x1,y1,x2,y2,color,backcolor);
for(k=0;kn;k++)
{
gotoxy(x1+2,y1+k*2+2);
cprintf(" %-2s",s[k]);
} /*for K*/
old_y=y1+r*2+2;
old_r=r;
gotoxy(35,7); printf("首次库存物品");
gotoxy(35,9); printf(" 物品入库");
gotoxy(35,11); printf(" 物品出库");
gotoxy(35,13); printf(" 当前物品");
gotoxy(35,15); printf(" 查询物品");
gotoxy(35,17); printf(" 作者的话");
gotoxy(35,19); printf(" 退出 ");
do
{
if (r=0&&r=n)
{
textcolor(WHITE);
textbackground(BLUE);
gotoxy(x1+2,old_y);cprintf(" %-2s",s[old_r]);
textcolor(BLACK);
textbackground(WHITE);
gotoxy(x1+2,y1+r*2+2); cprintf(" %-2s",s[r]);
old_r=r;old_y=y1+r*2+2;
}
c=getch();
if(c==77||c==80) r++;
if(c==75||c==72) r=r+n-1;
r=r%n;
}while(!(c==13));
return r;
}
/*************主菜单**********/
/*******信息条*******/
messageline(int y,char color,char backcolor,char *str)
{
char c[78]={' '},s[79]={0},string[400]={0};
int i=1,j,n;
int k=0;
for(i=0;i77;i++) c=' ';
c[77]=' ';
i=0;
n=strlen(str);
strcpy(string,c);
strcat(string,str);
strcat(string,c);
textcolor(color);
textbackground(backcolor);
do{
k=i;
for(j=0;j78;j++)
{
s[j]=string[k]; k++;
}
s[78]=' ';
gotoxy(2,y);
cprintf("%78s",s);
i++;
if (i==78+n) i=1;
delay(10000);
}while(!kbhit());
}
/************信息条**********************/
学C语言一个月了,刚学完链表
现在终于能做个很菜的管理系统了!
希望大家能批评,再批评! 这样能重新激起学C的欲望!
希望过年的时候能做点好些的东西!
楼主 2016-02-05 18:52 回复
Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号
意见反馈 |
关于直线 |
版权声明 |
会员须知