外星人源码论坛 骗局:初级C语言源代码

来源:百度文库 编辑:神马品牌网 时间:2024/04/27 21:28:25
各位朋友,为了巩固学习,帮我搞点初级C语言源代码得我来看哈几咯!
我在果了向你表示我最追真诚的感谢。
哥哥啊 !你这里的代码太深奥了吧!我只是学C语言基础,现在还没有编游戏的能力,麻烦你搞点简单的代码,例如学生成绩管理系统,DOS下远行的,不要界面的。拜托哒!

好的哦
#define N 200
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
int i,key;
int score=0;/*得分*/
int gamespeed=50000;/*游戏速度自己调整*/
struct Food
{
int x;/*食物的横坐标*/
int y;/*食物的纵坐标*/
int yes;/*判断是否要出现食物的变量*/
}food;/*食物的结构体*/
struct Snake
{
int x[N];
int y[N];
int node;/*蛇的节数*/
int direction;/*蛇移动方向*/
int life;/* 蛇的生命,0活着,1死亡*/
}snake;
void Init(void);/*图形驱动*/
void Close(void);/*图形结束*/
void DrawK(void);/*开始画面*/
void GameOver(void);/*结束游戏*/
void GamePlay(void);/*玩游戏具体过程*/
void PrScore(void);/*输出成绩*/
/*主函数*/
void main(void)
{
Init();/*图形驱动*/
DrawK();/*开始画面*/
GamePlay();/*玩游戏具体过程*/
Close();/*图形结束*/
}
/*图形驱动*/
void Init(void)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc");
cleardevice();
}
/*开始画面,左上角坐标为(50,40),右下角坐标为(610,460)的围墙*/
void DrawK(void)
{
/*setbkcolor(LIGHTGREEN);*/
setcolor(11);
setlinestyle(SOLID_LINE,0,THICK_WIDTH);/*设置线型*/
for(i=50;i<=600;i+=10)/*画围墙*/
{
rectangle(i,40,i+10,49); /*上边*/
rectangle(i,451,i+10,460);/*下边*/
}
for(i=40;i<=450;i+=10)
{
rectangle(50,i,59,i+10); /*左边*/
rectangle(601,i,610,i+10);/*右边*/
}
}
/*玩游戏具体过程*/
void GamePlay(void)
{
randomize();/*随机数发生器*/
food.yes=1;/*1表示需要出现新食物,0表示已经存在食物*/
snake.life=0;/*活着*/
snake.direction=1;/*方向往右*/
snake.x[0]=100;snake.y[0]=100;/*蛇头*/
snake.x[1]=110;snake.y[1]=100;
snake.node=2;/*节数*/
PrScore();/*输出得分*/
while(1)/*可以重复玩游戏,压ESC键结束*/
{
while(!kbhit())/*在没有按键的情况下,蛇自己移动身体*/
{
if(food.yes==1)/*需要出现新食物*/
{
food.x=rand()%400+60;
food.y=rand()%350+60;
while(food.x%10!=0)/*食物随机出现后必须让食物能够在整格内,这样才可以让蛇吃到*/
food.x++;
while(food.y%10!=0)
food.y++;
food.yes=0;/*画面上有食物了*/
}
if(food.yes==0)/*画面上有食物了就要显示*/
{
setcolor(GREEN);
rectangle(food.x,food.y,food.x+10,food.y-10);
}
for(i=snake.node-1;i>0;i--)/*蛇的每个环节往前移动,也就是贪吃蛇的关键算法*/
{
snake.x[i]=snake.x[i-1];
snake.y[i]=snake.y[i-1];
}
/*1,2,3,4表示右,左,上,下四个方向,通过这个判断来移动蛇头*/
switch(snake.direction)
{
case 1:snake.x[0]+=10;break;
case 2: snake.x[0]-=10;break;
case 3: snake.y[0]-=10;break;
case 4: snake.y[0]+=10;break;
}
for(i=3;i<snake.node;i++)/*从蛇的第四节开始判断是否撞到自己了,因为蛇头为两节,第三节不可能拐过来*/
{
if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])
{
GameOver();/*显示失败*/
snake.life=1;
break;
}
}
if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55||
snake.y[0]>455)/*蛇是否撞到墙壁*/
{
GameOver();/*本次游戏结束*/
snake.life=1; /*蛇死*/
}
if(snake.life==1)/*以上两种判断以后,如果蛇死就跳出内循环,重新开始*/
break;
if(snake.x[0]==food.x&&snake.y[0]==food.y)/*吃到食物以后*/
{
setcolor(0);/*把画面上的食物东西去掉*/
rectangle(food.x,food.y,food.x+10,food.y-10);
snake.x[snake.node]=-20;snake.y[snake.node]=-20;
/*新的一节先放在看不见的位置,下次循环就取前一节的位置*/
snake.node++;/*蛇的身体长一节*/
food.yes=1;/*画面上需要出现新的食物*/
score+=10;
PrScore();/*输出新得分*/
}
setcolor(4);/*画出蛇*/
for(i=0;i<snake.node;i++)
rectangle(snake.x[i],snake.y[i],snake.x[i]+10,
snake.y[i]-10);
delay(gamespeed);
setcolor(0);/*用黑色去除蛇的的最后一节*/
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],
snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);
} /*endwhile(!kbhit)*/
if(snake.life==1)/*如果蛇死就跳出循环*/
break;
key=bioskey(0);/*接收按键*/
if(key==ESC)/*按ESC键退出*/
break;
else
if(key==UP&&snake.direction!=4)
/*判断是否往相反的方向移动*/
snake.direction=3;
else
if(key==RIGHT&&snake.direction!=2)
snake.direction=1;
else
if(key==LEFT&&snake.direction!=1)
snake.direction=2;
else
if(key==DOWN&&snake.direction!=3)
snake.direction=4;
}/*endwhile(1)*/
}
/*游戏结束*/
void GameOver(void)
{
cleardevice();
PrScore();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(200,200,"GAME OVER");
getch();
}
/*输出成绩*/
void PrScore(void)
{
char str[10];
setfillstyle(SOLID_FILL,YELLOW);
bar(50,15,220,35);
setcolor(6);
settextstyle(0,0,2);
sprintf(str,"score:%d",score);
outtextxy(55,20,str);
}
/*图形结束*/
void Close(void)
{
getch();
closegraph();
}
#include <dos.h> /*DOS接口函数*/
#include <math.h> /*数学函数的定义*/
#include <conio.h> /*屏幕操作函数*/
#include <stdio.h> /*I/O函数*/
#include <stdlib.h> /*库函数*/
#include <stdarg.h> /*变量长度参数表*/
#include <graphics.h> /*图形函数*/
#include <string.h> /*字符串函数*/
#include <ctype.h> /*字符操作函数*/
#define UP 0x48 /*光标上移键*/
#define DOWN 0x50 /*光标下移键*/
#define LEFT 0x4b /*光标左移键*/
#define RIGHT 0x4d /*光标右移键*/
#define ENTER 0x0d /*回车键*/
void *rar; /*全局变量,保存光标图象*/
struct palettetype palette; /*使用调色板信息*/
int GraphDriver; /* 图形设备驱动*/
int GraphMode; /* 图形模式值*/
int ErrorCode; /* 错误代码*/
int MaxColors; /* 可用颜色的最大数值*/
int MaxX, MaxY; /* 屏幕的最大分辨率*/
double AspectRatio; /* 屏幕的像素比*/
void drawboder(void); /*画边框函数*/
void initialize(void); /*初始化函数*/
void computer(void); /*计算器计算函数*/
void changetextstyle(int font, int direction, int charsize); /*改变文本样式函数*/
void mwindow(char *header); /*窗口函数*/
int specialkey(void) ; /*获取特殊键函数*/
int arrow(); /*设置箭头光标函数*/
/*主函数*/
int main()
{
initialize();/* 设置系统进入图形模式 */
computer(); /*运行计算器 */
closegraph();/*系统关闭图形模式返回文本模式*/
return(0); /*结束程序*/
}
/* 设置系统进入图形模式 */
void initialize(void)
{
int xasp, yasp; /* 用于读x和y方向纵横比*/
GraphDriver = DETECT; /* 自动检测显示器*/
initgraph( &GraphDriver, &GraphMode, "" );
/*初始化图形系统*/
ErrorCode = graphresult(); /*读初始化结果*/
if( ErrorCode != grOk ) /*如果初始化时出现错误*/
{
printf("Graphics System Error: %s\n",
grapherrormsg( ErrorCode ) ); /*显示错误代码*/
exit( 1 ); /*退出*/
}
getpalette( &palette ); /* 读面板信息*/
MaxColors = getmaxcolor() + 1; /* 读取颜色的最大值*/
MaxX = getmaxx(); /* 读屏幕尺寸 */
MaxY = getmaxy(); /* 读屏幕尺寸 */
getaspectratio( &xasp, &yasp ); /* 拷贝纵横比到变量中*/
AspectRatio = (double)xasp/(double)yasp;/* 计算纵横比值*/
}
/*计算器函数*/
void computer(void)
{
struct viewporttype vp; /*定义视口类型变量*/
int color, height, width;
int x, y,x0,y0, i, j,v,m,n,act,flag=1;
float num1=0,num2=0,result; /*操作数和计算结果变量*/
char cnum[5],str2[20]={""},c,temp[20]={""};
char str1[]="1230.456+-789*/Qc=^%";/* 定义字符串在按钮图形上显示的符号 */
mwindow( "Calculator" ); /* 显示主窗口 */
color = 7; /*设置灰颜色值*/
getviewsettings( &vp ); /* 读取当前窗口的大小*/
width=(vp.right+1)/10; /* 设置按钮宽度 */
height=(vp.bottom-10)/10 ; /*设置按钮高度 */
x = width /2; /*设置x的坐标值*/
y = height/2; /*设置y的坐标值*/
setfillstyle(SOLID_FILL, color+3);
bar( x+width*2, y, x+7*width, y+height );
/*画一个二维矩形条显示运算数和结果*/
setcolor( color+3 ); /*设置淡绿颜色边框线*/
rectangle( x+width*2, y, x+7*width, y+height );
/*画一个矩形边框线*/
setcolor(RED); /*设置颜色为红色*/
outtextxy(x+3*width,y+height/2,"0."); /*输出字符串"0."*/
x =2*width-width/2; /*设置x的坐标值*/
y =2*height+height/2; /*设置y的坐标值*/
for( j=0 ; j<4 ; ++j ) /*画按钮*/
{
for( i=0 ; i<5 ; ++i )
{
setfillstyle(SOLID_FILL, color);
setcolor(RED);
bar( x, y, x+width, y+height ); /*画一个矩形条*/
rectangle( x, y, x+width, y+height );
sprintf(str2,"%c",str1[j*5+i]);
/*将字符保存到str2中*/
outtextxy( x+(width/2), y+height/2, str2);
x =x+width+ (width / 2) ; /*移动列坐标*/
}
y +=(height/2)*3; /* 移动行坐标*/
x =2*width-width/2; /*复位列坐标*/
}
x0=2*width;
y0=3*height;
x=x0;
y=y0;
gotoxy(x,y); /*移动光标到x,y位置*/
arrow(); /*显示光标*/
putimage(x,y,rar,XOR_PUT);
m=0;
n=0;
strcpy(str2,""); /*设置str2为空串*/
while((v=specialkey())!=45) /*当压下Alt+x键结束程序,否则执行下面的循环*/
{
while((v=specialkey())!=ENTER) /*当压下键不是回车时*/
{
putimage(x,y,rar,XOR_PUT); /*显示光标图象*/
if(v==RIGHT) /*右移箭头时新位置计算*/
if(x>=x0+6*width)
/*如果右移,移到尾,则移动到最左边字符位置*/
{
x=x0;
m=0;
}
else
{
x=x+width+width/2;
m++;
} /*否则,右移到下一个字符位置*/
if(v==LEFT) /*左移箭头时新位置计算*/
if(x<=x0)
{
x=x0+6*width;
m=4;
} /*如果移到头,再左移,则移动到最右边字符位置*/
else
{
x=x-width-width/2;
m--;
} /*否则,左移到前一个字符位置*/
if(v==UP) /*上移箭头时新位置计算*/
if(y<=y0)
{
y=y0+4*height+height/2;
n=3;
} /*如果移到头,再上移,则移动到最下边字符位置*/
else
{
y=y-height-height/2;
n--;
} /*否则,移到上边一个字符位置*/
if(v==DOWN) /*下移箭头时新位置计算*/
if(y>=7*height)
{
y=y0;
n=0;
} /*如果移到尾,再下移,则移动到最上边字符位置*/
else
{
y=y+height+height/2;
n++;
} /*否则,移到下边一个字符位置*/
putimage(x,y,rar,XOR_PUT); /*在新的位置显示光标箭头*/
}
c=str1[n*5+m]; /*将字符保存到变量c中*/
if(isdigit(c)||c=='.') /*判断是否是数字或小数点*/
{
if(flag==-1) /*如果标志为-1,表明为负数*/
{
strcpy(str2,"-"); /*将负号连接到字符串中*/
flag=1;
} /*将标志值恢复为1*/
sprintf(temp,"%c",c); /*将字符保存到字符串变量temp中*/
strcat(str2,temp); /*将temp中的字符串连接到str2中*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,str2); /*显示字符串*/
}
if(c=='+')
{
num1=atof(str2); /*将第一个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=1; /*做计算加法标志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='-')
{
if(strcmp(str2,"")==0) /*如果str2为空,说明是负号,而不是减号*/
flag=-1; /*设置负数标志*/
else
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=2; /*做计算减法标志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*画矩形*/
outtextxy(5*width,height,"0."); /*显示字符串*/
}
}
if(c=='*')
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=3; /*做计算乘法标志值*/
setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='/')
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=4; /*做计算除法标志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='^')
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=5; /*做计算乘方标志值*/
setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*画矩形*/
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='%')
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=6; /*做计算模运算乘方标志值*/
setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*画矩形*/
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='=')
{
num2=atof(str2); /*将第二个操作数转换为浮点数*/
switch(act) /*根据运算符号计算*/
{
case 1:result=num1+num2;break; /*做加法*/
case 2:result=num1-num2;break; /*做减法*/
case 3:result=num1*num2;break; /*做乘法*/
case 4:result=num1/num2;break; /*做除法*/
case 5:result=pow(num1,num2);break; /*做x的y次方*/
case 6:result=fmod(num1,num2);break; /*做模运算*/
}
setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆盖结果区*/
sprintf(temp,"%f",result); /*将结果保存到temp中*/
outtextxy(5*width,height,temp); /*显示结果*/
}
if(c=='c')
{
num1=0; /*将两个操作数复位0,符号标志为1*/
num2=0;
flag=1;
strcpy(str2,""); /*将str2清空*/
setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆盖结果区*/
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='Q')exit(0); /*如果选择了q回车,结束计算程序*/
}
putimage(x,y,rar,XOR_PUT); /*在退出之前消去光标箭头*/
return; /*返回*/
}
/*窗口函数*/
void mwindow( char *header )
{
int height;
cleardevice(); /* 清除图形屏幕 */
setcolor( MaxColors - 1 ); /* 设置当前颜色为白色*/
setviewport( 20, 20, MaxX/2, MaxY/2, 1 ); /* 设置视口大小 */
height = textheight( "H" ); /* 读取基本文本大小 */
settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );/*设置文本样式*/
settextjustify( CENTER_TEXT, TOP_TEXT );/*设置字符排列方式*/
outtextxy( MaxX/4, 2, header ); /*输出标题*/
setviewport( 20,20+height+4, MaxX/2+4, MaxY/2+20, 1 ); /*设置视口大小*/
drawboder(); /*画边框*/
}
void drawboder(void) /*画边框*/
{
struct viewporttype vp; /*定义视口类型变量*/
setcolor( MaxColors - 1 ); /*设置当前颜色为白色 */
setlinestyle( SOLID_LINE, 0, NORM_WIDTH );/*设置画线方式*/
getviewsettings( &vp );/*将当前视口信息装入vp所指的结构中*/
rectangle( 0, 0, vp.right-vp.left, vp.bottom-vp.top ); /*画矩形边框*/
}
/*设计鼠标图形函数*/
int arrow()
{
int size;
int raw[]={4,4,4,8,6,8,14,16,16,16,8,6,8,4,4,4}; /*定义多边形坐标*/
setfillstyle(SOLID_FILL,2); /*设置填充模式*/
fillpoly(8,raw); /*画出一光标箭头*/
size=imagesize(4,4,16,16); /*测试图象大小*/
rar=malloc(size); /*分配内存区域*/
getimage(4,4,16,16,rar); /*存放光标箭头图象*/
putimage(4,4,rar,XOR_PUT); /*消去光标箭头图象*/
return 0;
}
/*按键函数*/
int specialkey(void)
{
int key;
while(bioskey(1)==0); /*等待键盘输入*/
key=bioskey(0); /*键盘输入*/
key=key&0xff? key&0xff:key>>8; /*只取特殊键的扫描值,其余为0*/
return(key); /*返回键值*/
}
#include <dos.h> /*DOS接口函数*/
#include <math.h> /*数学函数的定义*/
#include <conio.h> /*屏幕操作函数*/
#include <stdio.h> /*I/O函数*/
#include <stdlib.h> /*库函数*/
#include <stdarg.h> /*变量长度参数表*/
#include <graphics.h> /*图形函数*/
#include <string.h> /*字符串函数*/
#include <ctype.h> /*字符操作函数*/
#define UP 0x48 /*光标上移键*/
#define DOWN 0x50 /*光标下移键*/
#define LEFT 0x4b /*光标左移键*/
#define RIGHT 0x4d /*光标右移键*/
#define ENTER 0x0d /*回车键*/
void *rar; /*全局变量,保存光标图象*/
struct palettetype palette; /*使用调色板信息*/
int GraphDriver; /* 图形设备驱动*/
int GraphMode; /* 图形模式值*/
int ErrorCode; /* 错误代码*/
int MaxColors; /* 可用颜色的最大数值*/
int MaxX, MaxY; /* 屏幕的最大分辨率*/
double AspectRatio; /* 屏幕的像素比*/
void drawboder(void); /*画边框函数*/
void initialize(void); /*初始化函数*/
void computer(void); /*计算器计算函数*/
void changetextstyle(int font, int direction, int charsize); /*改变文本样式函数*/
void mwindow(char *header); /*窗口函数*/
int specialkey(void) ; /*获取特殊键函数*/
int arrow(); /*设置箭头光标函数*/
/*主函数*/
int main()
{
initialize();/* 设置系统进入图形模式 */
computer(); /*运行计算器 */
closegraph();/*系统关闭图形模式返回文本模式*/
return(0); /*结束程序*/
}
/* 设置系统进入图形模式 */
void initialize(void)
{
int xasp, yasp; /* 用于读x和y方向纵横比*/
GraphDriver = DETECT; /* 自动检测显示器*/
initgraph( &GraphDriver, &GraphMode, "" );
/*初始化图形系统*/
ErrorCode = graphresult(); /*读初始化结果*/
if( ErrorCode != grOk ) /*如果初始化时出现错误*/
{
printf("Graphics System Error: %s\n",
grapherrormsg( ErrorCode ) ); /*显示错误代码*/
exit( 1 ); /*退出*/
}
getpalette( &palette ); /* 读面板信息*/
MaxColors = getmaxcolor() + 1; /* 读取颜色的最大值*/
MaxX = getmaxx(); /* 读屏幕尺寸 */
MaxY = getmaxy(); /* 读屏幕尺寸 */
getaspectratio( &xasp, &yasp ); /* 拷贝纵横比到变量中*/
AspectRatio = (double)xasp/(double)yasp;/* 计算纵横比值*/
}
/*计算器函数*/
void computer(void)
{
struct viewporttype vp; /*定义视口类型变量*/
int color, height, width;
int x, y,x0,y0, i, j,v,m,n,act,flag=1;
float num1=0,num2=0,result; /*操作数和计算结果变量*/
char cnum[5],str2[20]={""},c,temp[20]={""};
char str1[]="1230.456+-789*/Qc=^%";/* 定义字符串在按钮图形上显示的符号 */
mwindow( "Calculator" ); /* 显示主窗口 */
color = 7; /*设置灰颜色值*/
getviewsettings( &vp ); /* 读取当前窗口的大小*/
width=(vp.right+1)/10; /* 设置按钮宽度 */
height=(vp.bottom-10)/10 ; /*设置按钮高度 */
x = width /2; /*设置x的坐标值*/
y = height/2; /*设置y的坐标值*/
setfillstyle(SOLID_FILL, color+3);
bar( x+width*2, y, x+7*width, y+height );
/*画一个二维矩形条显示运算数和结果*/
setcolor( color+3 ); /*设置淡绿颜色边框线*/
rectangle( x+width*2, y, x+7*width, y+height );
/*画一个矩形边框线*/
setcolor(RED); /*设置颜色为红色*/
outtextxy(x+3*width,y+height/2,"0."); /*输出字符串"0."*/
x =2*width-width/2; /*设置x的坐标值*/
y =2*height+height/2; /*设置y的坐标值*/
for( j=0 ; j<4 ; ++j ) /*画按钮*/
{
for( i=0 ; i<5 ; ++i )
{
setfillstyle(SOLID_FILL, color);
setcolor(RED);
bar( x, y, x+width, y+height ); /*画一个矩形条*/
rectangle( x, y, x+width, y+height );
sprintf(str2,"%c",str1[j*5+i]);
/*将字符保存到str2中*/
outtextxy( x+(width/2), y+height/2, str2);
x =x+width+ (width / 2) ; /*移动列坐标*/
}
y +=(height/2)*3; /* 移动行坐标*/
x =2*width-width/2; /*复位列坐标*/
}
x0=2*width;
y0=3*height;
x=x0;
y=y0;
gotoxy(x,y); /*移动光标到x,y位置*/
arrow(); /*显示光标*/
putimage(x,y,rar,XOR_PUT);
m=0;
n=0;
strcpy(str2,""); /*设置str2为空串*/
while((v=specialkey())!=45) /*当压下Alt+x键结束程序,否则执行下面的循环*/
{
while((v=specialkey())!=ENTER) /*当压下键不是回车时*/
{
putimage(x,y,rar,XOR_PUT); /*显示光标图象*/
if(v==RIGHT) /*右

main()
{
printf("Hello, World !");
/*最初级的C语言源代码*/
getch();
}

学生成绩管理系统,DOS下远行的

/* HELLO.C - Hello, world ----my first real c program it take me n days*/

#include "stdio.h"
#include "conio.h"
#define leaths 10
#define kemus 4
#define lowest 0
#define highest 100
#define zfcc 10
struct student
{char num[zfcc];
char name[zfcc];
char sex[2];
float score[kemus];

}stu[leaths]; int i=1,j,k,kg=0,subject,leath=4; char flag='y';
main()
{
zjiemian();

print();
for(;flag=='y';)
{zjiemian1();

printf("\n\t\t%c *****continue?****** %c\n\t\ty to continue n to exit\n",2,2);
for(kg=0;kg==0;){flag=getchar(); /*询问用户是否继续操作*/
if(flag=='y'||flag=='n') kg=1;}
}
printf("\n\t\tdo you want to save the date");
printf("\n\t\tinput y to save or n to exit\n");
for(kg=0;kg==0;){flag=getchar();
if(flag=='y'||flag=='n') { kg=1;if(flag=='y')save1();}}
printf("\t\t%c thanks for using this program\npress any key to out",2);
getch();
}
/*选择法从大到小排序*/ px(struct student *p,int n,int sj){
if(sj==1){for(i=1;i<leath;i++) /*i到leath才终止是为了使最后的学生名次被赋值*/
{k=i;
for(j=i+1;j<leath;j++)
if((*(p+k)).score[n]< (*(p+j)).score[n] )
k=j;
if(k!=i){ stu[0]=stu[i];stu[i]=stu[k];stu[k]=stu[0];}
stu[i].score[kemus-1]=i;
}
}
else {for(i=1;i<leath;i++) /*i到leath才终止是为了使最后的学生名次被赋值*/
{k=i;
for(j=i+1;j<leath;j++)
if((*(p+k)).score[n]> (*(p+j)).score[n] )
k=j;
if(k!=i){ stu[0]=stu[i];stu[i]=stu[k];stu[k]=stu[0];}
stu[i].score[kemus-1]=leath-i;

} }

}
/*二分查找*/ erf(struct student *p,float *searchnum,int n)
{
int head=1,end=leath-1,middle,pd=0;
if(((*(p+head)).score[n]>=*searchnum)&&((*(p+end)).score[n]<=*searchnum)
)
for(;(end>=head)&&(pd==0);)
{middle=(end+head)/2;
if((*(p+middle)).score[n]==*searchnum){pd=1;
printf("\nstudent %s'score is %5.1f\n",(*(p+middle)).name,*searchnum);
printf("\nnum name \tsex mingci scores\t ave \n");
printonedate();
/*加入两个FOR循环以防成绩相同*/
for(i=1;((middle-i)>=head)&&((*(p+middle-i)).score[n]==*searchnum);i++)
{printf("\nstudent %s'score is %5.1f\n",(*(p+middle-i)).name,*searchnum);
printonedate();}

for(i=1;((middle+i)<=end)&&((*(p+middle+i)).score[n]==*searchnum);i++)
{printf("\nstudent %s'score is %5.1f\n",(*(p+middle+i)).name,*searchnum);
printonedate();}
}
else if((*(p+middle)).score[n]>*searchnum)
head=middle+1;
else
end=middle-1;
}

if(pd==0)printf("\n%5.1f not found\n",*searchnum); }

/*屏幕输出*/ print(){printf("\nnum name \tsex mingci scores\t ave \n");
for(i=1;i<leath;i++)
{printonedate(i);}
}
/*打印一个数据*/printonedate(int i){printf("%-5s %-10s %s %2d",
stu[i].num,stu[i].name,stu[i].sex,(int)stu[i].score[kemus-1]);
for(k=0;k<kemus-1;k++)
printf(" %5.1f",stu[i].score[k]);
printf("\n");}

/*保存文件*/save(){FILE *fp;

if((fp=fopen("score.txt","wb"))==NULL)/*如果保存错误就退出或重试*/
{printf("xannot open the file student\n");printf("\ttry again?\n\t1:---yes\t0:---no\n");
for(kg=0,subject=-1;kg==0;)
{fflush(stdin);
scanf("%d",&subject);
if(subject==0){kg=1;exit(0);}
else if(subject==1){kg=1;readen();}
if(kg==0) printf("error input\n");}
}
for(i=1;i<leath;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("cant not write\n");
fclose(fp);
}

/*从文件中读取数组*/ readen(){
FILE *fp;
if((fp=fopen("score.txt","rb"))==NULL)
{printf("cannot open the file student\n");
printf("\ttry again?\n\t1:---yes\t0:---no\n");/*如果读取错误就退出或重试*/
for(kg=0,subject=-1;kg==0;)
{fflush(stdin);
scanf("%d",&subject);
if(subject==0){kg=1;exit(0);}
else if(subject==1){kg=1;readen();}
if(kg==0) printf("error input\n");}
}
for(leath=1;fread(&stu[leath],sizeof(struct student),1,fp)!=0;leath++);
fclose(fp);
printf("read %d students\n",leath);
}
/*从键盘中读取数组*/ keyboardinput(){float sum;
printf("rember you must press enter when you input a score\n\nhow many student do you want to input?\n");
for(kg=0;kg==0;)
{ fflush(stdin);
scanf("%d",&leath);
if(leath>=0)kg=1;
if(kg==0) printf("error input\n");}leath++;
for(i=1;i<leath;i++)
{ scanonce(i);
stu[i].score[kemus-1]=i;printf("%f\n",stu[i].score[kemus-1]);}

}
/*界面*/ zjiemian()
{printf("\n\t************************************************\n");
printf("\n\t------------------------------------------------\n");
printf("\t what can I do for you\n");
printf("\t %c 0:\tread the students form file student.txt\n",15);
printf("\t %c 1:\tscanf the students form keyboard\n\t %c 2:\tcha ru\n\t %c 3:\tshan chu\n\t %c 4:\texit"
,15,15,15,1);
printf("\n\t------------------------------------------------\n");
printf("\n\t************************************************\n");
for(kg=0,subject=-1;kg==0;){ fflush(stdin); /*这是群上同学(158359755)
找到的函数,作用是清除掉键盘缓冲区*//*等待用户选择操作。设置FOR循环以防出现意外*/
scanf("%d",&subject);if(subject>=0&&subject<=4)kg=1;
if(kg==0) printf("\t%c\terror input\n",1);}
if(subject==1) keyboardinput();
else if(subject==0) readen();
else if(subject==2)insert();
else if(subject==3)delet();
else exit(0);}
/*界面1*/zjiemian1()
{printf("\n\t************************************************\n");
printf("\n\t------------------------------------------------\n");
printf("\t what can I do for you next\n");
printf("\t %c 0:\tpaixu\n",15);
printf("\t %c 1:\tcha zhao\n\t %c 2:\tprint dates\n\t %c 3:\texit\n\t",15,15,1);
printf("\n\t------------------------------------------------\n");
printf("\n\t************************************************\n");
for(kg=0,subject=-1;kg==0;){fflush(stdin); /*等待用户选择操作。设置FOR循环以防出现意外*/
scanf("%d",&subject);if(subject>=0&&subject<=3)kg=1;
if(kg==0) printf("\t%c\terror input\n",1);}
if(subject==1)charxun();
else if(subject==0)paixu();
else if(subject==2)searchstudent();
else {printf("\n\tdo you want to save the date");
printf("\n\tinput y to save or n to exit\n");
for(kg=0;kg==0;){flag=getchar();
if(flag=='y'||flag=='n') { kg=1;if(flag=='y')save();
printf("\t\t%c thanks for using this program\npress any key to out",2);
getch();}
}

exit(0);}}
/*界面2*/zjiemian2()
{printf("\n\t************************************************\n");
printf("\n\t------------------------------------------------\n");
printf("\t which of the follow manner do you want to search\n");
printf("\t 0:\tby num\n");
printf("\t 1:\tby name\n\t 2:\tby score");
printf("\n\t------------------------------------------------\n");
printf("\n\t************************************************\n");}
/*选择0之后的操作*/ paixu(){
int sj;
struct student *p;p=stu;
printf("\n\t please choose one subject to search: 0 to %d\n",kemus-2);
for(kg=0,subject=-1;kg==0;)
{fflush(stdin);
scanf("%d",&subject);
if(subject>=0&&subject<=kemus-2)kg=1;
if(kg==0) printf("error input\n\t please choose one subject to search: 0 to %d\n",kemus-2);}
printf("\nwhich pxfs to px\n s: 0\tj: 1\n");
for( kg=0,sj=-1;kg==0;)
{ fflush(stdin);
scanf("%d",&sj);
if(sj==0||sj==1)kg=1; px(p,subject,sj);
if(kg==0) printf("error input\nwhich pxfs to px\n j: 0\ts: 1\n");}

print();
}
/*选择1之后的操作*/ charxun()
{ zjiemian2();
for(kg=0,subject=-1;kg==0;)
{ fflush(stdin);
scanf("%d",&subject);
if(subject==0||subject==1||subject==2)kg=1;
if(kg==0) printf("error input\n ");}
if(subject==0)xuehao();
else if(subject==1)xinming();
else erfenchaz(1);
}
/*存储到score*/save1(){FILE *fp;

if((fp=fopen("score.txt","wb"))==NULL)
{printf("xannot open the file student\n");
return;}
for(i=1;i<leath;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("cant not write\n");
fclose(fp);
}
/*查找学号*/xuehao(){char searchnum[zfcc]; printf("input a num\n");getchar();
scanf("%s",searchnum);
for(i=0,kg=0;i<=leath-1&&kg==0;i++) /*由于学号的唯一性,只要有一个人符合条件循环就能结束*/

if(strcmp(searchnum,stu[i].num)==0)
{kg=1;printf("\nstudnet %s's num is. his date is\n",stu[i].num);
printf("\nnum name \tsex mingci\tscores ave \n");
printonedate(i);}
if(kg==0)printf("the student is not in"); return (i-1);
}
/*查找姓名*/xinming(){char searchname[zfcc];printf("input a name\n");
scanf("%s",searchname);
for(i=0,kg=0;i<=leath-1&&kg==0;i++)
if(strcmp(searchname,stu[i].name)==0)/*由于姓名的唯一性,只要有一个人符合条件循环就能结束*/
{kg=1;printf("\nstudnet %s's name is. his date is\n",stu[i].name);
printf("\nnum name \tsex mingci\tscores ave \n");
printonedate(i);}
if(kg==0)printf("the student is not in");return (i-1);
}

/*查找成绩*/erfenchaz(int n){ float search,*h=&search;
struct student *p;p=stu;
printf("please choose one subject : 0 to %d\n",kemus-2);
for(kg=0,subject=-1;kg==0;)
{fflush(stdin);
scanf("%d",&subject);
if(subject>=0&&subject<=kemus-2)kg=1;
if(kg==0) printf("error input\n\t please choose one subject : 0 to %d\n",kemus-2);}
px(p,subject,1);
if(n==1){printf("please input a number to search\n");
scanf("%f",&search);
erf(p,h,subject);}
else return(subject);
}
/*从键盘上读取一次数据*/scanonce(int i){float sum=0;
printf("please input num name sex scores\n");
scanf("%s%s%s",stu[i].num,stu[i].name,stu[i].sex);
for(k=0;k<kemus-2;k++)
{ printf("please input score%d\n",k);
for(kg=0;kg==0;)
{fflush(stdin);
scanf("%f",&stu[i].score[k]);
if(stu[i].score[k]>=lowest&&stu[i].score[k]<=highest)
{kg=1;sum+=stu[i].score[k];printf("%f\n",sum);}
if(kg==0)printf("\nplease check the score and scanf again %c\n",1); } }
stu[i].score[kemus-2]=sum/(kemus-2);}
/*插入数据*/insert(){FILE *fp;
int t,n;

for(kg=1;kg==1;){
readen();
print();

printf("please insert date\n");
scanonce(0);
stu[0].score[kemus-1]=i;
for(t=1;(stu[t].score[kemus-2]>stu[0].score[kemus-2])&&t<leath-1;t++);
fp=fopen("score.txt","wb");
for(i=1;i<t;i++)
fwrite(&stu[i],sizeof(struct student),1,fp);printf("%d\n",98);
fwrite(&stu[0],sizeof(struct student),1,fp); printf("%d\n",98);
for(i=t;i<leath-1;i++){fwrite(&stu[i],sizeof(struct student),1,fp);}
fwrite(&stu[i],sizeof(struct student),1,fp);
fclose(fp);
printf("\n\t1 to insert another date\n\t2 to go to next menun\n\t3 to exit\n");
for(kg=0;kg==0;){
fflush(stdin);
scanf("%d",&subject); if(subject>=1&&subject<=3)kg=1;
if(kg==0) printf("\t%c\terror input\n",1);}if(subject==1)kg=1;
else if(subject==2) {readen();return;}
else exit(0);}
}

delet(){
for(kg=1;kg==1;){ readen();

print();

printf("\n\t************************************************\n");
printf("\n\t------------------------------------------------\n");
printf("\t which of the follow manner do you want to delete\n");
printf("\t 0:\tby num\n");
printf("\t %c 1:\tby name\n\t %c 2:\t return\n\t %c 3:\t exit",15,15,1);
printf("\n\t------------------------------------------------\n");
printf("\n\t************************************************\n");
for(kg=0,subject=-1;kg==0;){ fflush(stdin);
scanf("%d",&subject);if(subject>=0&&subject<=3)kg=1;
if(kg==0) printf("\t%c\terror input\n",1);}
if(subject==1) deletbyname(leath);
else if(subject==0) deletbynum(leath);
else if(subject==2) {readen();return;}
else exit(0);
printf("\n\t1 to contine 2 to return\n");
for(kg=0;kg==0;){
fflush(stdin);
scanf("%d",&subject);if(subject==1)kg=1;
else if(subject==2) {readen();return;}
if(kg==0) printf("\t%c\terror input\n",1);}}
}
deletbyname(int n)
{ FILE *fp;
int t;
t=xinming();
if(kg==1){ fp=fopen("score.txt","wb");
for(i=1;i<t;i++)
fwrite(&stu[0],sizeof(struct student),1,fp);
for(i=t+1;i<n-1;i++){fwrite(&stu[i],sizeof(struct student),1,fp);}
fwrite(&stu[i],sizeof(struct student),1,fp);
fclose(fp);printf("\n his is now be delete");}
else printf("\ncan delete\n");}
deletbynum(int n)
{ FILE *fp;
int t;
t=xuehao();
if(kg==1){ fp=fopen("score.txt","wb");
for(i=1;i<t;i++)
fwrite(&stu[0],sizeof(struct student),1,fp);
for(i=t+1;i<n-1;i++){fwrite(&stu[i],sizeof(struct student),1,fp);}
fwrite(&stu[i],sizeof(struct student),1,fp);
fclose(fp);printf("\n his is now be delete");}
else printf("\ncan delete\n");}
/*打印成绩小于指定数字的学生成绩*/searchstudent(){float search;
int kemu;
kemu=erfenchaz(0);
printf("please input a number to compare\n");
scanf("%f",&search);
printf("print the student whose score more then the number or less the number?\n");
printf("\n\t1:less \t2;more\n");
for(kg=0,subject=-1;kg==0;){ fflush(stdin);
scanf("%d",&subject);
if(subject>=1&&subject<=2)kg=1;
if(kg==0) printf("\t%c\terror input\n",1);}
if(subject==1)
{for(i=1,kg=0;kg==0&&i<leath;i++)
if(stu[i].score[kemu]<=search)
{printf("haha\n");kg=1;for(j=i;j<leath;j++){printf("%d,%d\n",j,leath);printonedate(j);}} }
else
{for(i=leath-1,kg=0;kg==0&&i>0;i--)if(stu[i].score[kemu]>=search){printf("haha\n");kg=1;for(j=i;j>0;j--){printf("%d,%d\n",j,leath);printonedate(j);}}}
if(kg==0)printf("no these students in");}

main()
{
printf("Hello, World !");
}

gztjzxj04 把代码贴完啊