求一个300行左右的简单的c语言程序

求一个300行左右的简单的c语言程序,第1张

#include<stdio.h>

#include<malloc.h>

#include<string.h>

#define LEN sizeof(struct record) /*对结构体长度进行宏定义*/

void menu()/*声明菜单函数*/

struct record*insert(struct record *head)/*声明添加函数 */

struct record*delet(struct record *head) /*声明删除函数 */

struct record*alter(struct record *head) /*声明修改函数 */

void search(struct record *head) /*声明查找函数*/

void show(struct record *head) /*声明显示函数*/

struct record *head /*定义全局结构体指针变量*/

int n=0/*定义全局变量*/

struct record /*声明结构体*/

{

char number[10]

char name[20]

char phone[20]

char adress[40]

char postcode[10]

char e_mail[30]

struct record *next

}

/******************************************************************************

* *

* 主函数 *

* *

*******************************************************************************/

main()

{

head=NULL

menu()

rewind(stdin)

}

/******************************************************************************

* *

* 菜单函数 *

* *

*******************************************************************************/

void menu()

{

int choice

printf("\n\t\t******************** 主菜单 ********************")

printf("\n\t\t*********** 1-添加纪录 2-查询纪录 ************")

printf("\n\t\t*********** 3-删除纪录 4-修改记录 ************")

printf("\n\t\t*********** 5-显示纪录 6-退出系统 ************")

printf("\n\t\t************************************************")

printf("\n\t\t请选择:")

scanf("%d",&choice)rewind(stdin)

printf("\n")

switch (choice)

{

case 1:

head=insert(head)

rewind(stdin)

menu()

break

case 2:

search(head)rewind(stdin)

menu()

break

case 3:

head=delet(head)

rewind(stdin)

menu()

break

case 4:

head=alter(head)

rewind(stdin)

menu()

break

case 5:

show(head)

rewind(stdin)

menu()

break

default:

printf("\n\t\t谢谢使用!!")

break

}

}

/******************************************************************************

* *

* 添加函数 *

* *

*******************************************************************************/

struct record *insert(struct record *head)

{

struct record *pp,*p1,*p2

pp=(struct record *)malloc(LEN)

printf("\n\t\t**************** 请输入用户信息 ****************\n")

printf("\n\t\t输入序号:")

scanf("%s",pp->number)rewind(stdin)

printf("\n\t\t输入姓名:")

scanf("%s",pp->name)rewind(stdin)

printf("\n\t\t输入电话号码:")

scanf("%s",pp->phone)rewind(stdin)

printf("\n\t\t输入地址:")

scanf("%s",pp->adress)rewind(stdin)

printf("\n\t\t输入邮编:")

scanf("%s",pp->postcode)rewind(stdin)

printf("\n\t\t输入e-mail:")

scanf("%s",pp->e_mail)rewind(stdin)

if(head==NULL)/*在表头插入1*/

{

head=pp

pp->next=NULL

}

else

{

p1=head

while((strcmp(pp->number,p1->number)>0)&&(p1->next!=NULL))

{

p2=p1

p1=p1->next

}

if(strcmp(pp->number,p1->number)<=0)

{

if(head==p1)

head=pp /*在表头插入2*/

else

p2->next=pp/*在表中插入*/

pp->next=p1

}

else /*在表尾插入*/

{

p1->next=pp

pp->next=NULL

}

}

printf("\t添加成功!请继续选择功能键!\n\n")

n=n+1

return(head)

}

/******************************************************************************

* *

* 删除函数 *

* *

*******************************************************************************/

struct record*delet(struct record * head)

{

struct record *p1,*p2

char number[10]

printf("\t请输入要删除用户的序号number:")

scanf("%s",&number)rewind(stdin)

if(head==NULL)

{

printf("\n\t通讯录无用户信息记录!!\n")

return(head)

}

p1=head

while(strcmp(number,p1->number)!=0&&p1->next!=NULL)

{

p2=p1

p1=p1->next

}

if(strcmp(number,p1->number)==0)

{

if(p1==head)

{

head=p1->next

printf("\t删除成功!请继续选择功能键!\n\n")

}

else

{

p2=p1->next

printf("\t已删 除的用户的序号为:%s\n",number)

printf("\t删除成功!请继续选择功能键!\n\n")

}

n=n-1

}

else printf("\t通讯录无该用户的信息记录!\n ")

return(head)

}

/******************************************************************************

* *

* 查询函数 *

* *

*******************************************************************************/

void search(struct record *head)

