(完整word版)C语言实训项目分析及源码详解
C语言实训项目分析及源码

防灾科技学院实习报告书防灾科技学院灾害信息工程系2015年制项目一C语言实习一、实习目的本课程是网络工程专业的一门专业必修课程,是学生学习完C语言程序设计专业基础课程后,进一步学习其他专业课程前必须完成的一项实践教学环节。
本次实习通过1个综合性强、实用性强、趣味性强的应用实例,使学生进一步巩固C语言基本知识,掌握应用程序设计语言描述问题、分析问题和解决问题的方法和思想,为后继的面向对象程序设计、数据结构、Web应用技术、网络工程专业实习、网络工程生产实习、网络工程毕业实习课程等课程打下基础。
通过本课程的学习,使学生进一步明确学习目标、增强学习动力、培养学习兴趣。
二、实习任务概述任务一:员工工资管理系统的设计与实现本系统基于C语言,实现了一个小型的信息管理系统,主要包括以下功能:1.信息的录入:a)首次进入系统,可以添加职工的工号、姓名、基本工资、津贴、员工奖金等数据录入操作。
b)系统再次登录,可以从文件导入信息,也可以对文件内容进行修改,保存退出。
2.删除操作:对离职的员工信息要从系统里删除。
3.显示操作:将结构体中职工信息输出到屏幕上。
4.查询与修改操作:分别按职工工号和职工姓名查询,修改职工信息并保存。
5.统计与排序操作:分别统计所有员工的总工资,实现对总工资的排序。
三、实习所用软件简介VC++6.0是Microsoft公司推出的一个基于Windows系统平台、可视化的集成开发环境,它的源程序按C++语言的要求编写,并加入了微软提供的功能强大的MFC(Microsoft Foundation Class)类库。
使用VC++提供的高度可视化的应用程序开发工具和MFC类库,可使应用程序开发变得简单。
使用VC++提供的高度可视化的应用程序开发工具和MFC类库,可使应用程序开发变得简单。
Visual C++6.0以拥有“语法高亮”,自动编译功能以及高级除错功能而著称。
比如,它允许用户进行远程调试,单步执行等。
(完整word版)c语言中进制转换数据结构实训报告

《进制之间转换》数据结构程序设计报告专业:计算机网络技术班级:姓名:学号:二○一二年四月三十日目录1.需求分析 (1)2.概要设计 (2)3.采用的算法(流程图) (2)4.详细设计 (2)5. 调试分析 (3)6.用户使用说明 (3)7.测试结果 (3)8.附录 (13)1、需求分析(1)输入的形式和输入值的范围:◆不大于4位的十六进制数◆不大于16位的二进制数◆十进制数(2)输出的形式:同上(3)程序的功能:十六进制转化为十进制十六进制转化为二进制十六进制转化为八进制十进制转化为二进制十进制转化为八进制二进制转化为十进制二进制转化为十六进制(4)测试数据十六进制转化为十进制、十六进制转化为二进制:十六进制转化为八进制、十进制转化为二进制、十进制转化为八进制、二进制转化为十进制:二进制转化为十六进制、输入输入出错:2、概要设计:一,进制之间的转换用到头文件包match.h、stdio.h、stdlib.h。
问题要求根据输入的不同字符,执行不同的功能。
转换过程中需要各个函数之间进行调用二,输入合适的数据得出转换的数据,其重要考虑到输入数据的范围。
3.采用的算法(流程图)4.详细设计:5.调试分析:(1)首先是乱码问题。
由于使用中文所以出现了乱码,把中文改成英文就好了。
(2)如果选择0直接退出根本看不到goodbye所以加getch()可以停留在执行屏幕(3)在这次设计中,首先,我发现了很多问题,由于自己基本的语句掌握的不是十分熟练,所以在一开始不知道怎样把松散的函数调用紧凑地联系起来,经过仔细的看书以及向同学请教,终于将基本框架搭好,在调整细节时就相对轻松一些了,所以经过这次课程设计,我总结出了自己在学习数据结构中的不足,并且为其他类似语言打下了良好的基础,十分感谢老师以及同学的帮助,在此过程中还锻炼了我们与别人沟通的能力,使我们受益匪浅。
6、用户使用说明:(1)运行程序选择自己要转换的形式(2)输入对应数据(3)输入0退出7、测试结果:输入1———>输入1A1——>输出417输入2——>输入1A1——>输出110100001B输入3——>输入1A1——>输出641Q输入4——>输入12——>输出1100B输入5——>输入 12——>输出 14K输入6——>输入11011010——>输出218输入7——>输入101——>输出5H输入0——>退出8、附录(源代码):#include <stdio.h>#include <stdlib.h>#include<math.h>int Hten(){ int i=0,j=0,m=0;char x[10];char f=0;printf("Please enter no more than 4digit hexadecimal number sixteen\n");while(f!='\n'){scanf("%c",&x[i]);f=x[i];m++;i++;}for(i=0;i<m-1;i++){ if(x[i]>='A'&&x[i]<='F')x[i]=x[i]-55;elseif(x[i]>='0'&&x[i]<='9')x[i]=x[i]-48;else{ printf("Please input the correct form\n");return 0;}}for(i=0;i<m-1;i++)j=j+x[i]*pow(16,m-1-i-1);return j;}typedef int datatype;#define maxsize 64typedef struct{datatype data[maxsize];int top;}seqstack;setnull(seqstack *s){s->top=-1;}int Empty(seqstack *s){if(s->top>=0)return 0;/*false*/elsereturn 1;/*ture*/}int Full(seqstack *s){if(s->top==maxsize-1)return 1;elsereturn 0;}seqstack *push(seqstack *s,int x,int N) {int n;if(Full(s)){printf("overfull\n");return NULL;}else{while(x!=0){ n=x%N;x=x/N;s->top++;s->data[s->top]=n;}return s;}}int pop(seqstack *s){int x;if(Empty(s)){printf("empty\n");return 0;} else{x=s->data[s->top];s->top--;return x;}}Htwo(){seqstack *s;int k;s=(seqstack *)malloc(sizeof(seqstack));setnull(s);k=Hten();if(k!=0){push(s,k,2);}else return ;printf("Converted to a binary outcome for\n"); while(!Empty(s)){printf("%d",pop(s));}printf("B\n");}Height(){int k;seqstack *s;s=(seqstack *)malloc(sizeof(seqstack));setnull(s);k=Hten();if(k!=0)push(s,k,8);else return;printf("Converted to octal results\n");while(!Empty(s)){printf("%d",pop(s));}printf("Q\n");}Tentwo(){ seqstack *s;int k;s=(seqstack *)malloc(sizeof(seqstack));setnull(s);printf("Please enter a decimal number\n");scanf("%d",&k);push(s,k,2);printf("Converted to a binary outcome for\n"); while(!Empty(s)){printf("%d",pop(s));}printf("B\n");}Teneight(){ seqstack *s;int k;s=(seqstack *)malloc(sizeof(seqstack));setnull(s);printf("Please enter a decimal number\n");scanf("%d",&k);push(s,k,8);printf("Converted to octal results\n");while(!Empty(s)){printf("%d",pop(s));}printf("Q\n");}int Twoten(){int i=0,j=0,m=0;char x[10];char f=0;printf("Please enter no more than 16 bits of the binary number\n"); while(f!='\n'){scanf("%c",&x[i]);f=x[i];m++;i++;}for(i=0;i<m-1;i++)if(x[i]=='0'||x[i]=='1')x[i]=x[i]-48;else{ printf("Please input the correct form!\n");return 0;}}for(i=0;i<m-1;i++)j=j+x[i]*pow(2,m-1-i-1);return j;}Twoh(){ int k,y;seqstack *s;s=(seqstack *)malloc(sizeof(seqstack));setnull(s);k=Twoten();if(k!=0){push(s,k,16);}else return ;printf("Into sixteen decimal results\n");while(!Empty(s)){ y=pop(s);if(y<10)printf("%d",y);elseprintf("%c",y+55);printf("H\n");}main(){int a,k;INDEX:printf("**************************************\n");printf("0:\t exit \n");printf("1:\tSixteen hexadecimal conversion to decimal\n");printf("2:\tSixteen hexadecimal into binary\n");printf("3:\tSixteen hexadecimal converted to octal\n");printf("4:\tDecimal to binary\n");printf("5:\tDecimal to octal\n");printf("6:\tBinary to decimal conversion\n");printf("7:\tBinary conversion of sixteen hexadecimal\n");printf(" \t\tcopyright 2008-2018 \n");printf("**************************************\n"); SCANI: printf("What are you going to do?Please select a menu\n");scanf("%d",&a);getchar();switch(a){case 0: goto EXT;case 1: goto SET1;case 2: goto SET2;case 3: goto SET3;case 4: goto SET4;case 5: goto SET5;case 6: goto SET6;case 7:goto SET7;default: goto INDEX;}SET1:k=Hten();if(k!=0){printf("The result is converted to decimal\n");printf("%d\n",k);}goto SCANI;SET2: Htwo(); goto SCANI;SET3: Height(); goto SCANI;SET4: Tentwo();goto SCANI;SET5: Teneight();goto SCANI;SET6:k=Twoten();if(k!=0){printf("The result is converted to decimal\n");printf("%d\n",k);}goto SCANI;SET7:Twoh();goto SCANI;EXT: printf(" goodbye!\n");getch();}。
编译原理 C语言 词法分析 实验 源码

