博文
c语言课程设计_黑白棋对战(2006-06-19 12:49:00)
摘要:/*3.3.4 源程序*/#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=100;i<=420;i+=4......
c语言课程设计_扫雷游戏设计(2006-06-19 12:48:00)
摘要:c语言课程设计_扫雷游戏设计
/*5.3.4 源程序*/#include <graphics.h>#include <stdlib.h>#include <dos.h>#define LEFTPRESS 0xff01#define LEFTCLICK 0xff10#define LEFTDRAG 0xff19#define MOUSEMOVE 0xff08struct{ int num;/*格子当前处于什么状态,1有雷,0已经显示过数字或者空白格子*/ int roundnum;/*统计格子周围有多少雷*/ int flag;/*右键按下显示红旗的标志,0没有红旗标志,1有红旗标志*/}Mine[10][10];int gameAGAIN=0;/*是否重来的变量*/int gamePLAY=0;/*是否是第一次玩游戏的标志*/int mineNUM;/*统计处理过的格子数*/char randmineNUM[3];/*显示数字的字符串*/int Keystate;int MouseExist;int MouseButton;int MouseX;int MouseY;void Init(void);/*图形驱动*/void MouseOn(void);/*鼠标光标显示*/void MouseOff(void);/*鼠标光标隐藏*/void MouseSetXY(int,int);/*设置当前位置*/int LeftPress(void);/*左键按下*/int RightPress(void);/*鼠标右键按下*/void MouseGetXY(void);/*得到当前位置*/void Control(void);/*游戏开始,重新,关闭*/void GameBegain(void);/*游戏开始画面*/void DrawSmile(void);/*画笑脸*/void DrawRedflag(int,int);/*显示红旗*/void DrawEmpty(int,int,int,int);/*两种空格子的显示*/void GameOver(void);/*游戏结束*/void GameWin(void);/*显示胜利*/int&nbs......
赛车游戏(2006-06-16 17:57:00)
摘要:运动与静止同时实现在这里我用圆实现运动、方块实现静止 代码如下: #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> int main(void) { int gdriver = DETECT, gmode; void *ball; int x, y,maxx; unsigned int size; initgraph(&gdriver, &gmode, ""); maxx = getmaxx(); x = 0; y = 200; rectangle(x,y+11,x+20,y+31); circle(x+10,y,10); size = imagesize(x, y-10, x+20, y+10); ball = malloc(size); setfillstyle(SOLID_FILL, BLACK); while (!kbhit()) { cleardevice(); x += 10; if (x >= maxx) x = 0; rectangle(0,211,20,231); circle(x+10,y,10); delay(100); } free(ball); closegraph(); return 0; } 再来说一下赛车游戏 我上面给大家可以说是从第一步:制作简单的场景和玩家的赛车 到第二步:进一步完善场景, 大家可能已经有所领会 下面我们就把它做成一个简单的游戏 代码如下: #include <math.h>#include <conio.h> #include <stdio.h> #include <stdlib.h> #include <graphics.h> static int c=1; static int e=0; static int u=0; static int v=0; static int x=1; static int y=0; static int j=-21; static int i; static int b; void begin(void) { int xmax, ymax; ......
c语言(九格游戏100多行)(2006-06-16 17:55:00)
摘要:*很多人都觉得编游戏很高深...其实不然...以下是我初学C时写个一个九格游戏涉及的知识只有函数,各种流程控制和从老师那里问来的几个非常有用的函数. 当然,当时我连一点图形的知识都没有. 我只想说明一个问题:不要觉得你C语言学得不够多,只是,你没有充分利用你所学到的*/
#include #include /*使用其中的int random(int a): 产生一个在0到a-1之间的整数 和 randomize():复位随机发生器*/ #include /*使用其中的gotoxy(int x,int y): 把光标移动到屏幕的x(1~80),y(1~25/50)处*/ /*和clrscr():清屏*/ int num[]={1,2,3,4,5,6,7,8,0}; /*方块的数字*/
main(){ char key=0; /*键盘码*/ int pos; /*九格中,空格的位置*/ clrscr(); /*清屏*/ randomize(); /*初始化随机发生器*/ newGame(); for(;;){ key=getch(); /*获得键盘输入*/ if(key==0) continue; pos=GetTheNull(); /*得到空格*/ switch(key){ /*测试按键*/ case 72: /*按下*/ if(pos<=5) change(pos,pos+3); break; case 80: /*按上*/ if(pos>=3) change(pos,pos-3); break; case 77: /*按左*/ if(pos%3!=0) change(pos,pos-1); break; case 75: /*按右*/ if(pos%3!=2) change(pos,pos+1); break; case 110: /*按下‘n’新建游戏*/ newGame(); } update(); /*更新*/ if(isSuccess()){ /*看是否游戏成功*/ gotoxy(26,10); /*成功了,输出一个写有Well done!的外框*/ printf("\332\304\304\304\304\304\304\304\304\304\304\304\304\267"); gotoxy(26,11); printf("\26......
C语言中使用中常见的错误分析(2006-05-07 02:26:00)
摘要:
1 引言
C语言是比较通用的一种程序设计语言,具有数据类型多样、函数丰富、运算灵活、生成目标程序效率高、应用面广、可移植性好、且可以直接对硬件系统进行控制操作等优点而受到广泛的欢迎,目前很多高校都开设了C语言课程。但由于C语言书写比较灵活,语法限制不严,对初学者来说容易出错。笔者在教学中针对学生学习C语言时常见错误进行了分析,供初学者借鉴。
2 C语言使用中常见的错误
2.1 系统设置错误编译时出现“LinkerError:Unabletoopeninputfile‘COS.OBJ’”错误信息。说明连接目录在错误,改正的方法是在菜单“Option”中“Directories”需重新设置“Includedirectories”、“Librarydirecto-ries”和“Turbocdirectories”,如果TC安装在D:\TC目录下,那么以上三项分别应设置为“D:\TC\INCLUDE”、“D:\TC\LIB”、“D:\TC\TC”,然后使用菜单“Option”→“Saveoptions”保存当前的设置。这种错误常发生在TC不是安装在C盘的根目录下,因为系统默认是C盘的设置。
2.2 大小写错误C语言规定所有的关键字必须小写,而标识符中的字母则既可以大写,也可以小写,标识符不能与关键字相同,并区分大小写字母。例如,else是关键字,不能作为标识符使用,而ELSE可以作为标识符使用。
2.3 漏写分号、花括号在C语言中,规定一个语句必须以分号结束或花括号结束,如:intx=1;{inty=2;y+=x;printf("%d,%d\n",x,y);}应注意,复合语句中的最后一个语句仍然需要分号,最后一个“}”不能省略。比较容易忽视的是在“}”之后的分号,如一个类型的定义之后必须使用分号,包括结构体、联合体和枚举。如:structst{intx,*y;};
2.4 混淆“=”与“==”的区别在C语言中“=”是赋值运算符,不能作等号使用,这与其它高级语言是有区别的,而“==”是关系运算符,比较两个数据是否相等,且“==”比“=”优先级别高,如:main(){intx=1,y=2;pri......
学生成绩管理系统(2006-03-26 12:48:00)
摘要:/*头文件*/#include <stdio.h>#include<dos.h>#include<stdlib.h> /*其它说明*/#include<string.h> /*字符串函数*/#include<mem.h> /*内存操作函数*/#include<ctype.h> /*字符操作函数*/#include<alloc.h> /*动态地址分配函数*/#define LEN sizeof(STUDENT)typedef struct stu /*定义结构体数组用于缓存数据*/{char num[6]; char name[5]; int score[3]; int sum; float average; int order; struct stu *next;}STUDENT;
/*函数原型*/STUDENT *init(); /*初始化函数*/int menu_select(); /*菜单函数*/STUDENT *create(); /*创建链表*/void print(STUDENT *head); /* 显示全部记录*/void search(STUDENT *head); /*查找记录*/STUDENT *delete(STUDENT *head); /*删除记录*/STUDENT *sort(STUDENT *head); /*排序*/STUDENT *insert(STUDENT *head,STUDENT *new); /*插入记录*/void save(STUDENT *head); /*保存文件*/STUDENT *l......
一个女孩写的恋爱程序(2005-09-21 23:55:00)
摘要:result love(boy, girl) { if( boy.有房() and boy.有车() ) { boy.set(nothing); return girl.嫁给(boy); } if( girl.愿意等() ) { while(!(boy.赚钱 > 100,000 and girl.感情 > 8 ) ) { for( day=1; day <=365; day++) { if( day == 情人节 ) if( boy.givegirl(玫瑰) ) girl.感情++; else girl.感情--; if( day == girl.生日) if( boy.givegirl(玫瑰) ) girl.感情++; else girl.感情--; boy.拼命赚钱(); } } if( boy.有房() and boy.有车() ) { boy.set(nothing); return girl.嫁给(boy); } 年龄++; girl.感情--; } return girl.goto( another_boy); } ......
银行家算法实现(2005-09-18 11:27:00)
摘要: #include<iostream.h>#include<fstream.h>#include<stdlib.h>#include "windows.h"#define MAX_PROCESS 32 //最大进程数#define MAX_COURCE 64 //最大资源类别
int MAX_FACT_PROCESS; //实际总进程数int MAX_FACT_COURCE; //实际资源类别数int Available[MAX_COURCE]; //可利用资源向量int Max[MAX_PROCESS][MAX_COURCE]; //最大需求矩阵int Allocation[MAX_PROCESS][MAX_COURCE]; //分配矩阵int Need[MAX_PROCESS][MAX_COURCE]; //需求矩阵
int Request_PROCESS; ......
银行管理(2005-09-18 11:27:00)
摘要: #include <stdio.h>main(){int i,y;float b,l,total;printf("\nPlease input the cash(yuan) and the year(year=1,2,3,5,8).\n");loop: scanf("%f%d",&b,&y);switch(y){case 1:l=0.0063; break;case 2:l=0.0066; break;case 3:l=0.0069; break;case 5:l=0.0075; break;case 8:l=0.0084; break;default:printf("The year is error! Please input the cash and the year.\n ");goto loop;}total=b;for(i=1;i<=y*12;i++)total=total*(1+l);printf("The total is %f yuan .",total);getchar();getchar();}......
冒泡法(2005-09-18 11:27:00)
摘要: #include <iostream.h>
void BubbleSort(int* pData,int Count){ int iTemp; for(int i=1;i<Count;i++) { for(int j=Count-1;j>=i;j--) { if(pData[j]<pData[j-1]) { iTemp = pData[j-1]; pData[j-1] = pData[j]; pData[j] = iTemp; } } }}
void main(){ in......