{

int a

char f_name[20],f_number[10]

struct record *p1,*p2

if(head==NULL)

{

printf("\t通讯录无用户信息记录\n")

return

}

else

{

printf("\t请你选择你查找的方式:\n\n\t\t1:序号\n\t\t2:姓名\n")

printf("\t\t请选择:")

scanf("%d",&a)rewind(stdin)

switch(a)

{case 1:

printf("\n\t请输入要查找用户的序号number:")

scanf("%s",&f_number)rewind(stdin)

p1=head

while(strcmp(p1->number,f_number)!=0)

{

if(p1->next==NULL)

{

printf("\n\t通讯录无此用户信息记录\n")

return

}

else

{

p2=p1->next

p1=p2

}

}

printf("\n\t要查找用户的基本信息为:\n")

printf("\t\t序号: %s\n\t\t姓名:%s\n\t\t电话号码:%s",p1->number,p1->name,p1->phone)

printf("\n\t\t地址:%s\n\t\t邮编:%s\n\t\te_mail:%s\n",p1->adress,p1->postcode,p1->e_mail)

break

case 2:

printf("\n\t请输入要查找用户的姓名name:")

scanf("%s",f_name)rewind(stdin)

p1=head

while(strcmp(p1->name,f_name)!=0)

{

if(p1->next==NULL)

{

printf("\n\t通讯录无此用户信息记录\n")

return

}

else

{

p2=p1->next

p1=p2

}

}

printf("\n\t要查找用户的基本信息为:\n")

printf("\t\t序号: %s\n\t\t姓名:%s\n\t\t电话号码:%s",p1->number,p1->name,p1->phone)

printf("\n\t\t地址:%s\n\t\t邮编:%s\n\t\te_mail:%s",p1->adress,p1->postcode,p1->e_mail)

break

}

}

}

/******************************************************************************

* *

* 显示函数 *

* *

*******************************************************************************/

void show(struct record *head)

{

int i

struct record *p1,*p2

p1=head

if(head==NULL)

{

printf("\t通讯录无用户信息记录\n")

return

}

else

{

for(i=1i<=ni++)

{

printf("\n\t第%d个用户的基本信息为:",i)

printf("\n\t\t序号: %s 姓名:%s 电话号码:%s \n\t\t地址:%s 邮编:%s e_mail:%s\n"

,p1->number,p1->name,p1->phone,p1->adress,p1->postcode,p1->e_mail)

p2=p1->next

p1=p2

}

}

}

/******************************************************************************

* *

* 修改函数 *

* *

*******************************************************************************/

struct record*alter(struct record*head)

{

struct record *p1,*p2

int choice1

char alter_number[10],alter_name[20],alter_phone[20],alter_adress[40],alter_postcode[10],alter_e_mail[30],choice2

p1=head

if(head==NULL)

{

printf("通讯录无用户信息记录\n")

return(head)

}

printf("\t请输入要修改的用户的序号number:")

scanf("%s",alter_number)

rewind(stdin)

while(strcmp(p1->number,alter_number)!=0)

{

if(p1->next==NULL)

{

printf("\n\t通讯录无此用户信息记录\n")

return(head)

}

else

{

p2=p1

p1=p1->next

}

}

if(strcmp(p1->number,alter_number)!=0)

{

printf("通讯录无用户信息记录\n")

return(head)

}

else

{

printf("\t要修改的用户的基本信息为:\n\t")

printf("\t序号: %s 姓名:%s 电话号码:%s 地址:%s 邮编:%s e_mail:%s\n"

,p1->number,p1->name,p1->phone,p1->adress,p1->postcode,p1->e_mail)

}

while(1)

{

printf("\t你是否要修改的用户的基本信息?(y&n)")

scanf("%c",&choice2)

rewind(stdin)

if(choice2=='y')

{

printf("\t请选择你要修改的项目:\n\t")

printf("1:姓名 2:电话号码3:地址4:邮编 5:e_mail\n")

printf("\t你选择的序号为: ")

scanf("%d",&choice1)

rewind(stdin)

switch(choice1)

{case 1:printf("\t请输入更改后的姓名")

scanf("%s",alter_name)rewind(stdin)

strcpy(p1->name,alter_name)

continue

case 2:printf("\t请输入更改后的电话号码")

scanf("%s",alter_phone)rewind(stdin)

strcpy(p1->phone,alter_phone)

continue

case 3:printf("\t请输入更改后的地址")

scanf("%s",alter_adress)rewind(stdin)

strcpy(p1->adress,alter_adress)

continue

case 4:printf("\t请输入更改后的邮编")

scanf("%s",&alter_postcode)rewind(stdin)strcpy(p1->postcode,alter_postcode)

continue

case 5:printf("\t请输入更改后的e_mail")

scanf("%s",alter_e_mail)rewind(stdin)

strcpy(p1->e_mail,alter_e_mail)

continue

}

printf("\n\t修改后用户的基本信息为:\n\t")

printf("\t序号: %s 姓名:%s 电话号码:%s 地址:%s 邮编:%s e_mail\n"

,p1->number,p1->name,p1->phone,p1->adress,p1->postcode,p1->e_mail)

}

else

{

printf("\n\t修改成功!!\n")

break

}

}

return(head)

}