编译原理实验报告 词法分析
南京信息工程大学 计算机与软件学院 软件工程 2009 级 1 班 54andy1@ 一.实验目的
#region 负数 算数减 算数减并赋值 case ANSIC.Character.MinusSign:
break; #endregion
#region 算数乘 算数乘并赋值 case ANSIC.Character.Asterisk:
if (index + 1 < SourceLines[row].Length && SourceLines[row][index + 1] == '+') { Result.Add(new Token(TokenTypes.MultiplyAsign, row, index, 2, "*=")); index++;
word.Append(SourceLines[row][index]); index++; while (index<SourceLines[row].Length) { if (SourceLines[row][index] >= '0' && SourceLines[row][index] <= '9')
编译原理实验报告 词法分析 1 / 19
一开始做词法分析的时候,单纯做词法分析,没有考虑到语法分析,所以没有架构好,在要做语法分析的 时候找不到合适的接口,这是第一个教训。
(完整word版)进程管理实验报告源代码

实验一进程管理1.目的和要求通过实验理解进程的概念,进程的组成(PCB结构),进程的并发执行和操作系统进行进程管理的相关原语(主要是进程的创建、执行、撤消)。
2.实验内容用C语言编程模拟进程管理,至少要有:创建新的进程;查看运行进程;换出某个进程;杀死运行进程以及进程之间通信等功能。
3.实验环境Windows操作系统、VC++6.0C语言4.实验提示PCB结构通常包括以下信息:进程名,进程优先数,轮转时间片,进程所占用的CPU时间,进程的状态,当前队列指针等。
可根据实验的不同,PCB结构的内容可以作适当的增删。
主体程序#include "conio.h"#include "stdio.h"#include "stdlib.h"struct jincheng_type{int pid;int youxian;int daxiao;int msg;int live;};struct jincheng_type neicun[20],waicun[20];int shumu=0,pid_l;main(){int n,m,i;char a;n=1;while(n==1){system("cls");printf("\n********************************************");printf("\n* 进程演示系统*");printf("\n********************************************");printf("\n 1.创建新的进程 2.查看运行进程");printf("\n 3.换出某个进程 4.杀死运行进程");printf("\n 5.进程之间通信 6.退出");printf("\n********************************************");printf("\n请选择(1~6) ");a=getch();switch(a){case'1':create( );break;case'2':viewrun( );break;case'3':huanchu();break;case'4':kill( );break;case'5':tongxun( );break;case'6': exit(0);default: n=0;}}}create( ) /* 创建一个进程的示例(不完整的程序)*/ {if(shumu>=20){printf("\n内存已满,请先结束或换出进程\n");}else{printf("\n请输入新进程的pid\n");scanf("%d",&neicun[shumu+1].pid);printf("\n请输入新进程的优先级\n");scanf("%d",&neicun[shumu+1].youxian);printf("\n请输入新进程的大小\n");scanf("%d",&neicun[shumu+1].daxiao);printf("\n请输入新进程的消息\n");scanf("%d",&neicun[shumu+1].msg);neicun[shumu+1].live=1;shumu++;}return neicun[shumu-1].live;}viewrun( )/*查看运行进程*/{int vpid;printf("\n请输入进程的pid\n");scanf("%d",&vpid);if(vpid>0&&vpid<=20&&neicun[vpid].live==1){printf("\n进程的pid是: %d\n",neicun[vpid].pid);printf("进程的优先级是: %d\n",neicun[vpid].youxian);printf("进程的大小是:%d\n",neicun[vpid].daxiao);printf("进程的消息是:%d\n",neicun[vpid].msg);}else{printf("\n所查看运行进程不存在\n");}printf("请按回车退出查看\n");vpid=getch();}huanchu()/*换出某个进程*/{int pid1,pid2;char c;printf("\n请输入第一个替换进程的pid\n");scanf("%d",&pid1);printf("\n请输入第二个替换进程的pid\n");scanf("%d",&pid2);if(pid1>0&&pid1<=20&&neicun[pid1].live==1){if(neicun[pid1].youxian>neicun[pid2].youxian){waicun[20].pid=neicun[pid1].pid;waicun[20].youxian=neicun[pid1].youxian;waicun[20].daxiao=neicun[pid1].daxiao;waicun[20].msg=neicun[pid1].msg;neicun[pid1].pid=neicun[pid2].pid;neicun[pid1].youxian=neicun[pid2].youxian;neicun[pid1].daxiao=neicun[pid2].daxiao;neicun[pid1].msg=neicun[pid2].msg;neicun[pid2].pid=waicun[20].pid;neicun[pid2].youxian=waicun[20].youxian;neicun[pid2].daxiao=waicun[20].daxiao;neicun[pid2].msg=waicun[20].msg;printf("\n替换完成\n");printf("\n被替换进程的pid是: %d\n",waicun[20].pid); printf("被替换进程的优先级是: %d\n",waicun[20].youxian); printf("被替换进程的大小是:%d\n",waicun[20].daxiao); printf("被替换进程的消息是:%d\n",waicun[20].msg);}else{printf("\n进程优先级不够大");}}else{printf("所查看运行进程不存在");}printf("请按回车退出换出进程\n");c=getche();return;}kill()/*杀死运行进程*/{int kpid;printf("\n请输入进程的pid\n");scanf("%d",&kpid);if(kpid>0&&kpid<20&&neicun[kpid].live==1){neicun[kpid].live=0;}return;}tongxun( )/*进程之间通信*/{int tpid1,tpid2;int buffer;char d;printf("\n请输入通信源进程pid\n");scanf("%d",&tpid1);printf("\n请输入通信目的进程pid\n");scanf("%d",&tpid2);if(tpid1>0&&tpid1<20&&neicun[tpid1].live==1){buffer=neicun[tpid1].msg;neicun[tpid1].msg=neicun[tpid2].msg;neicun[tpid2].msg=buffer;printf("\n源进程的消息是: %d\n",neicun[tpid1].msg);printf("\n目的进程的消息是: %d\n",neicun[tpid2].msg);}else{printf("\n所查看运行进程不存在\n");}printf("\n请按回车退出进程通信\n");d=getch();return;}5.实验运行结果******************************************** * 进程演示系统* ********************************************1.创建新的进程2.查看运行进程3.换出某个进程4.杀死运行进程5.进程之间通信6.退出系统******************************************** 请选择(1~6)然后根据你选择的不同,出现不同的结果。
c语言课设实验报告-记事本程序(含源码)

C语言课设实验报告[记事本程序]班级:学号:姓名:指导老师:C语言课设实验报告#define key_down 80#define key_up 72#define key_esc 1#define key_alt_f 33#define key_alt_x 45#define key_enter 28#define key_alt_e 18int get_key();void box(int startx,int stary,int high,int width);{int i,key,x,y,l;char *w=NULL,*d=NULL,*s=NULL;FILE *fp;char *menu[]={ "File ", "Edit ","Format","View","Help"};char *red[]={ "F", "E","F","V","H"};char *f[]={ "New ", "Open" , "Save", "Another","Quit alt_x"};char *e[]={"Search","Search next","Replace","Date"};char buf[16*10*2],buf1[16*2];textbackground(3);clrscr();window(1,1,80,1);textbackground(WHITE);textcolor(BLUE);clrscr();window(1,1,80,2);for(i=0, l=0; i <5;i++){x=wherex();y=wherey();textcolor(BLACK);cprintf( " %s ",menu[i]);l=strlen(menu[i]);gotoxy(x,y); x.y等的头文件*//*功能键的扫描码的定义*//* i为循环次数的序数,key为从键盘输入的功能键,x,y 为光标的坐标,l为菜单栏中菜单的字符长度*//*w是存放输入的内容(记录的事情)的指针,*s是存放输入的文件名的指针,*d是存放输入要定时的文件的文件名的指针*/ /*菜单栏中各个菜单的定义*//*菜单栏中菜单开头要标颜色的字母的定义*//* file 子菜单中项目的定义*//*edit子菜单的定义*/ /*缓冲区的定义*//*整个大窗口的背景颜色设置*//*创建菜单栏窗口*/ /*设置菜单栏窗口背景颜色为白色,字体颜色为蓝色*//*利用循环输出menu菜单栏,有多少个菜单循环多少次。
C语言课程设计报告+源码

C 语言课程设计报告一.程序主要功能用单向链表结构实现简单的学生成绩管理功能,具有链表建立、链表输出、结点有序插入、结点删除、数据查询等功能。
用户在主菜单界面输入选项,即按照功能列表0-9输入任意数字,回车后执行该功能。
(1)Create List(建立有序单向链表)从键盘上一次输入一个学生的姓名及成绩,以姓名为序建立有序链表。
插入一条记录后,显示提示信息:确认是否输入下一条记录,如确认,继续输入,否则退出输入功能。
(2)Display All Record(显示所有结点记录)按顺序显示链表中所有记录,每屏显示10条记录。
每显示10条,按<Enter>键继续显示下一屏。
(3)Insert a Record (插入一条结点记录)在以姓名为序排列的链表中插入一条记录,插入后,链表仍有序。
输出插入成功的信息。
(4)Delete a Record (按姓名查找,删除一条结点记录)输入待删除记录的姓名,显示提示信息,用户再次确认是否要删除。
确认后,将该姓名的记录删除。
(5)Query (查找并显示一个结点记录)输入姓名,查找该记录,并显示该同学的成绩。
(6)Add Records from a Text File (从正文文件中添加数据到链表中) 从纯文本文件添加数据到链表。
(7)Write to a Text File将链表中数据写入文件(纯文本文档),键入文件名后建立该文件。
(0)Quit (退出学生成绩管理系统) 释放链表存储空间。
#include<stdlib.h> #include<ctype.h> #include<string.h>#include<alloc.h>struct stud /*定义结构体*/ {char Name[80]; int Score;struct stud *next;};typedefstruct stud Student; /*声明新的类型名Student*/ intmenu_select(); /*声明全体函数*/ Student *Create();void Display(Student *head);Student *Insert(Student *head,Student *s); Student *Insert_a_record(Student *head); Student *Delete(Student *head,char *name);Student *Delete_a_record(Student *head);Student *Query(Student *head,char *name); voidQuery_a_record(Student *head);Student *AddfromText(Student *head,char *filename); voidWritetoText(Student *head,char *filename); void Quit(Student *head);main()/*主函数*/ {Student *head=NULL;/*定义头指针为全局变量*/ for(;;) {switch(menu_select())/*调用menu_select()函数*/ {case 1:/*在主函数中进行各个功能函数的调用*/ head=Create(head);printf("Execution of Create List\n"); system("pause"); break; case 2: Display(head);printf("Execution of Display All Record\n"); system("pause"); break; case 3:head=Insert_a_record(head);printf("Execution of Insert a Record\n"); system("pause"); break; case 4:head=Delete_a_record(head);printf("Execution of Delete a Record\n"); system("pause"); break; case 5:Query_a_record(head); printf("Execution of Qurey\n"); system("pause");break; case 6:head=Add_Records_from_a_Text_File(head); printf("Execution of Add Records from a Text File\n"); system("pause"); break; case 7:Write_to_text(head);printf("Execution of Write to a text file\n"); system("pause"); break; case 0:printf("Goodbye!\n"); system("pause"); exit(0); }}}intmenu_select() /*菜单选择函数*/ { char c; do{system("cls");printf("1.Creat List\n"); printf("2.Display All records\n"); printf("3.Insert a Record\n"); printf("4.Delete a Record\n"); printf("5.Query\n");printf("6.Add Records From a Text File\n"); printf("7.Write to a Text File\n); printf("0.Quit\n");printf("Give your choice(0-7):"); c=getchar(); getchar(); }while(c<'0'||c>'7');return(c-'0'); /*返回选择值*/ }Student *Create(Student *head) /*创建链表*/ {Student *p; char x='y'; /*p 为新开辟的空间的首地址*/ printf("create an increasing list.............."); printf("please input name and score:");while(x=='y') {p=(Student *)malloc(sizeof(Student)); /*给p 分配动态存储空间*/scanf("%s%d",p->Name,&p->Score);head=insert(head,p); /*调用Insert 函数创建有序链表*/ printf("continue?? (y or n?)");getchar();x=getchar();if(x=='n') {printf("game over...\n");break;} elseprintf("please input the name and score:"); }return head; /*返回头指针变量*/ }void Display(Student *head) /*显示链表数据*/{Student *p=head; /*通过变量P 的改变对应链表中所有的数据*/ int i=1;printf("Student Name Score\n"); for(;p!=NULL;i++){printf("%-15s%d\n",p->Name,p->Score); p=p->next; if(i%10==0){system("pause"); /*输出10个暂停一次*/ system("cls");printf("FUNCTION LIST\n"); printf("1.Creat List\n"); printf("2.Display All Record\n"); printf("3.Insert a Record\n");printf("4.Delete a Record\n"); printf("5.Query\n");printf("6.Add Records From a Text File\n"); printf("7.Write to a Text File\n"); printf("0.Quit\n");printf("Student Name Score\n"); } } }Student *Insert(Student *head,Student *p) /*有序插入指针p 所对应的结点到链表*/ {Student *p1,*p2;if(head==NULL) /*如果链表为空*/ {head=p;p->next=NULL;return head; /*返回头指针变量*/}p2=p1=head;while(strcmp(s->Name,p1->Name)>0 && (p1->next!=NULL)) /*查找功能,head 指针非空的情况,当p 指向的Name 的首字母大于head 指针指向的Name*/ {p2=p1;p1=p1->next; /*p1后移,再进行循环,直到s 指向的Name 的首字母小于等于p1指针指向的Name 或p1指向了空指针*/ }if(strcmp(p->Name,p1->Name)<=0 ) {p->next=p1; /*把p 大的p1放在链表后面*/if(head==p1) head=p; /*判断p1是否为head*/ else p2->next=s; }else {p1->next=p;p->next=NULL;} /*p 指向的Name 的首字母大于head 指针指向的Name*/ return head; /*返回头指针变量*/}Student *Insert_a_record(Student *head) /*插入结点记录*/ {Student *p /*p 为新开辟的空间的首地址*/;p=(Student *)malloc(sizeof(Student)); /*给p 分配动态存储空间*/ scanf("%s%d",s->Name,&s->Score);head=Insert(head,p); /*调用Insert 函数插入*/ printf("Insert successfully\n");return head; /*返回头指针变量*/}Student *Delete(Student *head,char *name) /*删除链表中的一条数据,数组name 存放删除数据姓名*/ {Student *p1,*p2; p1=head;while(strcmp(p1->Name,name)!=0&&p1->next!=NULL) {p2=p1;p1=p1->next; }if(strcmp(p1->Name,name)==0) /*找到了姓名相同的记录*/{if(p1==head)head=p1->next; /*当p1==head ,p1->next 为NULL ,赋值给head ,起到了删除的作用*/ else p2->next=p1->next; /*p1->next 为NULL ,赋值给 p2->next 即p1,起到了删除的作用*/}return head; /*返回头指针变量*/ }Student *Delete_a_record(Student *head) /*删除结点记录*/ {charch, name[20]; Student *p; scanf("%s",name); getchar();p=Query(head,name);if(p==NULL) printf("Cannot Find %s\n",name); else {printf("Delete %s, Y/N?\n",name); ch=getchar();if(ch=='y'||ch=='Y') while(p!=NULL) { head=Delete(head,name);/*调用Delete 函数*/p=Query(head,name);/*调用Query 函数进行查找*/}printf("Delete %s is successfully.\n",name); }return head; /*返回头指针变量*/}Student *Query(Student *head,char *name) /*查找一条记录,name 存放待查数据姓名*/ {Student *p; /*通过p 访问所有结点*/p=head;while(strcmp(name,p->Name)!=0&&p->next!=NULL) /*查找功能,寻找需要与查找相同的记录*/p=p->next;if(strcmp(name,p->Name)==0)return p; /*p 此时为文件的头指针*/ elsereturn NULL; /*返回空指针*/ }void Query_a_record(Student *head) /*查询一条记录*/ {char name[20]; /*定义数组存放要查找的名字*/Student *p; /*如果有要查找的结点,P 为该结点的地址*/ scanf("%s",name);p=Query(head,name); /*调用Query 函数进行查找*/ if(p!=NULL) {printf("Find %s successfully\n%s %d\n",p->Name,p->Name,p->Score); } elseprintf("can't find the records of %s\n",name); }Student *AddfromText(Student *head,char *filename) /*从文件添加数据*/ {FILE *fp; /*定义指向FILE 的文件指针*/ Student *p;intn,i;if((fp=fopen(filename,"r"))==NULL) /*用只读方式打开文件*/ {printf("Cannot find file:%s\n",filename); return head; }fscanf(fp,"%d",&n); for(i=0;i<n;i++){p=(Student *)malloc(sizeof(Student)); /*给p 分配动态存储空间*/ fgetc(fp);fscanf(fp,"%s%d",p->Name,&p->Score);head=Insert(head,p); /*调用Insert 函数插入*/ }printf("Add from %s successfully\n",filename); fclose(fp); /*关闭fp1指向的文件*/ return head; /*返回头指针*/ }void WritetoText(Student *head,char *filename) /*将数据写入文件*/ {FILE *fp;Student *p; /*通过指针变量p 访问所有链表结点*/ intnum=0;if(head==NULL)printf("No Record!\n");return head; }fp=fopen(filename,"w"); /*打开输入了文件名的文件*/ p=head;for(;p!=NULL;num++) p=p->next; fprintf(fp,"%d\n",num); p=head;while(p!=NULL){fprintf(fp,"%s %d\n",p->Name,p->Score); /*循环输出,在文件中循环输出数据*/ p=p->next;}printf("Write to %s successfully\n",filename); fclose(fp); /*关闭文件*/ }void Quit(Student *head)/*释放内存空间*/{Student *p; /*通过指针变量p 访问所有链表结点*/ while(head!=NULL) {p=head;head=head->next;free(p); /*退出函数*/ } }四.函数调用关图五.测试流程及典型测试数据1. 执行功能1,输入上表中数据,输入‘n ’返回主菜单。
(完整word版)单片机C语言程序设计实训100例
《单片机C语言程序设计实训100例—基于8051+Proteus仿真》案例第 01 篇基础程序设计01 闪烁的LED/*名称:闪烁的LED说明:LED按设定的时间间隔闪烁*/#include<reg51.h〉#define uchar unsigned char#define uint unsigned intsbit LED=P1^0;//延时void DelayMS(uint x){uchar i;while(x-—){for(i=0;i〈120;i++);}}//主程序void main(){while(1){LED=~LED;DelayMS(150);}}02 从左到右的流水灯/* 名称:从左到右的流水灯说明:接在P0口的8个LED从左到右循环依次点亮,产生走马灯效果*/#include〈reg51。
h〉#include<intrins。
h>#define uchar unsigned char #define uint unsigned int//延时void DelayMS(uint x){uchar i;while(x—-){for(i=0;i〈120;i++);}}//主程序void main(){P0=0xfe;while(1){P0=_crol_(P0,1); //P0的值向左循环移动DelayMS(150);}}03 8只LED左右来回点亮/*名称:8只LED左右来回点亮说明:程序利用循环移位函数_crol_和_cror_形成来回滚动的效果*/#include<reg51.h>#include〈intrins.h>#define uchar unsigned char #define uint unsigned int//延时void DelayMS(uint x){uchar i;while(x——){for(i=0;i〈120;i++);}}//主程序void main(){uchar i;P2=0x01;while(1){for(i=0;i〈7;i++){P2=_crol_(P2,1); //P2的值向左循环移动DelayMS(150);}for(i=0;i<7;i++){P2=_cror_(P2,1); //P2的值向右循环移动DelayMS(150);}}}04 花样流水灯/* 名称:花样流水灯说明:16只LED分两组按预设的多种花样变换显示*/#include<reg51。
(完整版)c实验报告
(完整版)c实验报告实验名称: C语言实验报告实验内容:本次实验主要针对C语言编程进行实验。
通过实验的设计和完成,检验和加深对C语言的理解和应用能力。
实验步骤:1. 实验准备在开始实验之前,需要准备好以下必要的工具和材料:- 计算机- C语言编译器(比如GCC、Clang等)- 文本编辑器(比如Notepad++、Sublime Text等)2. 实验环境搭建在计算机上安装C语言编译器,并配置好相应的环境变量。
这样可以在终端或命令提示符中执行相关的C程序。
3. 编写实验代码根据实验要求,使用文本编辑器编写C语言代码。
根据实验的要求和功能需求,合理设计和组织代码结构,包括头文件的引用、变量的定义、函数的声明和定义等。
4. 编译和运行代码在命令行或终端中使用编译器对编写好的C语言代码进行编译,并生成可执行文件。
编译命令的具体格式根据不同的编译器而有所差异,但一般形式如下:```gcc -o output_file input_file.c```其中,"output_file"表示生成的可执行文件名,"input_file.c"表示待编译的C源代码文件名。
编译成功后,通过命令行或终端执行生成的可执行文件,检查程序的运行结果是否符合预期。
5. 实验结果分析根据实际运行结果,对实验数据进行分析和归纳。
可以通过输出结果、打印特定信息或观察程序的行为来判断程序是否正确地实现了预期的功能。
6. 实验总结在实验报告中对本次实验的过程、方法、结果进行总结,并提出实验中遇到的问题和解决方法。
同时,对所学习的C语言相关知识点进行总结和归纳,以加深对相关知识的理解和记忆。
实验结果:通过本次实验的设计和实现,我成功完成了对C语言编程的实验,达到了预期的目标。
通过编写实际的代码,我巩固了对C语言语法和基本概念的理解。
在实验过程中,我遇到了一些问题,通过查阅资料和与同学的讨论,我成功解决了这些问题。
(完整word版)纯C语言写的一个小型游戏源代码
/* A simple game*//*CopyRight: Guanlin*/ #include<stdio。
h〉#include〈stdlib。
h〉#include<string.h〉#include〈time。
h>#include〈conio。
h>#include<process.h〉struct object_fix{char name[20];char id[5];char desc[500];char action[30];char im[5];};struct object_move{char name[20];char id[5];char desc[500];int loc;int pwr;int strg;char im[5];};struct rover{char name[20];char id[5];char desc[500];int pwr;int strg;int location[2];char im[5];};struct map /* this is the map structure*/{char data[20];char add_data[20];int amount;int x; /* this were the successor keeps it's x & y values*/int y;};struct location /*this structure is for the successor lister*/{float height;char obj;};void stats_update(int selected, struct rover *p_rover){switch (selected){case 1:if(p_rover->pwr 〈 7)printf("\n\nYou do not have enough power to perform this action!\n\n”);else{(p_rover—〉pwr)—= 7;printf("You have destroyed the object!\n\n");}break;case 2:if(p_rover->pwr 〈 3)printf(”\n\nYou do not have enough power to perform this action!\n\n"); else if(p_rover—〉strg > 90)printf("\n\nYou do not have enough storage space for this object!\n\n");{(p_rover-〉pwr) —= 3;(p_rover—>strg) += 10;printf("You have collected a sample of the object!\n\n");}break;case 3:p_rover->pwr -= 10; /*Distance around object— value gained from mapper module. 1 square = -1 power*/printf(”You have avoided the object!\n\n”);break;case 4:p_rover—>pwr —= 2;printf("You have driven through the obstacle!\n\n”);break;case 5:if(p_rover—〉pwr == 100)printf(”\n\nYou do not need to charge up!\n\n");else{p_rover—〉pwr = 100;printf(”You have charged up your rover!\n\n”);}break;default:printf("\n\n*****ERROR*****\nInvalid Selection\n\n”);break;}}void action(char object, struct rover *p_rover){int selection;switch(object)case 1:printf(”\nYou have encountered: A Sandy Rock\n\n");printf(”This object can be:\n1.\tDestroyed\n2.\tCollected\nPlease choose action 1 or 2:\t"); scanf("%d”, &selection);stats_update(selection, p_rover);break;case 2:printf(”\nYou have encountered: A Solid Rock\n\n");printf(”This object can be:\n1。
(完整版)C语言课程设计实验报告
}
while(!ch);
system("cls");
/*一下为功能选择模块*/
说明:进入欢迎页面。
1.2
do
{
printf("\n\t\t\t\t1.录入球队信息\n\t\t\t\t2.显示积分排行榜\n\t\t\t\t3.保存积分\n\t\t\t\t4.退出\n");
printf("\t\t\t\t选择功能选项(输入所选功能前的数字):");
int i=0,j,n;
for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
for(n=j+1;n<10;n++)
{
if(Match[i][j]总积分等于Match[i][n]的总积分)
{
if(Match[i][j]总净胜球小于Match[i][n].总净胜球)
{
Match[i][j]结构体与Match[i][n]结构体调换
}
}
}
}
}
}Байду номын сангаас
void sort2()/*排序数据函数*/
{
struct MatchInfo match;
int i=0,j,n;
for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
for(n=j+1;n<10;n++)
{
if(Match[i][j]总积分等于Match[i][n]的总积分)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
防灾科技学院实习报告书防灾科技学院灾害信息工程系2015年制项目一C语言实习一、实习目的本课程是网络工程专业的一门专业必修课程,是学生学习完C语言程序设计专业基础课程后,进一步学习其他专业课程前必须完成的一项实践教学环节。
本次实习通过1个综合性强、实用性强、趣味性强的应用实例,使学生进一步巩固C语言基本知识,掌握应用程序设计语言描述问题、分析问题和解决问题的方法和思想,为后继的面向对象程序设计、数据结构、Web应用技术、网络工程专业实习、网络工程生产实习、网络工程毕业实习课程等课程打下基础。
通过本课程的学习,使学生进一步明确学习目标、增强学习动力、培养学习兴趣。
二、实习任务概述任务一:员工工资管理系统的设计与实现本系统基于C语言,实现了一个小型的信息管理系统,主要包括以下功能:1.信息的录入:a)首次进入系统,可以添加职工的工号、姓名、基本工资、津贴、员工奖金等数据录入操作。
b)系统再次登录,可以从文件导入信息,也可以对文件内容进行修改,保存退出。
2.删除操作:对离职的员工信息要从系统里删除。
3.显示操作:将结构体中职工信息输出到屏幕上。
4.查询与修改操作:分别按职工工号和职工姓名查询,修改职工信息并保存。
5.统计与排序操作:分别统计所有员工的总工资,实现对总工资的排序。
三、实习所用软件简介VC++6.0是Microsoft公司推出的一个基于Windows系统平台、可视化的集成开发环境,它的源程序按C++语言的要求编写,并加入了微软提供的功能强大的MFC(Microsoft Foundation Class)类库。
使用VC++提供的高度可视化的应用程序开发工具和MFC类库,可使应用程序开发变得简单。
使用VC++提供的高度可视化的应用程序开发工具和MFC类库,可使应用程序开发变得简单。
Visual C++6.0以拥有“语法高亮”,自动编译功能以及高级除错功能而著称。
比如,它允许用户进行远程调试,单步执行等。
还有允许用户在调试期间重新编译被修改的代码,而不必重新启动正在调试的程序。
其编译及创建预编译头文件(stdafx.h)、最小重建功能及累加连结(link)著称。
这些特征明显缩短程序编辑、编译及连结的时间花费,在大型软件计划上尤其显著。
四、参考文献[1] 韩莹.C语言实训教程[M].北京交通大学出版社,2013.[2] 李新良.教学测评系统的应用与研究[J].湖南人文科技学院学报,2012(6):73-77.[3] 张高煜.C语言程序设计实训.中国水利水电出版社,2011.8.[4] 白帆.C语言开发实例详解.电子工业出版社,2012.5.[5] 王为青.C语言实战105例.北京:人民邮电出版社,2011.[6]明日科技编著.C语言项目案例分析.北京:清华大学出版社,2012.五、实习日程安排六、实习内容及步骤任务1 员工工资管理系统(C语言模块)1.1 系统开发思路(需求分析)随着计算机技术的发展,企业管理越来越趋于自动化,而工资管理是企业管理的重要的组成部分,它与企业的财务管理、人才管理有着密切的联系。
由于企业员工工资结构存在一定的规律性,工资放在时间上和操作上存在的一定的重复性,这使得企业事业单位工资管理计算机的实现成为了可能。
1.2 数据结构设计struct Worker{char workernum[10];char workername[20];int basicwage;int allowance;int Bonus;int totalwage;}Worker_Infor[100];1.3 系统设计与实现1.3.1系统功能结构图及流程图图1-1员工工资管理系统参考模块图.1.3.2 主要函数设计void Input_Infor() 函数功能:员工信息的录入void Print_Worker(int i)函数功能:员工工资的显示void delet_worker() 函数功能:删除员工信息int Search_Name() 函数功能:姓名查询int Search_Num() 函数功能:工号查询int Search_Worker() 函数功能:查询主函数,调用姓名/工号查询void Modify_Worker() 函数功能:修改员工信息void Cal_Wages() 函数功能:计算总工资void Sort_Wage() 函数功能:对员工工资排序int Save_Infor() 函数功能:文件写操作void Up_Infor() 函数功能:读文件void Input_worker(int i) 函数功能:添加新的员工信息void main() 函数功能:主函数选择进入界面1.3.3 系统功能设计与实现下面分别对该模块中的具体功能进行详细描述,主要功能实现的代码相应功能实现的界面截图。
1.---------------------------------------//主函数void main(){int c,t=1,i;Up_Infor();printf("输入员工数量:");scanf("%d",&n);while(t){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 ("## 8.删除员工信息 ##\n"); printf ("## 9.退出程序 ##\n"); printf("## ##\n"); printf ("## 请选择对应的编号(1—7) ##\n"); printf ("#######################################################\n");scanf("%d",&c);getchar();if (c<1||10<c){printf ("\t输入错误,请重新输入:\n");continue ;} switch(c){case 1:Input_Infor();Cal_Wages();break;case 2:Sort_Wage();break;case 3:Save_Infor();printf ("\t按任意键继续!\n");getchar();break;case 4:Search_Worker();break;case 5:Modify_Worker();break;case 6:for (i=0;i<n;i++)Print_Worker(i);break;case 7:Input_worker(i);break;case 8:delet_worker();break;case 9:t=0;printf ("\t谢谢使用!\n");printf ("\t按任意键返回!");break;}}图1-32.----------------------------------------//读文件void Up_Infor(){int i;FILE *pk;pk=fopen("D:\\worker.txt","at+");for (i=0;i<100;i++){fscanf(pk,"%-10s%-8s\t%-10d%-10d%-10d%-10d\t\n",Worker_Infor[i ].workernum,Worker_Infor[i].workername,Worker_Infor[i].basicwage, Worker_Infor[i].allowance,Worker_Infor[i].Bonus,Worker_Infor[i].t otalwage);if (strcmp(Worker_Infor[i].workernum,"stop")==0)break;fclose(pk);}3.------------------------------//员工信息的录入void Input_Infor(){char c;int i;if (n==0)i=0;else i=n-1;printf ("\t请输入职工工资信息!\n");while (1){printf ("\t请输入第%d位职工编号:",i+1);//gets(Worker_Infor[i].workernum);scanf("%s",Worker_Infor[i].workernum);getchar();printf ("\t工号为%s职工的姓名:",Worker_Infor[i].workernum);gets(Worker_Infor[i].workername);printf ("\t%s职工基本工资:",Worker_Infor[i].workername);while(1){scanf("%d",&Worker_Infor[i].basicwage);if (Worker_Infor[i].basicwage>=0)break;else printf ("\t输入错误,请重试!");}printf ("\t%s职工的津贴:",Worker_Infor[i].workername);while(1){scanf("%d",&Worker_Infor[i].allowance);if (Worker_Infor[i].allowance>=0)break;else printf ("\t输入错误,重新输入:");}printf ("\t%s职工的奖金:",Worker_Infor[i].workername);while(1){scanf("%d",&Worker_Infor[i].Bonus);if (Worker_Infor[i].Bonus>=0)break;else printf ("\t输入错误,重新输入:");}i++;n=i;getchar();printf ("\n是否继续输入:(Y/N )或者 (y/n):");scanf ("%c",&c);if (c=='n'||c=='N')break;}}图1-44.-----------------------------------//对员工工资排序void Sort_Wage(){int i,j;int Worker_temp;Cal_Wages();for (i=0;i<n;i++){for (j=i+1;j<n;j++)if (Worker_Infor[j].totalwage<= Worker_Infor[i].totalwage){Worker_temp=Worker_Infor[i].totalwage;Worker_Infor[i].totalwage=Worker_Infor[j].totalwage;Worker_Infor[j].totalwage=Worker_temp;}}for (i=0;i<n;i++)printf("%-10s%-8s\t%-10d%-10d%-10d%-10d\t\n",Worker_Infor[i].workernum, Worker_Infor[i].workername,Worker_Infor[i].basicwage,Worker_Infor [i].allowance,Worker_Infor[i].Bonus,Worker_Infor[i].totalwage);}图1-55.---------------//文件写操作,文件保存到硬盘上int Save_Infor(){int i;FILE *pk;Cal_Wages();if ((pk=fopen("D:\\worker.txt","wr+"))==NULL){printf ("文件打开失败!");return 0;}for (i=0;i<n;i++){fprintf(pk,"%-10s%-8s\t%-10d%-10d%-10d%-10d\t\n",Worker_Infor[ i].workernum,Worker_Infor[i].workername,Worker_Infor[i].basicwage ,Worker_Infor[i].allowance,Worker_Infor[i].Bonus,Worker_Infor[i]. totalwage);}fclose(pk);printf ("文件保存成功!");return 1;}图1-66.-----------------//查询员工信息int Search_Worker(){int i,m;printf ("请选择查询方式:\n1.按姓名查找\n2.按员工工号查找\n3.退出\n");scanf ("%d",&m);switch(m){case 1:i=Search_Name();return i ;break;case 2:i=Search_Num();return i ;break;case 3:return -1;}}6.1--------------------------------//姓名查询int Search_Name(){int i;char name[20];printf ("请输入要查询的姓名:");scanf ("%s",name);for (i=0;i<n;i++){if (strcmp(name,Worker_Infor[i].workername)==0){printf("%-10s%-8s\t%-10d%-10d%-10d%-10d\t\n",Worker_Infor[i].workernum, Worker_Infor[i].workername,Worker_Infor[i].basicwage,Worker_Infor [i].allowance,Worker_Infor[i].Bonus,Worker_Infor[i].totalwage);return i;break;}}if (i==n){printf ("没有找到该员工!\n");return -1;}//else return i;}图1-76.2---------------------------//按工号查询int Search_Num(){int i;char num[20];printf ("请输入要查询的工号:");scanf ("%s",num);for (i=0;i<n;i++){if (strcmp(num,Worker_Infor[i].workernum)==0){printf("%-10s%-8s\t%-10d%-10d%-10d%-10d\t\n",Worker_Infor[i].workernum, Worker_Infor[i].workername,Worker_Infor[i].basicwage,Worker_Infor [i].allowance,Worker_Infor[i].Bonus,Worker_Infor[i].totalwage);return i;break;}}if (i==n){printf ("没有找到该员工!\n");return -1;}//else return i;}图1-87.--------------------------//修改员工信息void Modify_Worker(){int i,m;printf ("请查询您要修改的员工:\n");i=Search_Worker();getchar();printf("#######################################################\n");printf ("## 请选择您要修改的内容: ##\n");printf ("## 1.员工号 ##\n");printf("## 2.员工姓名 ##\n");printf ("## 3.员工的基本工资 ##\n");printf ("## 4.员工的津贴 ##\n");printf("## 5.员工的奖金 ##\n");printf("## 6.退出 ##\n");printf("#######################################################\n");scanf ("%d",&m);switch(m){case 1:printf ("请输入新的员工号:");scanf ("%s",&Worker_Infor[i].workernum);break;case 2:printf ("请输入新的员工名:");scanf ("%s",&Worker_Infor[i].workername);break;case 3:printf ("请输入新的员工基本工资:");scanf ("%d",&Worker_Infor[i].basicwage);break;case 4:printf ("请输入新的员工津贴:");scanf("%d",&Worker_Infor[i].allowance);break;case 5:printf ("请输入新的员工奖金:");scanf ("%d",&Worker_Infor[i].Bonus);break;case 6:return;}printf ("修改后的员工的基本信息为:\n");Print_Worker(i);}图1-98.---------------//查看所有员工信息void Print_Worker(int i){printf("%-10s%-8s\t%-10d%-10d%-10d%-10d\t\n",Worker_Infor[i].workernum, Worker_Infor[i].workername,Worker_Infor[i].basicwage,Worker_Infor [i].allowance,Worker_Infor[i].Bonus,Worker_Infor[i].totalwage);}图1-109.-------------------//添加新的员工信息void Input_worker(int i){char c;printf("\t请输入职工工资信息:\n");while(1){printf("\t第%d位职工的编号:",n+1);gets(Worker_Infor[i].workernum);printf("\t工号为%s职工的姓名:",Worker_Infor[n].workernum);gets(Worker_Infor[n].workername);printf("\t%s职工的基本工资:",Worker_Infor[n].workername);while(1){scanf("%d",&Worker_Infor[n].basicwage);if(Worker_Infor[n].basicwage>=0)break;else printf("\t输入错误请重试:");}printf("\t%s职工的津贴:",Worker_Infor[n].workername);while(1){scanf("%d",&Worker_Infor[n].allowance);if(Worker_Infor[n].allowance>=0)break;else printf("\t输入错误请重试:");}printf("\t%s职工的奖金:",Worker_Infor[n].workername);while(1){scanf("%d",&Worker_Infor[n].Bonus);if(Worker_Infor[n].Bonus>=0)break;else printf("\t输入错误请重试:");}i++;n++;getchar();printf("是否想要输入下一个员工信息(Y/N):");scanf("%c",&c);if(c=='N'||c=='n')break;getchar();}}图1-11图1-1210.----------------//删除员工信息void delet_worker(){int i,k=0;char name[20];printf("输入需要删除的员工姓名:");scanf("%s",name);for(i=0;i<n-1;i++){if(strcmp(name,Worker_Infor[i].workername)==0);break;} while(1){strcpy(Worker_Infor[i].workername,Worker_Infor[i+1].workername );strcpy(Worker_Infor[i].workernum,Worker_Infor[i].workernum);Worker_Infor[i].allowance=Worker_Infor[i].allowance;Worker_Infor[i].basicwage=Worker_Infor[i+1].basicwage;Worker_Infor[i].Bonus=Worker_Infor[i+1].Bonus;Worker_Infor[i].totalwage=Worker_Infor[i+1].totalwage;Print_Worker(i);i++;if(i==n-1)break;}}图1-13图1-141.4 结论1.4.1 本次实习取得的成绩第一次接触到这样多的代码的书写,不仅锻炼了自己的编程能力,而且学会了坚持的精神。