黑白棋游戏

#include "graphics.h" /*图形系统头文件*/

#define LEFT 0x4b00 /*光标左键值*/

#define RIGHT 0x4d00 /*光标右键值*/

#define DOWN 0x5000 /*光标下键值*/

#define UP 0x4800 /*光标上键值*/

#define ESC 0x011b /* ESC键值*/

#define ENTER 0x1c0d /* 回车键值*/

int a[8][8]={0},key,score1,score2/*具体分数以及按键与存放棋子的变量*/

char playone[3],playtwo[3]/*两个人的得分转换成字符串输出*/

void playtoplay(void)/*人人对战函数*/

void DrawQp(void)/*画棋盘函数*/

void SetPlayColor(int x)/*设置棋子第一次的颜色*/

void MoveColor(int x,int y)/*恢复原来棋盘状态*/

int QpChange(int x,int y,int z)/*判断棋盘的变化*/

void DoScore(void)/*处理分数*/

void PrintScore(int n)/*输出成绩*/

void playWin(void)/*输出胜利者信息*/

/******主函数*********/

void main(void)

{

int gd=DETECT,gr

initgraph(&gd,&gr,"c:\\tc")/*初始化图形系统*/

DrawQp()/*画棋盘*/

playtoplay()/*人人对战*/

getch()

closegraph()/*关闭图形系统*/

}

void DrawQp()/*画棋盘*/

{

int i,j

score1=score2=0/*棋手一开始得分都为0*/

setbkcolor(BLUE)

for(i=100i<=420i+=40)

{

line(100,i,420,i)/*画水平线*/

line(i,100,i,420)/*画垂直线*/

}

setcolor(0)/*取消圆周围的一圈东西*/

setfillstyle(SOLID_FILL,15)/*白色实体填充模式*/

fillellipse(500,200,15,15)/*在显示得分的位置画棋*/

setfillstyle(SOLID_FILL,8)/*黑色实体填充模式*/

fillellipse(500,300,15,15)

a[3][3]=a[4][4]=1/*初始两个黑棋*/

a[3][4]=a[4][3]=2/*初始两个白棋*/

setfillstyle(SOLID_FILL,WHITE)

fillellipse(120+3*40,120+3*40,15,15)

fillellipse(120+4*40,120+4*40,15,15)

setfillstyle(SOLID_FILL,8)

fillellipse(120+3*40,120+4*40,15,15)

fillellipse(120+4*40,120+3*40,15,15)

score1=score2=2/*有棋后改变分数*/

DoScore()/*输出开始分数*/

}

void playtoplay()/*人人对战*/

{

int x,y,t=1,i,j,cc=0

while(1)/*换棋手走棋*/

{

x=120,y=80/*每次棋子一开始出来的坐标,x为行坐标,y为列坐标*/

while(1) /*具体一个棋手走棋的过程*/

{

PrintScore(1)/*输出棋手1的成绩*/

PrintScore(2)/*输出棋手2的成绩*/

SetPlayColor(t)/*t变量是用来判断棋手所执棋子的颜色*/

fillellipse(x,y,15,15)

key=bioskey(0)/*接收按键*/

if(key==ESC)/*跳出游戏*/

break

else

if(key==ENTER)/*如果按键确定就可以跳出循环*/

{

if(y!=80&&a[(x-120)/40][(y-120)/40]!=1

&&a[(x-120)/40][(y-120)/40]!=2)/*如果落子位置没有棋子*/

{

if(t%2==1)/*如果是棋手1移动*/

a[(x-120)/40][(y-120)/40]=1

else/*否则棋手2移动*/

a[(x-120)/40][(y-120)/40]=2

if(!QpChange(x,y,t))/*落子后判断棋盘的变化*/

{

a[(x-120)/40][(y-120)/40]=0/*恢复空格状态*/

cc++/*开始统计尝试次数*/

if(cc>=64-score1-score2) /*如果尝试超过空格数则停步*/

{

MoveColor(x,y)

fillellipse(x,y,15,15)

break

}

else

continue/*如果按键无效*/

}

DoScore()/*分数的改变*/

break/*棋盘变化了,则轮对方走棋*/

}

else/*已经有棋子就继续按键*/

continue

}

else /*四个方向按键的判断*/

if(key==LEFT&&x>120)/*左方向键*/

{

MoveColor(x,y)

fillellipse(x,y,15,15)

SetPlayColor(t)

x-=40

fillellipse(x,y,15,15)

}

else

if(key==RIGHT&&x<400&&y>80)/*右方向键*/

{

MoveColor(x,y)

fillellipse(x,y,15,15)

SetPlayColor(t)

x+=40

fillellipse(x,y,15,15)

}

else

if(key==UP&&y>120)/*上方向键*/

{

MoveColor(x,y)

fillellipse(x,y,15,15)

SetPlayColor(t)

y-=40

fillellipse(x,y,15,15)

}

else

if(key==DOWN&&y<400)/*下方向键*/

{

MoveColor(x,y)

fillellipse(x,y,15,15)

SetPlayColor(t)

y+=40

fillellipse(x,y,15,15)

}

}

if(key==ESC)/*结束游戏*/

break

if((score1+score2)==64||score1==0||score2==0)/*格子已经占满或一方棋子为0判断胜负*/

{

playWin()/*输出最后结果*/

break

}

t=t%2+1/*一方走后,改变棋子颜色即轮对方走*/

cc=0 /*计数值恢复为0*/

} /*endwhile*/

}

void SetPlayColor(int t)/*设置棋子颜色*/

{

if(t%2==1)

setfillstyle(SOLID_FILL,15)/*白色*/

else

setfillstyle(SOLID_FILL,8)/*灰色*/

}

void MoveColor(int x,int y)/*走了一步后恢复原来格子的状态*/

{

if(y<100)/*如果是从起点出发就恢复蓝色*/

setfillstyle(SOLID_FILL,BLUE)

else/*其他情况如果是1就恢复白色棋子,2恢复黑色棋子,或恢复蓝色棋盘*/

switch(a[(x-120)/40][(y-120)/40])

{

case 1:

setfillstyle(SOLID_FILL,15)break/*白色*/

case 2:

setfillstyle(SOLID_FILL,8)break/*黑色*/

default:

setfillstyle(SOLID_FILL,BLUE)/*蓝色*/

}

}

int QpChange(int x,int y,int t)/*判断棋盘的变化*/

{

int i,j,k,kk,ii,jj,yes

yes=0

i=(x-120)/40/*计算数组元素的行下标*/

j=(y-120)/40/*计算数组元素的列下标*/

SetPlayColor(t)/*设置棋子变化的颜色*/

/*开始往8个方向判断变化*/

if(j<6)/*往右边*/

{

for(k=j+1k<8k++)

if(a[i][k]==a[i][j]||a[i][k]==0)/*遇到自己的棋子或空格结束*/

break

if(a[i][k]!=0&&k<8)

{

for(kk=j+1kk<k&&k<8kk++)/*判断右边*/

{

a[i][kk]=a[i][j]/*改变棋子颜色*/

fillellipse(120+i*40,120+kk*40,15,15)

}

if(kk!=j+1) /*条件成立则有棋子改变过颜色*/

yes=1

}

}

if(j>1)/*判断左边*/

{

for(k=j-1k>=0k--)

if(a[i][k]==a[i][j]||!a[i][k])

break

if(a[i][k]!=0&&k>=0)

{

for(kk=j-1kk>k&&k>=0kk--)

{

a[i][kk]=a[i][j]

fillellipse(120+i*40,120+kk*40,15,15)

}

if(kk!=j-1)

yes=1

}

}

if(i<6)/*判断下边*/

{

for(k=i+1k<8k++)

if(a[k][j]==a[i][j]||!a[k][j])

break

if(a[k][j]!=0&&k<8)

{

for(kk=i+1kk<k&&k<8kk++)

{

a[kk][j]=a[i][j]

fillellipse(120+kk*40,120+j*40,15,15)

}

if(kk!=i+1)

yes=1

}

}

if(i>1)/*判断上边*/

{

for(k=i-1k>=0k--)

if(a[k][j]==a[i][j]||!a[k][j])

break

if(a[k][j]!=0&&k>=0)

{

for(kk=i-1kk>k&&k>=0kk--)

{

a[kk][j]=a[i][j]

fillellipse(120+kk*40,120+j*40,15,15)

}

if(kk!=i-1)

yes=1

}

}

if(i>1&&j<6)/*右上*/

{

for(k=i-1,kk=j+1k>=0&&kk<8k--,kk++)

if(a[k][kk]==a[i][j]||!a[k][kk])

break

if(a[k][kk]&&k>=0&&kk<8)

{

for(ii=i-1,jj=j+1ii>k&&k>=0ii--,jj++)

{

a[ii][jj]=a[i][j]

fillellipse(120+ii*40,120+jj*40,15,15)

}

if(ii!=i-1)

yes=1

}

}

if(i<6&&j>1)/*左下*/

{

for(k=i+1,kk=j-1k<8&&kk>=0k++,kk--)

if(a[k][kk]==a[i][j]||!a[k][kk])

break

if(a[k][kk]!=0&&k<8&&kk>=0)

{

for(ii=i+1,jj=j-1ii<k&&k<8ii++,jj--)

{

a[ii][jj]=a[i][j]

fillellipse(120+ii*40,120+jj*40,15,15)

}

if(ii!=i+1)

yes=1

}

}

if(i>1&&j>1)/*左上*/

{

for(k=i-1,kk=j-1k>=0&&kk>=0k--,kk--)

if(a[k][kk]==a[i][j]||!a[k][kk])

break

if(a[k][kk]!=0&&k>=0&&kk>=0)

{

for(ii=i-1,jj=j-1ii>k&&k>=0ii--,jj--)

{

a[ii][jj]=a[i][j]

fillellipse(120+ii*40,120+jj*40,15,15)

}

if(ii!=i-1)

yes=1

}

}

if(i<6&&j<6)/* 右下*/

{

for(k=i+1,kk=j+1kk<8&&kk<8k++,kk++)

if(a[k][kk]==a[i][j]||!a[k][kk])

break

if(a[k][kk]!=0&&kk<8&&k<8)

{

for(ii=i+1,jj=j+1ii<k&&k<8ii++,jj++)

{

a[ii][jj]=a[i][j]

fillellipse(120+ii*40,120+jj*40,15,15)

}

if(ii!=i+1)

yes=1

}

}

return yes/*返回是否改变过棋子颜色的标记*/

}

void DoScore()/*处理分数*/

{

int i,j

score1=score2=0/*重新开始计分数*/

for(i=0i<8i++)

for(j=0j<8j++)

if(a[i][j]==1)/*分别统计两个人的分数*/

score1++

else

if(a[i][j]==2)

score2++

}

void PrintScore(int playnum)/*输出成绩*/

{

if(playnum==1)/*清除以前的成绩*/

{

setfillstyle(SOLID_FILL,BLUE)

bar(550,100,640,400)

}

setcolor(RED)

settextstyle(0,0,4)/*设置文本输出样式*/

if(playnum==1)/*判断输出哪个棋手的分,在不同的位置输出*/

{

sprintf(playone,"%d",score1)

outtextxy(550,200,playone)

}

else

{

sprintf(playtwo,"%d",score2)

outtextxy(550,300,playtwo)

}

setcolor(0)

}

void playWin()/*输出最后的胜利者结果*/

{

settextstyle(0,0,4)

setcolor(12)

if(score2>score1)/*开始判断最后的结果*/

outtextxy(100,50,"black win!")

else

if(score2<score1)

outtextxy(100,50,"white win!")

else

outtextxy(60,50,"you all win!")

}

五子棋游戏

/*五子棋*/

#include<stdio.h>

#include<stdlib.h>

#include<graphics.h>

#include<bios.h>

#include<conio.h>

#define LEFT 0x4b00

#define RIGHT 0x4d00

#define DOWN 0x5000

#define UP 0x4800

#define ESC 0x011b

#define SPACE 0x3920

#define BILI 20

#define JZ 4

#define JS 3

#define N 19

int box[N][N]

int step_x,step_y

int key

int flag=1

void draw_box()

void draw_cicle(int x,int y,int color)

void change()

void judgewho(int x,int y)

void judgekey()

int judgeresult(int x,int y)

void attentoin()

void attention()

{

char ch

window(1,1,80,25)

textbackground(LIGHTBLUE)

textcolor(YELLOW)

clrscr()

gotoxy(15,2)

printf("游戏 *** 作规则:")

gotoxy(15,4)

printf("Play Rules:")

gotoxy(15,6)

printf("1、按左右上下方向键移动棋子")

gotoxy(15,8)

printf("1. Press Left,Right,Up,Down Key to move Piece")

gotoxy(15,10)

printf("2、按空格确定落棋子")

gotoxy(15,12)

printf("2. Press Space to place the Piece")

gotoxy(15,14)

printf("3、禁止在棋盘外按空格")

gotoxy(15,16)

printf("3. DO NOT press Space outside of the chessboard")

gotoxy(15,18)

printf("你是否接受上述的游戏规则(Y/N)")

gotoxy(15,20)

printf("Do you accept the above Playing Rules? [Y/N]:")

while(1)

{

gotoxy(60,20)

ch=getche()

if(ch=='Y'||ch=='y')

break

else if(ch=='N'||ch=='n')

{

window(1,1,80,25)

textbackground(BLACK)

textcolor(LIGHTGRAY)

clrscr()

exit(0)

}

gotoxy(51,12)

printf(" ")

}

}

void draw_box()

{

int x1,x2,y1,y2

setbkcolor(LIGHTBLUE)

setcolor(YELLOW)

gotoxy(7,2)

printf("Left, Right, Up, Down KEY to move, Space to put, ESC-quit.")

for(x1=1,y1=1,y2=18x1<=18x1++)

line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI)

for(x1=1,y1=1,x2=18y1<=18y1++)

line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI)

for(x1=1x1<=18x1++)

for(y1=1y1<=18y1++)

box[x1][y1]=0

}

void draw_circle(int x,int y,int color)

{

setcolor(color)

setlinestyle(SOLID_LINE,0,1)

x=(x+JZ)*BILI

y=(y+JS)*BILI

circle(x,y,8)

}

void judgekey()

{

int i

int j

switch(key)

{

case LEFT :

if(step_x-1<0)

break

else

{

for(i=step_x-1,j=step_yi>=1i--)

if(box[i][j]==0)

{

draw_circle(step_x,step_y,LIGHTBLUE)

break

}

if(i<1)break

step_x=i

judgewho(step_x,step_y)

break

}

case RIGHT :

if(step_x+1>18)

break

else

{

for(i=step_x+1,j=step_yi<=18i++)

if(box[i][j]==0)

{

draw_circle(step_x,step_y,LIGHTBLUE)

break

}

if(i>18)break

step_x=i

judgewho(step_x,step_y)

break

}

case DOWN :

if((step_y+1)>18)

break

else

{

for(i=step_x,j=step_y+1j<=18j++)

if(box[i][j]==0)

{

draw_circle(step_x,step_y,LIGHTBLUE)

break

}

if(j>18)break

step_y=j

judgewho(step_x,step_y)

break

}

case UP :

if((step_y-1)<0)

break

else

{

for(i=step_x,j=step_y-1j>=1j--)

if(box[i][j]==0)

{

draw_circle(step_x,step_y,LIGHTBLUE)

break

}

if(j<1)break

step_y=j

judgewho(step_x,step_y)

break

}

case ESC :

break

case SPACE :

if(step_x>=1&&step_x<=18&&step_y>=1&&step_y<=18)

{

if(box[step_x][step_y]==0)

{

box[step_x][step_y]=flag

if(judgeresult(step_x,step_y)==1)

{

sound(1000)

delay(1000)

nosound()

gotoxy(30,4)

if(flag==1)

{

setbkcolor(BLUE)

cleardevice()

setviewport(100,100,540,380,1)

/*定义一个图形窗口*/

setfillstyle(1,2)

/*绿色以实填充*/

setcolor(YELLOW)

rectangle(0,0,439,279)

floodfill(50,50,14)

setcolor(12)

settextstyle(1,0,5)

/*三重笔划字体, 水平放?5倍*/

outtextxy(20,20,"The White Win !")

setcolor(15)

settextstyle(3,0,5)

/*无衬笔划字体, 水平放大5倍*/

outtextxy(120,120,"The White Win !")

setcolor(14)

settextstyle(2,0,8)

getch()

closegraph()

exit(0)

}

if(flag==2)

{

setbkcolor(BLUE)

cleardevice()

setviewport(100,100,540,380,1)

/*定义一个图形窗口*/

setfillstyle(1,2)

/*绿色以实填充*/

setcolor(YELLOW)

rectangle(0,0,439,279)

floodfill(50,50,14)

setcolor(12)

settextstyle(1,0,8)

/*三重笔划字体, 水平放大8倍*/

outtextxy(20,20,"The Red Win !")

setcolor(15)

settextstyle(3,0,5)

/*无衬笔划字体, 水平放大5倍*/

outtextxy(120,120,"The Red Win !")

setcolor(14)

settextstyle(2,0,8)

getch()

closegraph()

exit(0)

}

}

change()

break

}

}

else

break

}

}

void change()

{

if(flag==1)

flag=2

else

flag=1

}

void judgewho(int x,int y)

{

if(flag==1)

draw_circle(x,y,15)

if(flag==2)

draw_circle(x,y,4)

}

int judgeresult(int x,int y)

{

int j,k,n1,n2

while(1)

{

n1=0

n2=0

/*水平向左数*/

for(j=x,k=yj>=1j--)

{

if(box[j][k]==flag)

n1++

else

break

}

/*水平向右数*/

for(j=x,k=yj<=18j++)

{

if(box[j][k]==flag)

n2++

else

break

}

if(n1+n2-1>=5)

{

return(1)

break

}

/*垂直向上数*/

n1=0

n2=0

for(j=x,k=yk>=1k--)

{

if(box[j][k]==flag)

n1++

else

break

}

/*垂直向下数*/

for(j=x,k=yk<=18k++)

{

if(box[j][k]==flag)

n2++

else

break

}

if(n1+n2-1>=5)

{

return(1)

break

}

/*向左上方数*/

n1=0

n2=0

for(j=x,k=yj>=1,k>=1j--,k--)

{

if(box[j][k]==flag)

n1++

else

break

}

/*向右下方数*/

for(j=x,k=yj<=18,k<=18j++,k++)

{

if(box[j][k]==flag)

n2++

else

break

}

if(n1+n2-1>=5)

{

return(1)

break

}

/*向右上方数*/

n1=0

n2=0

for(j=x,k=yj<=18,k>=1j++,k--)

{

if(box[j][k]==flag)

n1++

else

break

}

/*向左下方数*/

for(j=x,k=yj>=1,k<=18j--,k++)

{

if(box[j][k]==flag)

n2++

else

break

}

if(n1+n2-1>=5)

{

return(1)

break

}

return(0)

break

}

}

void main()

{

int gdriver=VGA,gmode=VGAHI

clrscr()

attention()

initgraph(&gdriver,&gmode,"c:\\tc")

/* setwritemode(XOR_PUT)*/

flag=1

draw_box()

do

{

step_x=0

step_y=0

/*draw_circle(step_x,step_y,8)*/

judgewho(step_x-1,step_y-1)

do

{

while(bioskey(1)==0)

key=bioskey(0)

judgekey()

}

while(key!=SPACE&&key!=ESC)

}

while(key!=ESC)

closegraph()

}

#include #include #include void select()/*自定义函数的全局声明*/ void input()void output()void sort()void search()void modify()void deleted()void save()void load()struct student { int numberchar name[9]char sexchar xy[20]char zy[20]int classesdouble jcjdouble pcjdouble zcj}struct student a[40]void main() { select()//调用选择函数 } void select() { int nsystem("cls")printf("|--------------------------------------------------------------|\n")printf("| 主菜单 |\n")printf("| 1. 输入功能 |\n")printf("| 2. 输出功能 |\n")printf("| 3. 排序功能 |\n")printf("| 4. 查询功能 |\n")printf("| 5. 修改功能 |\n")printf("| 6. 删除功能 |\n")printf("| 7. SAVE功能 |\n")printf("| 8. LOAD功能 |\n")printf("| 9. 退出程序 |\n")printf("|--------------------------------------------------------------|\n")printf(" 请你选择功能:")scanf("%d",&n)switch(n) { case 1: input()select()break/*当调用完输入函数之后,回到主菜单的函数select函数*/ case 2: output()select()breakcase 3: sort()select()breakcase 4: search()select()breakcase 5: modify()select()breakcase 6: deleted()select()breakcase 7: save()select()breakcase 8: load()select()breakcase 9: exit(0)break} getchar()getchar()system("pause")} void input() { int i,nsystem("cls")printf(" welcome to 输入功能\n\n\n")for(i=0i<=39i++) { printf("------------------------------------------------------------|\n")printf("| 是否要给1个同学做信息的输入 |\n")printf("| 1. 输入 |\n")printf("| 2. 结束输入 |\n")printf("------------------------------------------------------------|\n")printf(" 请你输入你的选择:")scanf("%d",&n)if(n==2) breakprintf("学号:")scanf("%d",&a[i].number)getchar()printf("姓名:")gets(a[i].name)printf("性别:")a[i].sex=getchar()getchar()printf("学院:")gets(a[i].xy)printf("专业:")gets(a[i].zy)printf("班级:")scanf("%d",&a[i].classes)printf("卷面成绩:")scanf("%lf",&a[i].jcj)printf("平时成绩:")scanf("%lf",&a[i].pcj)} getchar()getchar()system("pause")} void output() { int isystem("cls")printf(" welcome to 输出功能\n\n\n")printf("%-9s","学号")printf("%-9s","姓名")printf("%-5s","性别")printf("%-20s","学院")printf("%-20s","专业")printf("%-5s","班级")printf("%-9s","卷面成绩")printf("%-9s","平时成绩")printf("%-9s","总成绩")printf("\n")for(i=0i<=39i++) { a[i].zcj=a[i].jcj*0.6+a[i].pcjif(a[i].number == 0) breakprintf("%-9d",a[i].number)printf("%-9s",a[i].name)printf("%-5c",a[i].sex)printf("%-20s",a[i].xy)printf("%-20s",a[i].zy)printf("%-5d",a[i].classes)printf("%-9.2lf",a[i].jcj)printf("%-9.2lf",a[i].pcj)printf("%-9.2lf",a[i].zcj)printf("\n")} getchar()getchar()system("pause")} void sort() { int i,j,nstruct student tsystem("cls")printf(" welcome to 排序功能\n\n\n")printf("------------------------------------------------------------|\n")printf("| 排序菜单 |\n")printf("| 1. 按总分总高到低排序输出 |\n")printf("| 2. 按总分总低到高排序输出 |\n")printf("| 3. 退出排序功能 |\n")printf("------------------------------------------------------------|\n")printf(" 请你输入你的选择:")scanf("%d",&n)switch(n) { case 1: for(j=38j>=0j--) { for(i=0i<=ji++) { if(a[i].number == 0 || a[i+1].number == 0) breakelse { if(a[i].zcj <a[i+1].zcj) { t=a[i]a[i]=a[i+1]a[i+1]=t} } } } breakcase 2: for(j=38j>=0j--) { for(i=0i<=ji++) { if(a[i].number == 0 || a[i+1].number == 0) breakelse { if(a[i].zcj >a[i+1].zcj) { t=a[i]a[i]=a[i+1]a[i+1]=t} } } } breakcase 3: select()break} printf("%-9s","学号")printf("%-9s","姓名")printf("%-5s","性别")printf("%-20s","学院")printf("%-20s","专业")printf("%-5s","班级")printf("%-9s","卷面成绩")printf("%-9s","平时成绩")printf("%-9s","总成绩")printf("\n")for(i=0i<=39i++) { a[i].zcj=a[i].jcj*0.6+a[i].pcjif(a[i].number == 0) breakprintf("%-9d",a[i].number)printf("%-9s",a[i].name)printf("%-5c",a[i].sex)printf("%-20s",a[i].xy)printf("%-20s",a[i].zy)printf("%-5d",a[i].classes)printf("%-9.2lf",a[i].jcj)printf("%-9.2lf",a[i].pcj)printf("%-9.2lf",a[i].zcj)printf("\n")} getchar()getchar()system("pause")} void search() { int i,nchar search_name[9]system("cls")printf(" welcome to 查询功能\n\n\n")printf("------------------------------------------------------------|\n")printf("| 查询菜单 |\n")printf("| 1. 按姓名查询 |\n")printf("| 2. 按性别查询 |\n")printf("| 3. 按学号查询 |\n")printf("| 4. 按专业查询 |\n")printf("| 5. 按学院查询 |\n")printf("| 6. 按总成绩及格同学查询 |\n")printf("| 7. 退出查询功能 |\n")printf("------------------------------------------------------------|\n")printf(" 请你输入你的选择:")scanf("%d",&n)getchar()switch(n) { case 1: printf("\n\n\n请你输入要查询某同学的姓名:")gets(search_name)printf("%-9s","学号")printf("%-9s","姓名")printf("%-5s","性别")printf("%-20s","学院")printf("%-20s","专业")printf("%-5s","班级")printf("%-9s","卷面成绩")printf("%-9s","平时成绩")printf("%-9s","总成绩")printf("\n")for(i=0i<=39i++) { if(a[i].number==0) breakelse { if(strcmp(a[i].name,search_name) == 0) { printf("%-9d",a[i].number)printf("%-9s",a[i].name)printf("%-5c",a[i].sex)printf("%-20s",a[i].xy)printf("%-20s",a[i].zy)printf("%-5d",a[i].classes)printf("%-9.2lf",a[i].jcj)printf("%-9.2lf",a[i].pcj)printf("%-9.2lf",a[i].zcj)printf("\n")} } } breakcase 2: break} getchar()getchar()system("pause")} void modify() { int i,n,mint modify_number/* 输入修改对象的学号*/ system("cls")printf(" welcome to 修改功能\n\n\n")printf("------------------------------------------------------------|\n")printf("| 修改菜单 |\n")printf("| 1. 修改全部信息 |\n")printf("| 2. 修改具体某项信息 |\n")printf("| 3. 退出修改功能 |\n")printf("------------------------------------------------------------|\n")printf(" 请你输入你的选择:")scanf("%d",&n)getchar()switch(n) { case 1: printf("\n\n请你输入你要修改的对象的学号:")scanf("%d",&modify_number)for(i=0i<=39i++) { if(modify_number == a[i].number) { printf("学号:")scanf("%d",&a[i].number)getchar()printf("姓名:")gets(a[i].name)printf("性别:")a[i].sex=getchar()getchar()printf("学院:")gets(a[i].xy)printf("专业:")gets(a[i].zy)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11374858.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存