源程序清单
工人类包括薪水类多文件操作C++源程序
Worker::~Worker()
{
number--;
}
int Worker::Getnumber()
{
return number;
}
void test(){
cout<<"现有工人:"<<Worker::Getnumber()<<"名。"<<endl;
Salary s1;
double getSubsidy();
double getRent();
double getWaterFee();
double getElecFee();
double RealSalary();
};
#endif
//薪水类的定义部分Salary.cpp源程序清单如下:
}
void Salary::setRent(double f)
{
Rent=f;
}
void Salary::setWaterFee(double f)
{
WaterFee=f;
}
void Salary::setElecFee(double f)
{
ElecFee=f;
}
double Salary::getWage()
}
Salary::Salary()
{
Wage=Subsidy=Rent=WaterFee=ElecFee;
}
void Salary::setWage(double f)
{
Wage=f;
}
void Salary::setSubsidy(double f)
源程序清单
源程序清单7. 源程序清单#include#include#define MVNum 100 //最大顶点数#define Maxint 32767typedef char VertexType;typedef int Adjmatrix;typedef enum {FALSE,TRUE} boolean; //定义布尔型typedef struct{VertexType vexs[MVNum]; //顶点数组,类型假定为char型Adjmatrix arcs[MVNum][MVNum]; //邻接矩阵,假定为int型}MGraph;int D1[MVNum],P1[MVNum];int D[MVNum][MVNum],P[MVNum][MVNum];void CreateMGraph(MGraph *G,int n,int e){ //采用邻接矩阵表示法构造有向图G,n,e表示图的当前顶点数和边数int i,j,k,w;for(i=1;i<=n;i++) //输入顶点信息G->vexs[i]=(char)i;for(i=1;i<=n;i++)for(j=1;j<=n;j++)G->arcs[i][j]=Maxint; //初始化邻接矩阵printf("输入%d条边的i,j及w:\n",e);for(k=1;k<=e;k++){ //读入e条边,建立邻接矩阵scanf("%d,%d,%d",&i,&j,&w);G->arcs[i][j]=w;}printf("有向图的存储结构建立完毕!\n");}void Dijkstra(MGraph G,int v1,int n){ //用Dijkstra算法求有向图G的v1顶点到其他顶点v的最短路径P[v]及其权D[v]//设G是有向图的邻接矩阵矩阵,若边不存在,则G[i][j]=Maxint //S[v]为真当且仅当v属于S,即已求得从v1到v的最短路径int D2[MVNum],P2[MVNum];int v,i,w,min;boolean S[MVNum];for(v=1;v<=n;v++){ //初始化S和DS[v]=FALSE; //置空最短路径终点集D2[v]=G.arcs[v1][v]; //置初始的最短路径值if(D2[v]<maxint)P2[v]=v1; //v1是v的前趋(双亲)elseP2[v]=0; //v无前趋}D2[v1]=0; S[v1]=TRUE; //S集初始时只有源点,源点到源点的距离为0//开始循环,每次求得v1到某个v顶点的最短路径,并将v加到S集中for(i=2;imin=Maxint;for(w=1;w<=n;w++)if(!S[w] && D2[w]<min){ v=w; min=D2[w]; } //w顶点离v1顶点更近S[v]=TRUE;for(w=1;w<=n;w++) //更新当前最短路径及距离if(!S[w] && (D2[v]+G.arcs[v][w]<d2[w])){ //修改D2[w]和P2[w],w属于v-sD2[w]=D2[v]+G.arcs[v][w];P2[w]=v;}}printf("路径长度路径\n");for(i=1;i<=n;i++){printf("%5d",D2[i]);printf("%5d",i);v=P2[i];while(v!=0){printf("<-%d",v);v=P2[v];}printf("\n");}}void Floyd(MGraph G,int n){int i,j,k;for(i=1;i<=n;i++) //设置路径长度D和路径path初值for(j=1;j<=n;j++){if(G.arcs[i][j]!=Maxint)P[i][j]=j; //j是i的后继elseP[i][j]=0;D[i][j]=G.arcs[i][j];}for(k=1;k<=n;k++){ //做k次迭代,每次均试图将顶点k扩充到当前求得的从i到j的最短路径Pij上for(i=1;i<=n;i++)for(j=1;j<=n;j++){if(D[i][k]+D[k][j]<d[i][j]){D[i][j]=D[i][k]+D[k][j]; //修改长度P[i][j]=P[i][k];}}}}void main(){MGraph G;int n,</d[i][j]){</d2[w]))</min)</maxint)e,v,w,k;int xz=1;printf("输入图中顶点个数和边数n,e:");scanf("%d,%d",&n,&e);CreateMGraph(&G,n,e); //建立图的存储结构while(xz!=0){printf("******求城市之间的最短路径******\n");printf("================================\n" );printf("1.求一个城市到所有城市的最短路径\n");printf("2.求任意的两个城市之间的最短路径\n");printf("================================\n" );printf("请选择:1 或 2 ,选择0 退出 :");scanf("%d",&xz);if(xz==2){Floyd(G,n);printf("输入源点(或称起点)和终点:v,w:");scanf("%d,%d",&v,&w);k=P[v][w]; //k为起点v的后继顶点if(k==0)printf("顶点 %d 到 %d无路径!\n",v,w);else{printf("从顶点%d到%d的最短路径是:%d\n",v,w,v);while(k!=w){printf("->%d",k); //输出后继顶点k=P[k][w]; //继续找下一个后继顶点}printf("->%d",w); //输出终点printf("路径长度:%d\n",D[v][w]);}}elseif(xz==1){printf("求单源路径,输入源点v:"); scanf("%d",&v);Dijkstra(G,v,n);}}printf("结束求最短路径,再见!\n"); }。
源代码清单
本资料由-大学生创业|创业|创业网/提供资料
<项目名称>
源代码清单
版本:<1.0>
文档编号:密级:秘密
编写:编写日期:
审核:审核日期:
批准:批准日期:年月日
Copyright @, All right reserved
修订记录
目录
0.介绍 (1)
0.1 目的 (1)
0.2 范围 (1)
0.3 读者对象 (1)
0.4 参考文献 (1)
0.5 术语与缩写解释 (1)
1、系统目录结构 (1)
2、代码清单 (1)
本资料由-大学生创业|创业|创业网/提供资料0.介绍
0.1 目的
0.2 范围
0.3 读者对象
0.4 参考文献
0.5 术语与缩写解释
1、系统目录结构
提示:说明系统目录结构与功能模块间的关系
2、代码清单
提示:按功能模块划分,列出源代码文件名称:。
源程序清单流程图(1)
输入两个8位数据A和B,求|A-B|,结果放在内存中,并输出结果。
2、调试说明
1在进行循环程序设计时,要注意循环初始化、内外层循环的控制、循环结束条件等的设置对整个程序的执行逻辑要非常清楚。这样可以避免死循环等意外情况的出现。
2分支程序的控制很重要,编写代码时,要注意注释重要的分支控制部分。这样思路才不会乱。同时要对照流程图,随时观察代码的逻辑思路是否正确。
3、源程序清单和流程图,附执行结果截图。
源程序清单
DATA SEGMENT
DB 'X:$','H',0AH,0DH,'Y:$','H',0AH,0DH,'|X-Y|:$'
X DB 0
Y DB 0
Z DB 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV DX,0
MOV AH,09H
INT 21H
CALL INPUT
MOV X,BL
ADD DX,3
MOV AH,09H
INT 21H
CALL INPUT
MOV Y,BL
MOV AL,X
MOV BL,Y
SUB AL,BL
MOV Z,AL
JC _OUT
JMP NEXT
_OUT: UB BL,X
MOV DL,BL
MOV AH,02H
INT 21H
DEC CH
JNZ LOP
MOV DL,'H'
MOV AH,02H
INT 21H
C语言_源代码-波形发生器_程序清单
波形发生器程序清单:ORG 0000HAJMP MAINORG 0000BHLJMP TOINTORG 0030HMAIN:MOV A,#30HMOV SP, AMOV 40H, #00H ;波形显初值MOV 41H,#00H ;频率显示初值MOV 42H,#00HMOV 43H,#00HMOV 44H,#00HMOV 45H,#00H ;参考电压显示初值MOV 46H,#00H ;设置标志初值MOV DPTR,#7FFCH ;初始化8255MOV A, #90HMOVX @DPTR,A;…………………LED显示子程序……………………………………………………;DISPLAY:MOV R2,H06H ;显示子程序MOV R1,#80HMOV R0,#40HDIS1:MOV DPTR,#7FFEH ;指向B口MOV A,R1MOVX @DPTR, ARR A ;形成下一次位选信号MOV R1 AMOV A,@R0 ;取显示数字MOV DPTR,#DISPLAYTABMOVC A,@A+DPTR ;由数字转换成显示段码MOV DPTR,#7EFFH ;指向A口MOV @DPTR, A ;送段码到A口LCALL DELAY ;显示延时INC R0DJNZ R2, DIS1 ;判断是否显示6次MOV A, #00HMOV P1, A ;熄灭波形指示灯AJMP KEYSPAN ;转到键盘管理子程序DELAY:MOV R3,#80H ;延时LOOP1:MOV R4,#0A0HDJNZ R4,$DJNZ R3,LOOP1RETDISPLAYTAB:DB 3FH,06H,5BH,4FH,66H ;0 1 2 3 4DB 6DH,7DH,07H,7FH,6FH ;5 6 7 8 9DB 40H ;—;…………………键盘管理子程序……………………………………………………;KEY SPAN:MOV A,#F0HCLR P2.7MOV R0, #FDH ;指向C口MOVX @R0, A ;输出列扫描查询码MOV A,@R0 ;读入行状态CJNE A,F0H,KEY1 ;有键闭合、转KEY1LJMP KEYSPANEND ;无键闭合、退出KEY1:LCALL DELAY10ms ;延时、去抖动CLR IE ;关闭定时中断MOV R1,#FEHKEY2:MOV A,R1CLR P2.7MOVX @R0, A ;输出列扫描码MOVX A,@R0 ;读入行状态和列状态ANL A,#F0H ;保留行状态CJNE A,#F0H,KEY3 ;有键闭合、转KEY3,无键闭合形成下一次列扫描码,并判断是否扫描四次MOV A,R1RL AMOV R1, AJB ACC.3,KEY2LJMP KEYSPANEND ;四次列扫描完毕,退出KEY3:MOV R2, A ;行码送R2中保存MOV A,R1 ;扫描码送A中ANL A,#0FH ;保留列码(低4位)ORL A,R2 ;列码在低4位,行码在高4位MOV R2, A ;列行码值保存在R2MOV DPTR,#KEYTAB ;指向键特征值表MOV R1,#00H ;从键值0开始比对KEY4:CLR AMOVC A,@A+DPTR ;取特征值XRL A,R2 ;列行码值与特征值比对JZ KEY5 ;A=0找到键特征值,转KEY5INC R1 ;形成下一个键值INC DPTR ;形成下一个特征值地址CJNE R1,#10H,KEY4 ;判断是否比对了16次,R1≠10H,转KEY4,否则,顺序执行LJMP KEYSPANEND ;退出KEY5:MOV A,#F0HCLR P2.7MOVC @R0, A ;输出查询码MOVC A,@R0 ;读入状态SETB P2.7CJNE A, #F0H, KEY5 ;等待键释放LCALL KEYPROCESS ;调用键功能子程序KEYSPANEND:LJMP DISPLAY ;返回到LED显示子程序开始处DELAY10ms:MOV R3,#0C8HLOOP2:MOV R4,#0A0HDJNZ R4,$DJNZ R3,LOOP2RET;…………………………键特征值表…………………………………………………………;KEYTAB:DB EEH,EDH,EBH,E7H ;0 1 2 3 DB DEH,DDH,DBH,D7H ;4 5 6 7DB CEH,CDH,CBH,C7H ;8 9 EN CLDB 7EH,7DH,7BH,77H ;W F V .;………………………键功能散转………………………………………………………;KWYREOCESS:MOV A,R1RL AMOV DPTR,#KEYPROTABJMP @A+DPTRKEYPROTAB: AJMP KEY_0_PROAJMP KEY_1_PROAJMP KEY_2_PROAJMP KEY_3_PROAJMP KEY_4_PROAJMP KEY_5_PROAJMP KEY_6_PROAJMP KEY_7_PROAJMP KEY_8_PROAJMP KEY_9_PROAJMP KEY_EN_PROAJMP KEY_CL_PROAJMP KEY_W_PROAJMP KEY_F_PROAJMP KEY_V_PROAJMP KEY_·_PRO;………………………………键功能处理子程序………………………………………………;KEY_0_PRO:MOV A,46H ;“0”键处理子程序CJNE A,#00H,D01SJMP D0ENDD01:CJNE A,#01H,D0ENDCJNE R5,#43H,D02SJMP D0ENDD02:MOV @R5,#0HINC R5D0END:RETKEY_1_PRO:MOV A,#46H ;“1”键处理子程序CJNE A,#00H,D11AJMP D1ENDD11:CJNE A,#01H,D12CJNE R5,#43H,F1AJMP D1ENDF1:MOV @R5,#01HINC R5AJMP D1ENDD12:CJNE A,#02H,D13MOV 45H,#01HSJMP D1ENDD13:MOV 40H,#01HD1END:RETKEY_2_PRO:MOV A,#46H ;“2”键处理子程序CJNE A,#00H,D21AJMP D2ENDD21:CJNE A,#01H,D22CJNE R5,#43H,F2AJMP D2ENDF2:MOV @R5,#02HINC R5AJMP D2ENDD22:CJNE A,#02H,D23MOV 45H,#02HSJMP D2ENDD23:MOV 40H,#02HD2END:RETKEY_3_PRO:MOV A,#46H ;“3”键处理子程序CJNE A,#00H,D31AJMP D3ENDD31:CJNE A,#01H,D32CJNE R5,#43H,F3AJMP D3ENDF3:MOV @R5,#03HINC R5AJMP D3ENDD32:CJNE A,#02H,D33MOV 45H,#03HSJMP D3ENDD33:MOV 40H,#03HD3END:RETKEY_4_PRO:MOV A,#46H :“4”键处理子程序CJNE A,#00H,D41AJMP D4ENDD41:CJNE A,#01H,D42CJNE R5,#43H,F4AJMP D4ENDF4:MOV @R5,#04HINC R5AJMP D4ENDD42:CJNE A,#02H,D43MOV 45H,#04HSJMP D4ENDD43:MOV 40H,#04HD4END:RETKEY_5_PRO:MOV A,46H ;“5”键处理子程序CJNE A,#00H,D51AJMP D5ENDD51: CJNE A, #01H, D52CJNE R7, #44H, F5AJMP D5ENDF5:MOV @R5, #00HINC R5AJMP D5ENDD52:CJNE A,#02H,D53MOV 45,#05HD53:RETKEY_6_PRO:RET ;“6”键处理子程序KEY_7_PRO:RET ;“7”键处理子程序KEY_8_PRO:RET ;“8”键处理子程序KEY_9_PRO:RET ;“9”键处理子程序KEY_EN_PRO:MOV A,40HCJNE A,#00H,EN1AJMP ENENDEN1:MOV A,45HCJNE A,#00H,VREFAJMP ENENDVREF:DPTR,#VREFTABMOVC A,@A+DPTRMOV R0, #FFHCLR P2.5 ;选中0832(1)MOCX @R0, A ;向0832(1)送参考电压编码MOV A,41HORL A,42HORL A,43HCJNE A,#00H,1KHZAJMP ENEND1KHZ:MOV A,41H ;1KHZ设置定时初值CJNE A,#01H,500HZMOV TMOD,#00HMOV TLO,#01HMOV THO,#0FFHAJMP OPEN_TI0500HZ:MOV A,42H ;500HZ设置定时初值CJNE A,#05H,200HZMOV TMOD,#00HMOV TLO,#01HMOV THO,#0FEHAJMP OPEN_TI0200HZ:CJNE A,#02H,100HZ ;200HZ设置定时初值MOV TMOD,#00HMOV TLO,#03HMOV THO,#0FBHAJMP OPEN_TI0100HZ:CJNE A,#01H,50HZ ;100HZ设置定时初值MOV TMOD,#00HMOV TLO,#08HMOV THO,#0F6HAJMP OPEN_TI050HZ:MOV A,43H ;50HZ设置定时初值CJNE A,#05H,20HZMOV TMOD,#00HMOV TLO,#0FHMOV THO,#0ECHAJMP OPEN_TI020HZ:CJNE A,#02H,10HZ ;20HZ设置定时初值MOV TMOD,#00HMOV TLO,#16HMOV THO,#90HAJMP OPEN_TI010HZ:CJNE A,#01H,ENEND ;10HZ设置定时初值MOV TMOD,#00HMOV TLO,#0BHMOV THO,#9EHAJMP OPEN_TI0OPEN_TI0:MOV TCON,#10H ;定时器0工作,运行位TR控制MOV IE,82H ;中断允许总控制,定时器0中断允许MOV R6,#00H ;样值初始编号ENEND:RETVREFTAB:DB 32H,68H,A2H,CDH,FFH ;1V 2V 3V 4V 5VKEY_CL_PRO:MOV A,#00H ;“CL”键处理子程序MOV R0,#40HCL1:MOV @R0, #40HINC R0CJNE R0, #46H, CL1MOV R5, AMOV TL0, #00HMOV TH0, #00HCLR TR0RETKEY_F_PRO:MOV A, #01H;“F”处理子程序MOV 46H, A ;(46H)=01H表示频率设置MOV R5, 42HMOV 41H #0AH ;频率LED位显示“- - - 0”MOV 42H #0AHMOV 43H #0AHRETKEY_V_PRO:MOV A, #02H ;“V”处理子程序MOV 46H, A ;(46H)=02H表示参考电压设置MOV 45H #0AH ;电压LED位显示“—”RETKEY_W_PRO:MOV A, #03H ;“W”处理子程序MOV 46H, A ;(46H)=03H表示波形选择MOV 40H #0AH ;波形LED位显示“—”RETKEY_·_PRO:RET ;“·”处理子程序;…………………………定时中断服务程序……………………………………………………;TOINT:PUSH PSWPUSH ACCPUSH DPHPUSH DPLPUSH R0PUSH R1PUSH R2PUSH R3PUSH R4 ;保护现场MOV R7, 40HLCALL WA VE1;调用波形产生子程序POP R4POP R3POP R2POP R1POP R0POP DPLPOP DPHPOP ACCPOP PSW;恢复现场RETI;返回断点处,执行主程序;…………………………波形产生子程序……………………………………………………;WA VE1:CJNE R7, #01H, W A VE2CLR P1.0MOV DPTR, #W_TAB1 ;指向方波表首址MOV A, R6MOVC A, @A+DPTRMOV DPTR, #0AFFFH ;指向DAC0832(2)MOVX @DPTR, AMOV A, R6INC AMOV R6, A ;指向下一个样值CJNE A, #32, W_ENDMOV R6, #00HAJMP W_ENDWA VE2:CJNE R7, #02H, W A VE3CLR P1.1MOV DPTR, #W_TAB2 ;指向正弦波表首址MOV A, R6MOVC A, @A+DPTRMOV DPTR, #0AFFFH ;指向DAC0832(2)MOVX @DPTR, AMOV A, R6INC AMOV R6, A ;指向下一个样值CJNE A, #32, W_ENDMOV R6, #00HAJMP W_ENDWA VE3:CJNE R7, #03H, W A VE4CLR P1.2MOV DPTR, #W_TAB3 ;指向三角波表首址MOV A, R6MOVC A, @A+DPTRMOV DPTR, #0AFFFH ;指向DAC0832(2)MOVX @DPTR, AMOV A, R6INC AMOV R6, A ;指向下一个样值CJNE A, #32, W_ENDMOV R6, #00HAJMP W_ENDWA VE4:CJNE R7, #04H, W_ENDCLR P1.3MOV DPTR, #W_TAB4 ;指向锯齿波表首址MOV A, R6MOVC A, @A+DPTRMOV DPTR, #0AFFFH ;指向DAC0832(2)MOVX @DPTR, AMOV A, R6INC AMOV R6, A ;指向下一个样值CJNE A, #32, W_ENDMOV R6, #00HW_END :RET ;返回中断服务程序执行;……………………………波形样值表……………………………………………………;W_TAB1:DB 0FFH, FFH, FFH, FFH, FFH, FFH, FFH, FFHDB 0FFH, FFH, FFH, FFH, FFH, FFH, FFH, FFHDB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00HDB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00HW_TAB2:DB 98H, B0H, C6H, D9H, E9H, F5H, FCH, FFHDB FCH, F5H, E9H, D9H, C6H, B0H, 98H, 7FHDB 66H, 4EH, 38H, 25H, 15H, 0AH, 02H, 00HDB 02H, 0AH, 15H, 25H, 38H, 4EH, 66H, 7FHW_TAB3:DB 8FH, 9FH, 0AFH, BFH, CFH, DFH, EFH, FFHDB EFH, DFH, CFH, BFH, AFH, 9FH, 8FH, 7FHDB 6FH, 5FH, 4FH, 3FH, 2FH, 1FH, 0FH, 00HDB 0FH, 1FH, 2FH, 3FH, 4FH, 5FH, 6FH, 7FHW_TAB4:DB 0FH, 17H, 1FH, 27H, 2FH, 37H, 3FH, 47HDB 4FH, 57H, 5FH, 67H, 6FH, 77H, 7FH, 87HDB 8FH, 97H, 9FH, A7H, AFH, B7H, BFH, C7HDB CFH, D7H, DFH, E7H, EFH, F7H, FFH, 07HEND。
危险源辨识、风险评价表及重要危险源清单(包括程序文件)
(一)各项目部项目经理负责对危险源辨识及风险评价的组织领导工作,审定本项目部重大危险清单和控制计划。
(二)安全部负责有关制度的监督检查工作,并组织有关部门对本区域危害因素调查和重大危险源的评价,初步确定重大危险源,共同制订控制计划。
(三)各项目部负责本区域危险源调查,分析和评价一般危险因素,初步确定相关的重大危险源,制订相应控制计划。
第四条 工作程序(一)总则1、危险源的分类,有两种:(1)按导致事故和职业危害的直接原因进行分类,详见GB/T13816-92《生产过程危险和危险源分类与代码》的规定。
(2)参照事故类别和职业病类别进行分类,详见GB6441-86《企业伤亡事故分类》和卫生部、总工会、原劳动部颁发的《职业病范围和职业病患者处理办法的规定》2、危害辨识和评价采取“项目部主管部门人员负责,相关部门人员参与配合”的方式进行。
危险源辨识与风险评价控制程序第一条 目的通过辨识和评价总承包总所属各项目部施工现场范围内的危险源,进而评价其危险程度,判定重大危险源,采取相应措施,进行有效控制。
第二条 范围适用于总承包部所属各项目部场所及施工现场范围内相关的危险源辨识及风险评价。
第三条 职责(二)危险源的辨识1、原则(1)危险源辩识依据本程序、条款的分类和有关法律法规及有关规定及标准,并结合各项目部实际情况,考虑过去、现在、将来三种时态;(2)对进入现场的人员(含内部及外部人员)相关方的活动也应辨识。
(3)对重大危险源进行重点分析,要防止遗漏,特别是可能导致重要事故的危险源要特别关注,不仅分析正常生产、施工操作时的危险源,更要分析设备、装置破坏及操作失误可能产生的严重后果的危险源。
2、辨识(1)危险源辨识应考虑项目部所有的活动及办公场所、施工现场,从办公区、施工区域布置、建(构)筑物、物质、生产工艺及设备,辅助生产设施、作业环境几部分,分别分析其存在的危险源,列表登记,综合归纳,从而得出系统中存在哪些种类危险源及其分布状况的综合资料。
第14讲 文件的应用
及时释放所占资源; 使一个文件流对象可分时与多个文件关联; 使有限的可同时打开的文件总数得到充分利用。
[例1] 编写程序,完成打开一个文件及建立一 个新文件。
源程序清单如下: #include <iostream> #include <fstream> using namespace std; void main() { ifstream ifile1("e:\\test\\file1.txt"); if(!ifile1) cout<<"打开文件1失败"<<endl; else cout<<"打开文件1成功"<<endl;
第十一章
文件的应用
1
教学目标
理解数据文件的基本概念; 掌握建立文件、打开和关闭文件、读写顺序 文件数据的基本操作; 了解文件指针的定位操作。
§11.1 C++的输入输出
一、输入输出的含义
C++语言的输入与输出包括以下3方 面的内容: ⑴ 对系统指定的标准设备的输入和输出。 即从键盘输入数据,输出到显示器屏幕。 这种输入输出称为标准的输入输出,简 称为标准I/O。
除了可以从键盘获取信息以及将输出发 送给计算机屏幕外,程序也能从磁盘上的文 件接收信息或发出信息给磁盘上的文件。 从文件获取信息的操作称为“读取文件或 读操作”,相应的数据文件称为“输入文 件”; 向文件发出信息的操作称为“写入文件或 写操作”,相应的数据文件称为“输出文 件”。 可以使用流对象来完成文件输入和输出 操作。和C++创建的标准cin和cout对象不同, 程序员必须创建程序使用的输入和输出对象。 要创建文件对象,必须在程序中包含fstream
go back n 源程序清单
#include <stdio.h>#include <string.h>#include "protocol.h"#include "datalink.h"static int phy_ready = 0; //物理层状态static boolean between (seq_nr a,seq_nr b,seq_nr c){if( ((a<=b)&&(b<c)) || ((c<a)&&(a<=b)) || ((b<c)&&(c<a)) ) return true;elsereturn false;}static void put_frame(unsigned char *frame, int len) //crc编码并向物理层发送{*(unsigned int *)(frame + len) = crc32(frame, len);send_frame(frame, len + 4);phy_ready = 0;}static void send_data(unsigned char kind,seq_nr frame_nr,seq_nr frame_expected,packet buffer[],int dlen[]) //生成帧{frame s;s.kind = kind;if(kind == Ack) //生成ack帧{s.ack = (frame_expected + MAX_SEQ) % (MAX_SEQ+1);dbg_frame("Send ACK %d\n", s.ack);put_frame((unsigned char *)&s, 2);}else if(kind == Nak) //生成nak帧,s.ack记录需要重传的窗口号{s.ack = frame_expected;dbg_frame("Send NAK %d\n", s.ack);put_frame((unsigned char *)&s, 2);}else //生成数据(data)帧{memcpy(,buffer[frame_nr],PKT_LEN);s.seq = frame_nr;s.ack = (frame_expected + MAX_SEQ) % (MAX_SEQ+1);dbg_frame("Send DATA %d %d, ID %d\n", s.seq, s.ack, *(short *));put_frame((unsigned char *)&s, 3+dlen[frame_nr]);start_timer(frame_nr,DATA_TIMER);}phy_ready = 0;stop_ack_timer();}int main(int argc, char* *argv){int event, arg,len;int bufferLen[MAX_SEQ+1];seq_nr next_frame_to_send=0; /* MAX_SEQ > 1; used for outbound stream, and initianize next frame going out */ seq_nr ack_expected=0; /* oldest frame as yet unacknowledged, and initianize next ack expected inbound */ seq_nr frame_expected=0; /* next frame expected on inbound stream, and initialize number of frame expected inbound */frame r; /* scratch varible */packet buffer[MAX_SEQ+1]; /* buffers for the outbound stream */seq_nr nbuffered=0; /* # output buffers currently in use, and initially no packets are buffered */seq_nr i; /* used to index into the buffer array */protocol_init(argc, argv);lprintf("\nDesigned by Liu Yang,Teng Xiao,Xu Ye Nan, build: " __DATE__" "__TIME__"\n");enable_network_layer();while(true){event = wait_for_event(&arg);switch(event){case NETWORK_LAYER_READY: /* the network layer has a packet to send */bufferLen[next_frame_to_send] =get_packet(buffer[next_frame_to_send]);/*bufferLen 存储每个buffer中数据的有效长度*/nbuffered ++;/* expand the sender's window */send_data(Data,next_frame_to_send,frame_expected,buffer,buf ferLen); //发送数据帧inc(next_frame_to_send);/* advance sender's upper window edge */break;case PHYSICAL_LAYER_READY:phy_ready = 1;break;case FRAME_RECEIVED:/* a data or control frame has arrived */len = recv_frame((unsigned char *)&r,sizeof(r));//返回存放帧的缓冲区的大小if (len < 6 || crc32((unsigned char *)&r, len) != 0) //大小不够或者校验错误{dbg_event("**** Receiver Error, Bad CRC Checksum\n");if(r.seq == frame_expected) //若错误帧中的seq是期望的seq,则发送nak(忽略seq是错误的情况){send_data(Nak,next_frame_to_send,frame_expected,buffer,buff erLen);}break;}if(r.kind == Data) //接收的是数据帧{dbg_frame("Recv data %d %d,ID %d\n",r.seq,r.ack,*(short *));if(r.seq == frame_expected) //若所得帧是期望得到的帧,递交给网络层{put_packet(,len-7);start_ack_timer(ACK_TIMER);inc(frame_expected);}}else if(r.kind == Ack) //接受ackdbg_frame("Recv ACK %d\n", r.ack);else //接受nak,r.ack为对方需要重传的窗口号,表明对方已经收到r.ack之前的数据帧{ //即相当于收到了一个窗口号为r.ack-1的ackdbg_frame("Recv NAK %d\n", r.ack);next_frame_to_send = r.ack;r.ack = (r.ack+MAX_SEQ) % (MAX_SEQ+1);while(between(ack_expected,r.ack,next_frame_to_send)) //执行收到了ack的操作{nbuffered --;stop_timer(ack_expected);inc(ack_expected);}for(i=1;i<=nbuffered;i++) //重发错误帧{send_data(Data,next_frame_to_send,frame_expected,buffer,buf ferLen);inc(next_frame_to_send);}break;}while(between(ack_expected,r.ack,next_frame_to_send)){nbuffered --;stop_timer(ack_expected);inc(ack_expected);}break;case DATA_TIMEOUT: //数据发送超时重发dbg_event("----- data %d timeout\n", arg);next_frame_to_send = ack_expected;for(i=1;i<=nbuffered;i++){send_data(Data,next_frame_to_send,frame_expected,buffer,buf ferLen);inc(next_frame_to_send);}break;case ACK_TIMEOUT: //ack超时单独发送ack帧send_data(Ack,next_frame_to_send,frame_expected,buffer,buff erLen);break;}if(nbuffered < MAX_SEQ && phy_ready) //缓冲区控制enable_network_layer();elsedisable_network_layer();}return 0;}。
C语言实验报告参考答案
长沙理工大学2010C语言实验报告参考答案实验一熟悉C语言程序开发环境及数据描述四、程序清单1.编写程序实现在屏幕上显示以下结果:The dress is longThe shoes are bigThe trousers are black答案:#include<stdio.h>main(){printf("The dress is long\n");printf("The shoes are big\n");printf("The trousers are black\n");}2.改错题(将正确程序写在指定位置)正确的程序为:#include <stdio.h>main(){printf("商品名称价格\n");printf("TCL电视机¥7600\n");printf("美的空调¥2000\n");printf("SunRose键盘¥50.5\n");2.编写程序: a=150,b=20,c=45,编写求a/b、a/c(商)和a%b、a%c(余数)的程序。
答案:#include<stdio.h>main(){int a,b,c,x,y;a=150;b=20;c=45;x=a/b;y=a/c;printf("a/b的商=%d\n",x);printf("a/c的商=%d\n",y);x=a%b;y=a%c;printf("a/b的余数=%d\n",x);printf("a/c的余数=%d\n",y);}4. 设变量a的值为0,b的值为-10,编写程序:当a>b时,将b赋给c;当a<=b时,将a 赋给c。
(提示:用条件运算符)答案:#include<stdio.h>main()int a,b,c;a=0;b=-10;c= (a>b) ? b:a;printf("c = %d\n",c);}五、调试和测试结果1.编译、连接无错,运行后屏幕上显示以下结果:The dress is longThe shoes are bigThe trousers are black3、编译、连接无错,运行后屏幕上显示以下结果:a/b的商=7a/c的商=3a/b的余数=10a/c的余数=154. 编译、连接无错,运行后屏幕上显示以下结果:c =-10实验二顺序结构程序设计四、程序清单1.键盘输入与屏幕输出练习问题1 D 。
源程序清单——精选推荐
四、源程序清单完成人:孙雨佳数据库设计:createdatabase accountuse accountcreatetable users(userId varchar(10)notnull,/*用户账号,主键*/userName varchar(10)notnull,/*用户名*/userPassword varchar(10)notnull,/*密码*/idNo varchar(20)notnull,/*身份证号码,唯一*/userMoney numeric(10,2)default 0,/*总金额,不能小于零*/userStatus varchar(4)check (userStatus='使用'or userStatus='冻结')default'使用',/*用户状态(使用,冻结),默认是使用中*/userAddress varchar(30)notnull,/*用户地址*/startTime DateTime,/*开户时间,应该是开户时的系统时间,不应该人为输入*/primarykey(userId),/*设置主键*/)--用户的状态一旦变成冻结状态,那么卡也应该不能使用createtrigger userstatus_updateon usersafterupdateasifupdate(userStatus)beginif (select userStatus from inserted)='冻结'updatecardset cardStatus='冻结'where userId=(select userId from deleted)if (select userStatus from inserted)='使用'updatecardset cardStatus='使用'where userId=(select userId from deleted)endcreatetablecard(cardId varchar(20)primarykey,/*卡号,主键*/userId varchar(10)notnull,/*用户账号,外键,参照users表的userId*/cardPassword varchar(10)notnull,/*卡密码*/cardStatus varchar(5)check (cardStatus in('使用','冻结','挂失'))default'使用',/*卡状态(使用,冻结,挂失),默认是使用*/--cardMoney numeric(10,2) check(cardMoney >=0),foreignkey (userId)references users(userId)ondeletecascade/*当删除用户帐号时,他的卡号会及联删除*/)--管理员表createtableadmin(adminId varchar(10)notnull primarykey,/*操作员号码,主键*/adminName varchar(10)notnull,/*操作员名字*/adminPassword varchar(20)notnull,/*操作员密码*/BankAddress varchar(20)notnull/*操作员所在银行地址*/)insertintoadminvalues('001','张财主','123','工商银行新罗分行')--创建一个ATM表,至少应该含有编号以及ATM机里的总金额createtable ATM(ATMId varchar(10)primarykey,/*ATM机ID*/ATMMoney numeric(20,2)check (ATMMoney>=0),/*ATM机里的总钱数,不允许用户的取款数大于它的总钱数,所以它的总钱数不能小于*/ATMAddress varchar(20)/*ATM机的地点*/)insertinto ATM values('000', 10000,'新罗区')insertinto ATM values('111', 50000,'新罗区')--用户ATM机存取款信息表createtable ATMOutIn(ATMId varchar(10),/*取款机号,外键,参照ATM表的ATMId*/cardId varchar(20)notnull,/*用户卡号,外键,参照card表的cardId*/ATMTime DateTime,/*在ATM机存取款时间(应该是进行存取款时的系统时间*/ATMCunQu numeric(10,2),/*ATM机存款金额*/ATMSummary varchar(30),/*存取款摘要*/balanceMoney numeric(10,2)default 0,/*经过操作后账号中的金额*/foreignkey(ATMId)references ATM(ATMId)ondeletecascade,foreignkey(cardId)referencescard(cardId)ondeletecascade)--创建一个触发器,当产生这一信息时,账号上的钱也会随之改动createtrigger ATMOutIn_inserton ATMOutInafterinsertasdeclare@num_rows intselect@num_rows=@@rowcountif@num_rows= 0 /*未插入成功*/returnif@num_rows>0 /*数据插入成功*/beginupdate users set userMoney=userMoney+(select ATMCunQu from Inserted)where userId in(select u serId fromcard c,insertedi where c.cardId=i.cardId)update ATM set ATMMoney=ATMMoney+(select ATMCunQu from Inserted)where ATMId in(select ATMId f rom inserted)/*对应的atm机的总金额也会随之改变*/declare@balanceMoney numeric(10,2)/*账号余额*/select@balanceMoney=(select userMoney from users where userId in(select userId fromcard c,in sertedi where c.cardId=i.cardId))update ATMOutIn set balanceMoney=(@balanceMoney)where cardId in(select cardId from inserted )and atmtime in(select atmtime from inserted)/*完成了账号金额的修改,再将新的金额插入到信息表中,就是剩余的总余额了(注意修改的只是一个账号此次的操作*/end--用户银行存取款信息信息表createtable BankOutIn(adminId varchar(10)notnull,/*操作员号码,外键,参照操作员表的adminId*/cardId varchar(20)notnull,/*用户卡号,外键,参照用户信息表*/BankTime DateTime,/*银行存款时间*/BankCunQu numeric(10,2),/*银行存款*/BankSummary varchar(30),balanceMoney numeric(10,2)default 0,/*经过操作后账号中的金额*/foreignkey (adminId)referencesadmin(adminId)ondeletecascade,foreignkey (cardId)referencescard(cardId)ondeletecascade)--创建一个触发器,当插入这条数据时会自动修改users表里的金额信息createtrigger BankOutIn_inserton BankOutInforinsertasdeclare@num_rows intselect@num_rows=@@rowcountif@num_rows= 0 /*未插入成功*/returnif@num_rows>0 /*数据插入成功*/beginupdate users set userMoney=userMoney+(select BankCunQu from Inserted)where erId=(s elect userId fromcard c,insertedi where c.cardId=i.cardId)declare@balanceMoney numeric(10,2)select@balanceMoney=(select userMoney from users where userId=(select userId fromcard c,ins ertedi where c.cardId=i.cardId))update BankOutIn set balanceMoney=(@balanceMoney)where cardId=(select cardId from inserted )and banktime=(select banktime from inserted)/*完成了账号金额的修改,再将新的金额插入到信息表中,就是剩余的总余额了(要注意这个信息总额的唯一性)*/end--总信息可以用其它的表推出,建一个视图,一个虚表,来综合他们的信息createview allInfo(userId,cunquTime,cunquAddress,cunquMoney,cunquSummary,balanceMone y)asselect userId,bankTime,BankAddress,bankCunqu,bankSummary,balanceMoneyfrom bankoutinb,admin a,card cwhere b.adminId=a.adminId and c.cardId=b.cardIdunionselect userId,ATMTime,ATMAddress,ATMCunqu,ATMSummary,balanceMoneyfrom atmoutina,card c,ATMatmwhere c.cardId=a.cardId and a.atmid=atm.atmid程序源码:DBConnection.javapackage com.connection;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;/*** 定义一个数据库的连接及关闭资源的类* @author Administrator**/public class DBConnection {/*** 创建数据库的链接* @return 返回一个数据库的链接*/public static Connection getConnection(){Connection conn = null;try {Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); //加载数据库驱动String url = "jdbc:microsoft:sqlserver://localhost:1433;databaseName=account";String username = "sa"; //数据库用户名String password = "123456"; //数据库密码conn = DriverManager.getConnection(url,username,password); //获得数据库的链接} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return conn;}/*** 关闭数据库资源* @param obj 数据库打开的资源对象(在此处用Object,因为链接数据库是会打开多个资源)*/public static void closeObject(Object obj){if(obj != null){if(obj instanceof ResultSet){try {((ResultSet) obj).close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if(obj instanceof PreparedStatement){try {((PreparedStatement) obj).close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if(obj instanceof Connection){try {((Connection) obj).close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}}AdminDao.javapackage com.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import com.connection.DBConnection;import com.dto.Admin;/*** 处理管理员操作的类(将管理员的操作封装与此)* @author Administrator**/public class AdminDao {Connection conn = null;PreparedStatement ps = null;ResultSet rs = null;/*** 验证管理员的身份和密码* @param adminName* @param adminPassword* @return*/public boolean loginCheck(String adminName,String adminPassword){ boolean flag = false;String sql = "select adminPassword from admin where adminName = ? ";//根据传过来的用户名搜索密码,这样能够减少数据库的负担conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);ps.setString(1, adminName);rs = ps.executeQuery();if(rs.next()){if(adminPassword.equals(rs.getString(1))){flag = true;}}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{//关闭数据库的链接DBConnection.closeObject(rs);DBConnection.closeObject(ps);DBConnection.closeObject(conn);}return flag;}/*** 通过管理员登录名,获取管理员的信息* @param adminName* @return*/public Admin getAdminByName(String adminName){Admin admin = new Admin();String sql = "select * from admin where adminName = ?";conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);ps.setString(1, adminName);rs = ps.executeQuery();if(rs.next()){//从数据库中获取信息,并付给admin对象admin.setAdminId(rs.getString(1));admin.setAdminName(rs.getString(2));admin.setAdminPassword(rs.getString(3));admin.setBankAddress(rs.getString(4));}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return admin;}}AllInfoDao.javapackage com.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import com.connection.DBConnection;import com.dto.AllInfo;/*** 对视图操作的方法进行封装* @author Administrator**/public class AllInfoDao {Connection conn = null;PreparedStatement ps = null;/*** 根据传递过来的用户账号以及次数显示用户的操作信息* @param numbers 操作次数* @param userId 用户账号* @return 一系列的用户操作*/public List <AllInfo> getCaoZuoByUserId(String numbers,String userId){ ResultSet rs = null;List <AllInfo> list = new ArrayList<AllInfo>();//String sql = "select top ? * from bankoutin where userId = ? order by banktime desc";if("".equals(numbers)||null==numbers){String sql = "select * from allInfo where userId =? order by cunquTime desc";conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);ps.setString(1, userId);rs = ps.executeQuery();while (rs.next()){AllInfo info = new AllInfo();info.setUserId(rs.getString(1));info.setCunquTime(rs.getDate(2));info.setCunquAddress(rs.getString(3));info.setCunquMoney(rs.getDouble(4));info.setCunquSummary(rs.getString(5));info.setBalanceMoney(rs.getDouble(6));list.add(info);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(rs);DBConnection.closeObject(ps);DBConnection.closeObject(conn);}}else{int times = Integer.parseInt(numbers);StringBuffer stb = new StringBuffer();stb.append("select top ");stb.append(times);stb.append(" * from allInfo where userId = ");stb.append(userId);stb.append(" order by cunquTime desc");String sql = stb.toString();conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);rs = ps.executeQuery();while (rs.next()){AllInfo info = new AllInfo();info.setUserId(rs.getString(1));info.setCunquTime(rs.getDate(2));info.setCunquAddress(rs.getString(3));info.setCunquMoney(rs.getDouble(4));info.setCunquSummary(rs.getString(5));info.setBalanceMoney(rs.getDouble(6));list.add(info);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(rs);DBConnection.closeObject(ps);DBConnection.closeObject(conn);}}return list;}}ATMDao.javapackage com.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import com.connection.DBConnection;import com.dto.ATM;/*** 处理ATM机的相关操作* @author Administrator**/public class ATMDao {Connection conn = null;PreparedStatement ps = null;/*** 通过ATMId号获取ATM里的余额* @param ATMId 传递过来的ATMId* @return ATM机的余额*/public double getATMMoneyById(String ATMId){ResultSet rs = null;double ATMMoney = 0;String sql = "select ATMMoney from atm where ATMId = ?";conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);ps.setString(1, ATMId);rs = ps.executeQuery();if(rs.next()){ATMMoney = rs.getDouble(1); //获取ATM机里的余额}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return ATMMoney;}/*** 通过atm机号获取atm机的信息* @param atmId atm机号* @return*/public List<ATM> getATMInfoByATMId(String atmId){List <ATM> list = new ArrayList<ATM>();ResultSet rs = null;StringBuffer stb = new StringBuffer("select * from atm where atmId like '%");stb.append(atmId);stb.append("%'");String sql = stb.toString();conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);rs = ps.executeQuery();while(rs.next()){ATM atm = new ATM();atm.setATMId(rs.getString(1));atm.setATMMoney(rs.getDouble(2));atm.setATMAddress(rs.getString(3));list.add(atm);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return list;}}ATMOutInDao.javapackage com.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import com.connection.DBConnection;import com.dto.ATMOutIn;/*** 取款机存储信息表处理* @author Administrator**/public class ATMOutInDao {Connection conn = null;PreparedStatement ps = null;//当在ATM机上进行存取款操作时,就会自动生成一条存取款信息public boolean ATMOutInInfo(ATMOutIn atmoutin){boolean flag = false;String sql = "insert into ATMOutIn values(?,?,getDate(),?,?,default)";conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);ps.setString(1, atmoutin.getATMId());ps.setString(2, atmoutin.getCardId());ps.setDouble(3, atmoutin.getATMCunQu());ps.setString(4, atmoutin.getATMSummary());int count = ps.executeUpdate();if(count>0){flag = true; //证明数据插入成功}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(ps);DBConnection.closeObject(conn);}return flag;}/*** 根据传递过来的额数据,显示该ATM机近期的操作数* @param numbers 需要显示的数量* @param userId 需要显示的用户id号* @return 一系列的操作数据*/public List <ATMOutIn> getCaoZuoByATMId(String times,String atmId){ ResultSet rs = null;List <ATMOutIn> list = new ArrayList<ATMOutIn>();ATMOutIn aoi = new ATMOutIn();//String sql = "select top ? * from bankoutin where userId = ? order by banktime desc";if("".equals(times)){String sql = "select * from atmoutin where atmid = ? order by atmtime desc";conn = DBConnection.getConnection();try{ps = conn.prepareStatement(sql);ps.setString(1, atmId);rs = ps.executeQuery();while(rs.next()){aoi.setATMId(rs.getString(1));aoi.setCardId(rs.getString(2));aoi.setATMTime(rs.getDate(3));aoi.setATMCunQu(rs.getDouble(4));aoi.setATMSummary(rs.getString(5));aoi.setBalanceMoney(rs.getDouble(6));list.add(aoi);}}catch(Exception e){e.printStackTrace();}finally{DBConnection.closeObject(rs);DBConnection.closeObject(ps);DBConnection.closeObject(conn);}}else{int numbers = Integer.parseInt(times);StringBuffer stb = new StringBuffer();stb.append("select top ");stb.append(numbers);stb.append(" * from atmoutin where atmid = ");stb.append(atmId);stb.append(" order by atmtime desc");String sql = stb.toString();conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);//ps.setInt(1, numbers);//ps.setString(2, userId);rs = ps.executeQuery();while (rs.next()){aoi.setATMId(rs.getString(1));aoi.setCardId(rs.getString(2));aoi.setATMTime(rs.getDate(3));aoi.setATMCunQu(rs.getDouble(4));aoi.setATMSummary(rs.getString(5));aoi.setBalanceMoney(rs.getDouble(6));list.add(aoi);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(rs);DBConnection.closeObject(ps);DBConnection.closeObject(conn);}}return list;}/*** 根据卡号返回该卡的操作* @param cardId 卡号* @return*/public List<ATMOutIn> getCaozuoByCardId(String times,String cardId){ ResultSet rs = null;List<ATMOutIn> list = new ArrayList<ATMOutIn>();conn = DBConnection.getConnection();if("".equals(times)){ //获取所有操作String sql = "select * from ATMOutIn where cardId = ?";try {ps = conn.prepareStatement(sql);ps.setString(1, cardId);rs = ps.executeQuery();while(rs.next()){ATMOutIn atmoutin = new ATMOutIn();atmoutin.setATMId(rs.getString(1));atmoutin.setCardId(rs.getString(2));atmoutin.setATMTime(rs.getDate(3));atmoutin.setATMCunQu(rs.getDouble(4));atmoutin.setATMSummary(rs.getString(5));atmoutin.setBalanceMoney(rs.getDouble(6));list.add(atmoutin);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(ps);DBConnection.closeObject(conn);}}else{int numbers = Integer.parseInt(times);StringBuffer stb = new StringBuffer();stb.append("select top ");stb.append(numbers);stb.append(" * from atmoutin where cardId = ");stb.append(cardId);stb.append(" order by atmtime desc");String sql = stb.toString();try {ps = conn.prepareStatement(sql);rs = ps.executeQuery();while(rs.next()){ATMOutIn atmoutin = new ATMOutIn();atmoutin.setATMId(rs.getString(1));atmoutin.setCardId(rs.getString(2));atmoutin.setATMTime(rs.getDate(3));atmoutin.setATMCunQu(rs.getDouble(4));atmoutin.setATMSummary(rs.getString(5));atmoutin.setBalanceMoney(rs.getDouble(6));list.add(atmoutin);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(rs);DBConnection.closeObject(ps);DBConnection.closeObject(conn);}}return list;}/*** 根据传递过来的信息,查询ATM的操作* @param year 年份* @param month 月份* @param day 日期* @param ATMId atm号* @return*/public List <ATMOutIn> getCaoZuoByATMId(String year,String month,String day,String ATMId){ResultSet rs = null;List <ATMOutIn> list = new ArrayList<ATMOutIn>();StringBuffer stb = new StringBuffer();stb.append("select * from atmoutin where atmId like '%");stb.append(ATMId);stb.append("%' and CONVERT(varchar(20),atmtime,120) like '%");stb.append(year);stb.append("-"+month);stb.append("-"+day);stb.append("%'");stb.append(" order by atmtime desc");String sql = stb.toString();System.out.println(sql);conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);rs = ps.executeQuery();while (rs.next()){ATMOutIn aoi = new ATMOutIn();aoi.setATMId(rs.getString(1));aoi.setCardId(rs.getString(2));aoi.setATMTime(rs.getDate(3));aoi.setATMCunQu(rs.getDouble(4));aoi.setATMSummary(rs.getString(5));aoi.setBalanceMoney(rs.getDouble(6));list.add(aoi);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(rs);DBConnection.closeObject(ps);DBConnection.closeObject(conn);}return list;}}BankOutInDao.javapackage com.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import com.connection.DBConnection;import com.dto.BankOutIn;/*** 用户银行存取款信息处理* @author Administrator**/public class BankOutInDao {Connection conn = null;PreparedStatement ps = null;//当在银行上进行存取款操作时,就会自动生成一条存取款信息public boolean BankOutInInfo(BankOutIn bankoutin){boolean flag = false;String sql = "insert into BankOutIn values(?,?,getDate(),?,?,default)";conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);ps.setString(1, bankoutin.getAdminId());ps.setString(2, bankoutin.getCardId());ps.setDouble(3, bankoutin.getBankCunQu());ps.setString(4, bankoutin.getBankSummary());//System.out.println(bankoutin.getAdminId()+""+bankoutin.getcardId()+" "+bankoutin.getBankCunQu()+" "+bankoutin.getBankSummary());int count = ps.executeUpdate();if(count>0){flag = true; //证明数据插入成功}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(ps);DBConnection.closeObject(conn);}return flag;}/*** 根据传递过来的时间,显示用户近期的操作数* @param numbers 需要显示的数量* @param userId 需要显示的用户id号* @return 一系列的操作数据*/public List <BankOutIn> getCaoZuoByUserId(String year,String month,String day,String userId){ResultSet rs = null;List <BankOutIn> list = new ArrayList<BankOutIn>();//String sql = "select top ? * from bankoutin where userId = ? order by banktime desc";StringBuffer stb = new StringBuffer();stb.append("select * from bankoutin where userId = ");stb.append(userId);//先构建好大体的框架,然后开始写模糊查询的语句//////////////////////////////////////////////stb.append(" and CONVERT(varchar(20),banktime,120) like '%");stb.append(year);stb.append("-"+month);stb.append("-"+day);stb.append("%'");//////////////////////////////////////////////stb.append(" order by banktime desc");String sql = stb.toString();System.out.println(sql);conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);rs = ps.executeQuery();while (rs.next()){BankOutIn boi = new BankOutIn();boi.setAdminId(rs.getString(1));boi.setCardId(rs.getString(2));boi.setBankTime(rs.getDate(3));boi.setBankCunQu(rs.getDouble(4));boi.setBankSummary(rs.getString(5));boi.setBalanceMoney(rs.getDouble(6));list.add(boi);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(rs);DBConnection.closeObject(ps);DBConnection.closeObject(conn);}return list;}}CardDao.javapackage com.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import com.connection.DBConnection;import com.dto.Card;public class CardDao {Connection conn = null;PreparedStatement ps = null;ResultSet rs = null;/*** 使用银行卡登录检测* @param cardId 卡号* @param cardPassword 卡密码* @return*/public boolean cardLoginCheck(String cardId,String cardPassword){ boolean flag = false;conn = DBConnection.getConnection();String sql = "select cardPassword from card where cardId = ?";try {ps = conn.prepareStatement(sql);ps.setString(1,cardId);rs= ps.executeQuery();if(rs.next()){if(rs.getString(1).equals(cardPassword)){flag = true;}}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return flag;}/*** 根据银行卡号,判断银行是否存在* @param cardId* @return*/public boolean checkCardId(String cardId){boolean flag = false;String sql = "select cardId from card where cardId = ?";conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);ps.setString(1, cardId);rs = ps.executeQuery();if(rs.next()){ //如果存在,返回真flag = true;}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(rs);DBConnection.closeObject(ps);DBConnection.closeObject(conn);}return flag;}/*** 办卡的方法* @param card 带有卡信息的card对象* @return 一个boolean型的值,判断卡是否添加成功*/public boolean addCard(Card card){boolean flag = false;String sql = "insert into card values(?,?,?,DEFAULT)";conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);ps.setString(1, card.getCardId());ps.setString(2, card.getUserId());ps.setString(3, card.getCardPassword());int count = ps.executeUpdate(); //用一个常量标记,看是否插入数据成功if(count>0){ //插入数据成功flag = true;}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(rs);DBConnection.closeObject(ps);DBConnection.closeObject(conn);}return flag;}/*** 根据卡号获取卡信息* @param cardId 传递过来的卡号* @return 一个含有改卡号对应卡的信息*/public Card queryOne(String cardId){Card card = new Card();conn = DBConnection.getConnection();String sql = "select * from card where cardId = ?";try {ps = conn.prepareStatement(sql);ps.setString(1, cardId);rs = ps.executeQuery();if(rs.next()){card.setCardId(rs.getString(1));card.setUserId(rs.getString(2));card.setCardPassword(rs.getString(3));card.setCardStatus(rs.getString(4));}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(rs);DBConnection.closeObject(ps);DBConnection.closeObject(conn);}return card;}/*** 根据银行卡号获取账户金额* @param cardId 银行账号* @return 账户金额*/public double getUserMoneyByCardId (String cardId){double userMoney = 0;String sql = "select userMoney from users where userId = (select userId from card where cardId = ?)";conn = DBConnection.getConnection();try {ps = conn.prepareStatement(sql);ps.setString(1, cardId);rs = ps.executeQuery();while(rs.next()){userMoney = rs.getDouble(1);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return userMoney;}/*** 通过用户账号获取银行卡信息(可能一个人有多张卡,所以要用一个List)* @param userId 用户账号* @return 卡信息*/public List<Card> getCardByUserId(String userId){List<Card> list = new ArrayList<Card>();conn = DBConnection.getConnection();String sql = "select * from card where userId = ?";try {ps = conn.prepareStatement(sql);ps.setString(1,userId);rs = ps.executeQuery();while(rs.next()){Card card = new Card();card.setCardId(rs.getString(1));card.setUserId(rs.getString(2));card.setCardPassword(rs.getString(3));card.setCardStatus(rs.getString(4));list.add(card);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBConnection.closeObject(rs);DBConnection.closeObject(ps);DBConnection.closeObject(conn);}return list;}/*** 修改银行卡的密码和状态* @param cardId 需要修改的银行卡号* @param password 密码* @param status 状态* @return 一个表示是否修改的值*/public boolean updateCardInfo(String cardId,String password,String status){ boolean flag = false;StringBuffer stb = new StringBuffer();stb.append("update card set cardpassword = '");stb.append(password);stb.append("',cardstatus = '");stb.append(status); //必须要用这种写法,因为汉字的话,需要用引号stb.append("' where cardId = ");stb.append(cardId);//String sql = "update card set cardpassword = ?,cardstatus = ? where cardId =?";String sql = stb.toString();System.out.println(sql);conn =DBConnection.getConnection();try {ps = conn.prepareStatement(sql);//ps.setString(1, password);//ps.setString(2, status);。
源程序清单
目录1引言 (1)1.1标题 (1)1.2模块开发情况表 (1)2模块1(标识符) (3)2.1功能说明 (3)2.2原代码清单(标识符) (3)2.2.1子模块(Server) (3)2.2.2子模块(Login) (11)2.2.3子模块(MainWindow ) (14)3.模块2(标识符) (23)3.1功能说明 (23)3.2原代码清单 (23)3.2.1子模块1(TransInforR) (23)3.2.2子模块2(SelectFriends) (28)3.2.3子模块3(AddFriends) (31)4模块3(标识符) (35)4.1功能说明 (35)4.2原代码清单(标识符) (35)4.2.1子模块1(ChangeInfo) (35)4.2.2子模块2(ChangePwd) (40)4.2.3子模块3(Enrol) (43)4.2.4子模块4(AddUserid) (47)5号宋体(西文times new roman)1.5倍行距1引言1.1标题软件系统名称和标识符模块名称和标识符(如果本卷宗包含多于一个的模块,则用这组模块的功能标识代替模块名)1.2模块开发情况表扼要说明本模块(或本组模块)的功能,主要是输入、要求的处理、输出。
可以从系统设计说明书中摘录。
(自制表格,说明模块名称和标识符、程序编制员签名、修改完成日期)注意所有新章换页。
图的要求如下:图1-1 ××××××××图名居中,位于图下方,两级标号:章节号-序列号。
每章序号升序排列。
表的要求如下:表1-1 ××××××××表名居中,位于表上方,两级标号:章节号-序列号。
每章序号升序排列。
非异性表格的一律使用三线表。
如表格换页请拆分表格后加续表表头。
全文关于图表的要求同上。
三.源程序清单
三.源程序清单import java.util.*;import java.io.*;import javax.swing.*;import java.awt.event.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import javax.swing.tree.*;import javax.swing.event.*;class MyFrame extends Frame implements ActionListener{Label lab1,lab2; //首先对用户登录框对进行设计TextField text1,text2;Button button;MyFrame(String s){super(s);setSize(400,120);setVisible(true);setForeground(Color.blue);setBackground(Color.pink);setLayout(new GridLayout(3,2,8,8));lab1=new Label("用户名");lab2=new Label("密码");text1=new TextField(10);text2=new TextField(10);button=new Button("登录");add(lab1);add(text1);add(lab2);add(text2);add(button);button.addActionListener(this);}public void actionPerformed(ActionEvent e){ if(e.getSource()==button){ button.setLabel("登录成功"); //用户名和密码正确后显示登陆成功 Mytree fr=new Mytree();fr.validate();}}}class Mytree extends JFrame implements TreeSelectionListener{JTree tree=null;JPanel text=new JPanel() ;JSplitPane splitPane;Mytree(){Container con=getContentPane();DefaultMutableTreeNode root=new DefaultMutableTreeNode("图书管理系统" );DefaultMutableTreeNode t1=new DefaultMutableTreeNode("显示所有图书 ");DefaultMutableTreeNode t3=new DefaultMutableTreeNode("添加");DefaultMutableTreeNode t2=new DefaultMutableTreeNode("查询 ");root.add(t2); root.add(t3);root.add(t1);tree=new JTree(root);JScrollPane scrollPane=new JScrollPane(text) ;splitPane=new JSplitPane (JSplitPane.HORIZONTAL_SPLIT,true,tree,text);splitPane=new JSplitPane (JSplitPane.HORIZONTAL_SPLIT,true);splitPane.add(tree,0);tree.addTreeSelectionListener(this);con.add(splitPane);addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});setVisible(true);setBounds(100,100,500,500);}public void valueChanged(TreeSelectionEvent e){if(e.getSource()==tree){DefaultMutableTreeNode node=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent();if( node.getUserObject().toString().equals("添加")){show fr=new show( );text.add(fr);splitPane.add(text);}else if( node.getUserObject().toString().equals("查询")){ MyFrame1 my1=new MyFrame1();text.add(my1);splitPane.add(text);}else if( node.getUserObject().toString().equals("显示所有图书")){ MyFrame2 my2=new MyFrame2();text.add(my2); splitPane.add(text);}}}}class tianjia //定义一个“添加图书”的类{ String 书名,作者,出版社,内容简介;tianjia(String 书名, String 作者, String 出版社, String 内容简介){this.书名=书名;this.作者=作者;this.出版社 =出版社 ;this.内容简介=内容简介;}}class show extends Panel implements ActionListener{LinkedList 书单=null;JTextField 书名文本框=new JTextField();JTextField 作者文本框=new JTextField();JTextField 出版社文本框=new JTextField();JTextField 内容简介文本框=new JTextField(); JButton badd=new JButton("添加图书");show(){书单=new LinkedList();setLayout(new GridLayout(5,2));setSize(300,300);add(new Label("输入书名:"));add(书名文本框);add(new Label("输入作者:"));add(作者文本框);add(new Label("输入出版社:"));add(出版社文本框);add(new Label("输入内容简介:"));add(内容简介文本框);add(new Label("点击添加"));add(badd);badd.addActionListener(this) ;setBackground(Color.pink);setBackground(Color.pink);}public void actionPerformed(ActionEvent e){ if(e.getSource()==badd){String shuming=null; String zuozhe=null;String chubanshe=null; String neirongjianjie=null;shuming=书名文本框.getText();zuozhe=作者文本框.getText();chubanshe=出版社文本框.getText();neirongjianjie=内容简介文本框.getText();tianjia tj=new tianjia(shuming,zuozhe,chubanshe,neirongjianjie);书单.add(tj);try{FileOutputStream file=new FileOutputStream("shudan.txt");ObjectOutputStream out=new ObjectOutputStream(file);out.writeObject(书单);out.close();}catch(IOException event){System.out.print("找不到书单"); }}}}class chaxun //定义查询的类{String 书名,作者,出版社,内容简介;chaxun(String 书名, String 作者, String 出版社, String 内容简介){this.书名=书名;this.作者=作者;this.出版社 =出版社 ;this.内容简介=内容简介;}}class MyFrame1 extends Panel implements ActionListener{ Button button ;TextArea text;TextField t;Label lab1,lab2,lab3;LinkedList l=null;MyFrame1(){l=new LinkedList();lab1=new Label("请输入要查询的书名");lab2=new Label("点击查询");lab3=new Label("查询结果");button=new Button("查询");text=new TextArea(20,20); //查询框的设置t=new TextField(10);setLayout(new FlowLayout() );setBackground(Color.pink);setBackground(Color.pink);add(lab1);add(t);add(lab2);add(button);add(lab3);add(text);button.addActionListener(this);setSize(300,300);setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==button){String sh=t.getText();try { FileInputStream comein=new FileInputStream("shudan.txt");ObjectInputStream in=new ObjectInputStream(comein);l=(LinkedList)in.readObject();in.close();}catch(ClassNotFoundException event){ }catch(IOException event){System.out.print("找不到书单"); }for(int i=0;i<l.size();i++){chaxun c=(chaxun)l.get(i);if(c.书名.equals(sh)){text.append("书名"+c.书名+" ");text.append("作者 "+c.作者 +" ");text.append("出版社 "+c.出版社 +" ");text.append("内容简介 "+c.内容简介 +" ");text.append("\n");text.setBackground(Color.cyan);}}}else{text.append("找不到"); }}}class tianjia1{String 书名,作者,出版社,内容简介;tianjia1(String 书名, String 作者, String 出版社, String 内容简介){this.书名=书名;this.作者=作者;this.出版社 =出版社 ;this.内容简介=内容简介;}}class MyFrame2 extends Panel implements ActionListener{ LinkedList 书单= null;TextArea text ;Button button;MyFrame2( ){ LinkedList 书单=new LinkedList();text=new TextArea(20,20);button=new Button("查询");setLayout(new FlowLayout() );add(text); add(button);button.addActionListener(this);setSize(400,120);setVisible(true);setForeground(Color.blue); setBackground(Color.pink);}public void actionPerformed(ActionEvent e){ if(e.getSource()==button){ try { FileInputStream comein=new FileInputStream("shudan.txt");ObjectInputStream in=new ObjectInputStream(comein);书单=(LinkedList)in.readObject();}catch(ClassNotFoundException event){ }catch(IOException event){System.out.print("找不到书单"); }Iterator iter= 书单.listIterator();while (iter.hasNext()){tianjia tj=(tianjia)iter.next();text.append("书名"+tj.书名+" ");text.append("作者 "+tj.作者 +" ");text.append("出版社 "+tj.出版社 +" ");text.append("内容简介 "+tj.内容简介 +" ");text.append("\n");}}}}public class a{public static void main(String args[]){ MyFrame f=new MyFrame("欢迎登录图书管理系统");f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});f.validate();}}。
源程序清单
***********************************功能4,DA转换***********************************
FUN4: ;功能4,DA转换
015A D201 SETB FUN4_F ;置功能4标志位为
015C 900100 MOV DPTR,#0100H ;DA地址0100H
课程设计源程序清单
课程名称:微机原理与接口技术
题目:B型单片机系统的设计
学院:机电工程学院系:机械系
专业:机械设计制造及其自动化
班级:
学号:
学生姓名:
起讫日期:
指导教师:
系分管主任:
审核日期:
***************************************赋值****************************************
00AA 20941A OUT0: JB P1.4,OUT1 ;判断键0
00AD 5153 ACALL DELAY
00AF 2094F8 JB P1.4,OUT0
00B2 D290 SETB P1.0
00B4 D28E SETB TR1
00B6 753E00 MOV KEY_NUM,#0
00B9 5135 ACALL DIS_INT
0036 758912 MOV TMOD,#00010010B;设置定时中断的工作模式,定时器0为方式2,定时器1为方式1
0039 758A9C MOV TL0,#9CH;设置定时器0初值,定时100us
003C 758C9C MOV TH0,#9CH
003F 758BB0MOV TL1,#0B0H;设置定时器1初值,定时50ms
源程序清单-样板
#include <linux/config.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/poll.h>
#include <linux/init.h>
#include <linux/smp_lock.h>
if (atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2]) {
tcp_enter_memory_pressure();
goto suppress_allocation;
}
/* Under pressure. */
if (atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[1])
{
struct sock *sk = skb->sk;
atomic_sub(skb->truesize, &sk->rmem_alloc);
sk->forward_alloc += skb->truesize;
}
/*
* LISTEN is a special case for poll..
*/
static __inline__ unsigned int tcp_listen_poll(struct sock *sk, poll_table *wait)
atomic_t tcp_sockets_allocated; /* Current number of TCP sockets. */
计算机二级C++程序题及答案解析
计算机二级C++程序题及答案解析计算机二级C++程序题及答案解析为了使广大考生在备战计算机等级考试时,更快的掌握相应知识点,下面是店铺搜索整理的计算机二级C++程序题及答案解析,供参考练习,预祝考生们考出自己理想的成绩!计算机二级C++程序题及答案解析一、改错题使用VC6打开考生文件夹下的工程kt7_1,此工程包含一个源程序文件kt7_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:Constructor1Constructor1Constructor1DestructorConstructor2Destructorx=0x=5DestructorDestructor源程序文件kt21_1.cpp清单如下:#includeclassB{intx;public:B(){x=0;cout<<"Constructor1"<<endl;}< p="">B(inti){x=i;cout<<"Constructor2"<<endl;}< p="">~B(){cout<<"Destructor"<<endl;}< p="">/**********found**********/~B(inti){cout<<i<<"bedestructor"<<endl;}< p="">voidprint(){cout<<"x="<<x<<endl;}};< p="">voidmain(){B*ptr;ptr=newB[2];/**********found**********/ptr[0]=B(0);ptr[1]=B(5);/**********found**********/for(inti=0;i<2;)ptr[i].print();[]ptr;}【参考答案】(1)将~B(int i){cout<<i<<" p="" destructor?<<endl;}删除<="" be="">(2)将ptr[0]=B(0);改为:ptr[0]=B();(3)将for (int i=0;i<2;)改为:for(int i=0;i<2;i++)B(inti){x=i;cout<<"Constructor2"<<endl;}< p="">~B(){cout<<"Destructor"<<endl;}< p="">/**********found**********/~B(inti){cout<<i<<"bedestructor"<<endl;}< p="">voidprint(){cout<<"x="<<x<<endl;}};< p="">voidmain(){B*ptr;ptr=newB[2];/**********found**********/ptr[0]=B(0);ptr[1]=B(5);/**********found**********/for(inti=0;i<2;)ptr[i].print();[]ptr;}【参考答案】(1)将~B(int i){cout<<i<<" p="" destructor?<<endl;}删除<="" be="">(2)将ptr[0]=B(0);改为:ptr[0]=B();(3)将for (int i=0;i<2;)改为:for(int i=0;i<2;i++)【试题解析】本题主要考查对文件相关操作的熟练程度。
源代码清单
附录:主要窗体的源代码:1:订房信息窗体的源代码:Option Explicit'是否改动过记录,ture为改过Dim mblChange As BooleanDim mrc AsPublic txtSQL As StringPrivate Sub cboItem_Change(Index As Integer)'有变化设置gblchangemblChange = TrueEnd SubPrivate Sub cboItem_Click(Index As Integer)Dim mrcc AsDim intCount As IntegerDim MsgText As StringIf gintBmode = 1 ThenIf Index = 0 ThentxtSQL = "select * from rooms where roomNO = '" & Trim(cboItem(0)) & "' and putup <> '是'"Set mrcc = ExecuteSQL(txtSQL, MsgText)For intCount = 1 To 3cboItem(intCount).ClearcboItem(intCount).AddItem (intCount)cboItem(intCount).ListIndex = 0Next intCounttxtItem(5) = (5)End IfEnd IfEnd SubPrivate Sub cboItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)EnterToTab KeyCodeEnd SubPrivate Sub cmdExit_Click()If mblChange And ThenIf MsgBox("保存当前记录的变化吗", vbOKCancel + vbExclamation, "警告") = vbOK Then'保存Call cmdSave_ClickEnd IfEnd IfUnload MeEnd SubPrivate Sub cmdSave_Click()Dim intCount As IntegerDim sMeg As StringDim mrcc AsDim MsgText As StringFor intCount = 0 To 3If Trim(txtItem(intCount) & " ") = "" ThenSelect Case intCountCase 0sMeg = "顾客姓名"Case 1sMeg = "身份证号码"Case 2sMeg = "折扣"Case 3sMeg = "入住时间"End SelectsMeg = sMeg & "不能为空!"MsgBox sMeg, vbOKOnly + vbExclamation, "警告"txtItem(intCount).SetFocusExit SubEnd IfNext intCountFor intCount = 0 To 3If Trim(cboItem(intCount) & " ") = "" ThenSelect Case intCountCase 0sMeg = "客房编号"Case 1sMeg = "客房种类"Case 2sMeg = "客房位置"Case 3sMeg = "客房单价"End SelectsMeg = sMeg & "不能为空!"MsgBox sMeg, vbOKOnly + vbExclamation, "警告" cboItem(intCount).SetFocusExit SubEnd IfNext intCountIf IsDate(txtItem(2)) ThentxtItem(2) = Format(txtItem(2), "yyyy-mm-dd")ElseMsgBox "入库时间应输入日期(yyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"txtItem(2).SetFocusExit SubEnd IfFor intCount = 1 To 3 Step 2If Not IsNumeric(txtItem(intCount)) ThenMsgBox "请输入数字", vbOKOnly + vbExclamation, "警告"txtItem(intCount).SetFocusExit SubEnd IfNext intCountIf gintBmode = 2 ThentxtSQL = "delete from bookin where bookno = '" & Trim(txtNo) & "'"Set mrcc = ExecuteSQL(txtSQL, MsgText)End IftxtSQL = "select * from bookin"Set mrcc = ExecuteSQL(txtSQL, MsgText)(0) = txtNoFor intCount = 0 To 1(intCount + 1) = txtItem(intCount)Next intCount(3) = cboItem(0)For intCount = 2 To 4(intCount + 2) = txtItem(intCount)Next intCount(8) = 0txtSQL = "select * from rooms where roomNO = '" & Trim(cboItem(0)) & "'"Set mrcc = ExecuteSQL(txtSQL, MsgText)If Not Thenmrcc!putup = "y"End IfIf gintBmode = 1 ThenMsgBox "添加订房信息成功!", vbOKOnly + vbExclamation, "添加订房消息"Unload MeIf flagBedit ThenUnload frmBookinEnd If= "select bookno,customname,customID,roomno,indate,discount,inmemo from bookin where ammount = '0'"ElseMsgBox "修改订房信息成功!", vbOKOnly + vbExclamation, "修改订房消息"Unload MeIf flagBedit ThenUnload frmBookinEnd If= "select bookno,customname,customID,roomno,indate,discount,inmemo frombookin where ammount = '0'"End IfEnd SubPrivate Sub Form_Load()Dim sSql As StringDim intCount As IntegerDim MsgText As StringIf flagSedit ThenSet mrc = ExecuteSQL(txtSQL, MsgText)If Not ThenFor intCount = 0 To 3cboItem(intCount).AddItem (intCount) cboItem(intCount).ListIndex = 0Next intCounttxtItem(5) = (5)End IftxtNo = GetRkno()gintBmode = 1ElseIf gintBmode = 1 Then= & "添加"'初始化客房信息txtSQL = "select DISTINCT roomNO from rooms where putup <> 'y'"Set mrc = ExecuteSQL(txtSQL, MsgText)If Not ThenDo While NotcboItem(0).AddItem Trim(0))LoopElseMsgBox "请先进行客房登记!", vbOKOnly + vbExclamation, "警告"= FalseExit SubEnd IftxtNo = GetRknoElseIf gintBmode = 2 ThenSet mrc = ExecuteSQL(txtSQL, MsgText)If = False ThenWith mrctxtNo = !booknoFor intCount = 0 To 1If Not IsNull(.Fields(intCount + 1)) ThentxtItem(intCount)= .Fields(intCount + 1)End IfNext intCountcboItem(0).AddItem !roomnocboItem(0).ListIndex = 0For intCount = 2 To 4If Not IsNull(.Fields(intCount + 2)) ThentxtItem(intCount)= .Fields(intCount + 2)End IfNext intCountEnd WithEnd If= & "修改"txtSQL = "select * from rooms where roomNO = '" & Trim(cboItem(0)) & "'"Set mrc = ExecuteSQL(txtSQL, MsgText)If Not ThenFor intCount = 1 To 3cboItem(intCount).AddItem (intCount) cboItem(intCount).ListIndex = 0Next intCounttxtItem(5) = (5)End IfEnd IfEnd IfmblChange = FalseEnd SubPrivate Sub Form_Unload(Cancel As Integer)gintBmode = 0End SubPrivate Sub txtItem_Change(Index As Integer)'有变化设置gblchangemblChange = TrueEnd SubPrivate Sub txtItem_GotFocus(Index As Integer)txtItem(Index).SelStart = 0txtItem(Index).SelLength = Len(txtItem(Index))End SubPrivate Sub txtItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)EnterToTab KeyCodeEnd Sub2:订房信息查询窗体源代码:Option Explicit'用于传递查询块Private Sub chkItem_Click(Index As Integer)If Index = 2 ThencboYear(0).SetFocusElsetxtItem(Index).SetFocusEnd IfEnd SubPrivate Sub cmdExit_Click()End SubPrivate Sub cmdOK_Click()Dim dBeginDate As StringDim sQSql As StringIf chkItem(0).Value = vbChecked ThensQSql = " customname = '" & Trim(txtItem(0) & " ") & "'"End IfIf chkItem(1).Value = vbChecked ThenIf Trim(sQSql & " ") = "" ThensQSql = " roomno ='" & Trim(txtItem(1) & " ") & "'" ElsesQSql = sQSql & " and roomno ='" & Trim(txtItem(1) & " ") & "'"End IfEnd IfIf chkItem(2).Value = vbChecked ThendBeginDate = Format(CDate(cboYear(0) & "-" & cboMonth(0) & "-" & cboDay), "yyyy-mm-dd")If Trim(sQSql & " ") = "" ThensQSql = " indate ='" & dBeginDate & "'"ElsesQSql = sQSql & " and indate ='" & dBeginDate & "'" End IfEnd IfIf Trim(sQSql) = "" ThenMsgBox "请设置查询条件!", vbOKOnly + vbExclamation, "警告"Exit SubElseIf flagBedit ThenUnload frmBookinEnd If= "select bookno,customname,customID,roomno,indate,discount,inmemo from bookin where ammount = '0' and " & sQSqlEnd IfEnd SubPrivate Sub Form_Load()Dim i As IntegerDim j As IntegerDim sSql As StringDim txtSQL As StringDim MsgText As StringDim mrc AstxtSQL = "select distinct datepart(yy,indate) from bookin where ammount = '0' "Set mrc = ExecuteSQL(txtSQL, MsgText)If = False ThenWith mrcDo While Not .EOFcboYear(0).AddItem .Fields(0).MoveNextLoopEnd WithcboYear(0).ListIndex = 0For j = 1 To 12cboMonth(0).AddItem jNext jcboMonth(0).Text = Month(Now())For j = 1 To 31jNext j= Day(Now())Else= FalseEnd IfEnd SubPrivate Sub lblitem_Click(Index As Integer)chkItem(Index).Value = vbCheckedEnd SubPrivate Sub txtItem_GotFocus(Index As Integer)txtItem(Index).SelStart = 0txtItem(Index).SelLength = Len(txtItem(Index)) End Sub3:订房信息列表窗体源代码:Option ExplicitPublic txtSQL As StringDim mrc AsDim MsgText As StringPrivate Sub Form_Load()ShowTitleShowDataflagBedit = TrueEnd SubPrivate Sub Form_Resize()If <> vbMinimized And <> vbMinimized Then '边界处理If < 10 * ThenExit SubEnd IfIf < + / 2 ThenExit SubEnd If'控制控件的位置== - / 2= + + / 2= - 200= + 100= - - 200End IfEnd SubPublic Sub FormClose()Unload MeEnd Sub'删除记录Private Sub Form_Unload(Cancel As Integer) flagBedit = FalsegintBmode = 0End Sub'显示Grid的内容Private Sub ShowData()Dim j As IntegerDim i As IntegerSet mrc = ExecuteSQL(txtSQL, MsgText)With msgList.Rows = 1Do While Not.Rows = .Rows + 1For i = 1 To Select Case (i - 1).Type Case adDBDate.TextMatrix(.Rows - 1, i) = Format(i - 1) & "", "yyyy-mm-dd")Case Else.TextMatrix(.Rows - 1, i) = (i - 1) & "" End SelectNext iLoopEnd WithEnd Sub'显示Grid表头Private Sub ShowTitle()Dim i As IntegerWith msgList.Cols = 8.TextMatrix(0, 1) = "".TextMatrix(0, 2) = "顾客姓名" .TextMatrix(0, 3) = "身份证号码" .TextMatrix(0, 4) = "房间编号" .TextMatrix(0, 5) = "入住日期" .TextMatrix(0, 6) = "折扣".TextMatrix(0, 7) = "备注"'固定表头.FixedRows = 1'设置各列的对齐方式For i = 0 To 7.ColAlignment(i) = 0Next i'表头项居中.FillStyle = flexFillRepeat.Col = 0.Row = 0.RowSel = 1.ColSel = .Cols - 1.CellAlignment = 4'设置单元大小.ColWidth(0) = 300.ColWidth(1) = 0.ColWidth(2) = 1000.ColWidth(3) = 2000.ColWidth(4) = 2000.ColWidth(5) = 1000.ColWidth(6) = 1000.ColWidth(7) = 600.Row = 1End WithEnd SubPrivate Sub msgList_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)'右键弹出If Button = 2 And Shift = 0 ThenPopupMenuEnd IfEnd Sub4:结算信息窗体源代码:Option Explicit'是否改动过记录,ture为改过Dim mblChange As BooleanDim mrc AsPublic txtSQL As StringPrivate Sub cboItem_Change(Index As Integer) '有变化设置gblchangemblChange = TrueEnd SubPrivate Sub cboItem_Click(Index As Integer) Dim sSql As StringDim MsgText As StringDim mrcc AsDim intCount As IntegerIf gintCmode = 1 Then'初始化员工名称和IDIf Index = 0 ThencboItem(1).Enabled = TruecboItem(2).Enabled = TruecboItem(3).Enabled = TruecboItem(1).ClearcboItem(2).ClearcboItem(3).CleartxtSQL = "select roomNO,roomtype,roomposition,roomprice from rooms where roomNO ='" & Trim(cboItem(0)) & "'"Set mrcc = ExecuteSQL(txtSQL, MsgText)If Not ThencboItem(1).AddItem mrcc!roomtypecboItem(2).AddItem mrcc!roompositioncboItem(3).AddItem mrcc!roompricecboItem(1).Enabled = FalsecboItem(2).Enabled = FalsecboItem(3).Enabled = FalsecboItem(1).ListIndex = 0cboItem(2).ListIndex = 0cboItem(3).ListIndex = 0= TrueElseMsgBox "没有订房信息!", vbOKOnly + vbExclamation, "警告"= FalseExit SubEnd IftxtSQL = "select * from bookin where ammount = '0' and roomno = '" & Trim(cboItem(0)) & "'"Set mrcc = ExecuteSQL(txtSQL, MsgText)If Not ThentxtNo = mrcc!booknotxtItem(0) = mrcc!customnametxtItem(1) = mrcc!customIDtxtItem(2) = mrcc!indatetxtItem(3) = mrcc!discounttxtItem(5) = mrcc!inmemoFor intCount = 0 To 3txtItem(intCount).Enabled = FalseNext intCountEnd IfEnd IfEnd IfExit SubEnd SubPrivate Sub cboItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)EnterToTab KeyCodeEnd SubPrivate Sub cmdExit_Click()If mblChange And ThenIf MsgBox("保存当前记录的变化吗", vbOKCancel + vbExclamation, "警告") = vbOK ThenCall cmdSave_ClickEnd IfEnd IfUnload MeEnd SubPrivate Sub cmdSave_Click()Dim intCount As IntegerDim sMeg As StringDim mrcc AsDim MsgText As StringDim bYear As IntegerDim eYear As IntegerDim bDays As IntegerDim eDays As IntegerDim aDays As IntegerDim amMount As DoubleIf Trim(txtItem(4) & " ") = "" ThenMsgBox sMeg, vbOKOnly + vbExclamation, "警告" txtItem(4).SetFocusEnd IfIf IsDate(txtItem(4)) ThentxtItem(4) = Format(txtItem(4), "yyyy-mm-dd")ElseMsgBox "入库时间应输入日期(yyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"txtItem(4).SetFocusExit SubEnd If'再加入新记录txtSQL = "select * from bookin where bookno = '" & Trim(txtNo) & "'"Set mrcc = ExecuteSQL(txtSQL, MsgText)(6) = txtItem(5)(7) = txtItem(4)bYear = DatePart("yyyy", txtItem(2))eYear = DatePart("yyyy", txtItem(4))bDays = DatePart("y", txtItem(2))eDays = DatePart("y", txtItem(4))If bYear = eYear ThenaDays = eDays - bDaysElseaDays = (eYear - bYear - 1) * 365 + (365 - bDays) + eDays End If(8) = aDays * Trim(cboItem(3)) * Trim(txtItem(3)) / 100amMount = aDays * Trim(cboItem(3)) * Trim(txtItem(3)) / 100txtSQL = "select * from rooms where roomNO = '" & cboItem(0) & "'"Set mrcc = ExecuteSQL(txtSQL, MsgText)If Not Thenmrcc!putup = " "End IfIf gintCmode = 1 ThenUnload MemblChange = FalseMsgBox "金额为" & amMount & "元,结算完毕!", vbOKOnly +vbExclamation, "添加结算信息"If flagCedit ThenUnload frmCheckoutEnd If= "select * from bookin where ammount <> '0'"ElseIf gintCmode = 2 ThenMsgBox "金额为" & amMount & "元,结算信息修改完毕!", vbOKOnly + vbExclamation, "修改结算信息"Unload MeIf flagCedit ThenUnload frmCheckoutEnd If= "select * from bookin where ammount <> '0'"End IfEnd SubPrivate Sub Form_Load()Dim sSql As StringDim intCount As IntegerDim MsgText As StringIf gintCmode = 1 Then= & "添加"'初始化物资名称txtSQL = "select DISTINCT roomno from bookin where ammount = '0'"Set mrc = ExecuteSQL(txtSQL, MsgText)If Not ThenDo While NotcboItem(0).AddItem Trim(mrc!roomno)LoopElseMsgBox "没有顾客入住!", vbOKOnly + vbExclamation, "警告"= FalseExit SubEnd IfElseIf gintCmode = 2 ThenSet mrc = ExecuteSQL(txtSQL, MsgText)If = False ThenWith mrctxtNo = (0)For intCount = 0 To 1txtItem(intCount) = .Fields(intCount + 1)Next intCountcboItem(0).AddItem .Fields(3)cboItem(0).ListIndex = 0For intCount = 2 To 3If Not IsNull(.Fields(intCount + 2)) ThentxtItem(intCount) = .Fields(intCount + 2) End IfNext intCounttxtItem(5) = .Fields(6)txtItem(4) = .Fields(7)End WithEnd IftxtSQL = "select * from rooms where roomNO = '" & cboItem(0) & "'"Set mrc = ExecuteSQL(txtSQL, MsgText)If = False ThenWith mrcFor intCount = 1 To 3cboItem(intCount).AddItem .Fields(intCount) cboItem(intCount).ListIndex = 0Next intCountEnd WithEnd IfFor intCount = 0 To 3txtItem(intCount).Enabled = FalseNext intCount= & "修改"End IfmblChange = FalseEnd SubPrivate Sub Form_Unload(Cancel As Integer)gintCmode = 0End SubPrivate Sub txtItem_Change(Index As Integer)'有变化设置gblchangemblChange = TrueEnd SubPrivate Sub txtItem_GotFocus(Index As Integer)txtItem(Index).SelStart = 0txtItem(Index).SelLength = Len(txtItem(Index))End SubPrivate Sub txtItem_KeyDown(Index As Integer, KeyCode As Integer,Shift As Integer)EnterToTab KeyCodeEnd Sub5:结算信息查询窗体源代码:Option Explicit'用于传递查询块Private Sub chkItem_Click(Index As Integer) If Index = 2 ThencboYear(0).SetFocusElsetxtItem(Index).SetFocusEnd IfEnd SubPrivate Sub cmdExit_Click()End SubPrivate Sub cmdOK_Click()Dim dBeginDate As StringDim sQSql As StringIf chkItem(0).Value = vbChecked ThensQSql = " customname = '" & Trim(txtItem(0) & " ") & "'" End IfIf chkItem(1).Value = vbChecked ThenIf Trim(sQSql & " ") = "" ThensQSql = " roomno ='" & Trim(txtItem(1) & " ") & "'" ElsesQSql = sQSql & " and roomno ='" & Trim(txtItem(1) & " ") & "'"End IfEnd IfIf chkItem(2).Value = vbChecked ThendBeginDate = Format(CDate(cboYear(0) & "-" & cboMonth(0) & "-" & cboDay), "yyyy-mm-dd")If Trim(sQSql & " ") = "" ThensQSql = " indate ='" & dBeginDate & "'"ElsesQSql = sQSql & " and indate ='" & dBeginDate & "'" End IfEnd IfIf Trim(sQSql) = "" ThenMsgBox "请设置查询条件!", vbOKOnly + vbExclamation, "警告"Exit SubElseIf flagBedit ThenUnload frmCheckoutEnd If= "select * from bookin where ammount <> '0' and " & sQSql End IfEnd SubPrivate Sub Form_Load()Dim i As IntegerDim j As IntegerDim sSql As StringDim txtSQL As StringDim MsgText As StringDim mrc AstxtSQL = "select distinct datepart(yy,indate) from bookin where ammount <> '0'"Set mrc = ExecuteSQL(txtSQL, MsgText)If = False ThenWith mrcDo While Not .EOFcboYear(0).AddItem .Fields(0).MoveNextLoopEnd WithcboYear(0).ListIndex = 0For j = 1 To 12cboMonth(0).AddItem jNext jcboMonth(0).Text = Month(Now())For j = 1 To 31jNext j= Day(Now())Else= FalseEnd IfEnd SubPrivate Sub lblitem_Click(Index As Integer)chkItem(Index).Value = vbCheckedEnd SubPrivate Sub txtItem_GotFocus(Index As Integer)txtItem(Index).SelStart = 0txtItem(Index).SelLength = Len(txtItem(Index)) End Sub6:结算信息列表窗体源代码:Option ExplicitPublic txtSQL As StringDim mrc AsDim MsgText As StringPrivate Sub Form_Load()ShowTitleShowDataflagCedit = TrueEnd SubPrivate Sub Form_Resize()If <> vbMinimized And <> vbMinimized Then '边界处理If < 10 * ThenExit SubEnd IfIf < + / 2 ThenExit SubEnd If'控制控件的位置== - / 2= + + / 2= - 200= + 100= - - 200End IfEnd SubPublic Sub FormClose()Unload MeEnd SubPrivate Sub Form_Unload(Cancel As Integer) flagCedit = FalsegintCmode = 0End Sub'显示Grid的内容Private Sub ShowData()Dim j As IntegerDim i As IntegerSet mrc = ExecuteSQL(txtSQL, MsgText)With msgList.Rows = 1Do While Not.Rows = .Rows + 1For i = 1 To Select Case (i - 1).Type Case adDBDate.TextMatrix(.Rows - 1, i) = Format(i - 1) & "", "yyyy-mm-dd")Case Else.TextMatrix(.Rows - 1, i) = (i - 1) & "" End SelectNext iLoopEnd WithEnd Sub'显示Grid表头Private Sub ShowTitle()Dim i As IntegerWith msgList.Cols = 10.TextMatrix(0, 1) = "".TextMatrix(0, 2) = "顾客姓名" .TextMatrix(0, 3) = "身份证号码" .TextMatrix(0, 4) = "房间编号" .TextMatrix(0, 5) = "入住日期" .TextMatrix(0, 6) = "折扣".TextMatrix(0, 7) = "备注信息" .TextMatrix(0, 8) = "结算日期" .TextMatrix(0, 9) = "金额"'固定表头.FixedRows = 1'设置各列的对齐方式For i = 0 To 9.ColAlignment(i) = 0Next i'表头项居中.FillStyle = flexFillRepeat .Col = 0.Row = 0.RowSel = 1.ColSel = .Cols - 1.CellAlignment = 4'设置单元大小.ColWidth(0) = 300.ColWidth(1) = 0.ColWidth(2) = 1000.ColWidth(3) = 2000.ColWidth(4) = 2000.ColWidth(5) = 2000.ColWidth(6) = 2000.ColWidth(7) = 2000.ColWidth(8) = 2000.ColWidth(9) = 1000.Row = 1End WithEnd SubPrivate Sub msgList_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)'右键弹出If Button = 2 And Shift = 0 ThenPopupMenuEnd IfEnd Sub7:客房信息窗体源代码:Option Explicit'是否改动过记录,ture为改过Dim mblChange As BooleanDim mrc AsPublic txtSQL As StringPrivate Sub cboItem_Change(Index As Integer)'有变化设置gblchangemblChange = TrueEnd SubPrivate Sub cboItem_Click(Index As Integer)Dim sSql As StringDim MsgText As StringDim mrcc As'初始化员工名称和IDIf Index = 0 ThentxtSQL = "select typename,price from roomtype where typename='" & Trim(cboItem(0)) & "'"Set mrcc = ExecuteSQL(txtSQL, MsgText)If Not ThentxtItem(2) = mrcc!price= TrueElseMsgBox "请先建立客房标准!", vbOKOnly + vbExclamation, "警告"= FalseExit SubEnd IfEnd IfExit SubEnd SubPrivate Sub cboItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)EnterToTab KeyCodeEnd SubPrivate Sub cmdExit_Click()If mblChange And ThenIf MsgBox("保存当前记录的变化吗", vbOKCancel + vbExclamation, "警告") = vbOK Then'保存Call cmdSave_ClickEnd IfEnd IfUnload MeEnd SubPrivate Sub cmdSave_Click()Dim intCount As IntegerDim sMeg As StringDim mrcc AsDim MsgText As StringFor intCount = 0 To 3If Trim(txtItem(intCount) & " ") = "" ThenSelect Case intCountCase 0sMeg = "客房编号"Case 1sMeg = "客房位置"End SelectsMeg = sMeg & "不能为空!"MsgBox sMeg, vbOKOnly + vbExclamation, "警告"txtItem(intCount).SetFocusExit SubEnd IfNext intCountIf gintRmode = 1 ThentxtSQL = "select * from rooms where roomNO='" & Trim(txtItem(0)) & "'"Set mrc = ExecuteSQL(txtSQL, MsgText)If = False ThenMsgBox "已经存在此客房编号的记录!", vbOKOnly + vbExclamation, "警告"txtItem(0).SetFocusExit SubEnd IfEnd IfIf gintRmode = 2 Then'先删除已有记录txtSQL = "delete from rooms where roomNO='" & Trim(txtItem(0)) & "'"Set mrc = ExecuteSQL(txtSQL, MsgText)End If'再加入新记录txtSQL = "select * from rooms"Set mrc = ExecuteSQL(txtSQL, MsgText)(0) = Trim(txtItem(0))(1) = Trim(cboItem(0))For intCount = 1 To 2If Trim(txtItem(intCount) & " ") = "" Then (intCount + 1) = NullElse(intCount + 1) = Trim(txtItem(intCount)) End IfNext intCount(4) = " "(5) = Trim(txtItem(3))If gintRmode = 1 ThenFor intCount = 0 To 3txtItem(intCount) = ""Next intCountmblChange = FalseIf flagRedit ThenUnload frmRoom= "select * from rooms"End If。
《C语言程序设计》实验报告 15电气工程及其自动化2
《C语言程序设计》实验报告2015~2016学年第二学期班级15电气工程及其自动化2姓名学号指导教师张老师实验一实验项目名称:C程序的运行环境和运行C程序的方法所使用的工具软件及环境:Visual C++ 6.0一、实验目的:1.了解在Visual C++ 6.0环境下如何编辑、编译、连接和运行一个C程序;2.通过运行简单的C程序,初步了解C源程序的特点。
二、预习内容:教材《C语言程序设计教程》第1章。
三、实验内容:1. 在Visual C++ 6.0环境下输入并运行下面的程序:#include <stdio.h>main( ){printf("This is a C program.\n");}2. 在Visual C++ 6.0环境下输入下面的程序(有语法错误),编译、连接、调试该程序,直至程序无语法错误,然后运行程序,并观察分析运行结果。
#include <stdio.h>main( ){int a,b,suma=3;b=4;sun=a+b;print("%d+%d=%d\n",a,b,sum);}四、实验结果:1. 运行结果2. (1) 改正后的源程序:(2) 运行结果五、编程题:1.从键盘输入a,b,c三个整数,求这三个数之和?源程序:2.从键盘输入任意两个整数,编程实现这两个数之间的交换。
源程序成绩指导教师签名实验二实验项目名称:数据类型、运算符和表达式所使用的工具软件及环境:Visual C++ 6.0一、实验目的:1.掌握整型、实型与字符型这三种基本类型的概念;2.掌握常量及变量的使用方法;3. 掌握基本算术运算符及其表达式的使用方法;4. 掌握++、--运算符、赋值运算符及其表达式的使用方法。
二、预习内容:教材《C语言程序设计教程》第2章。
三、实验内容:1. 在Visual C++ 6.0环境下输入下面的程序(有语法错误),编译、连接、调试该程序,直至程序无语法错误。
源程序清单——精选推荐
#include"stdio.h"#include"stdlib.h"#include"string.h"#include"time.h"#define SIZE 20000intc1=0,m1=0,c2=0,m2=0,c3=0,m3=0,c4=0,m4=0,c5=0,m5=0,c6=0,m6=0,c7=0,m7=0,c8=0,m8=0,n ;//c,m为记录关键字比较和移动的次数typedef struct{int key;}ElemType;typedef struct{ElemType *elem;int length;}SqList;void addlist(SqList &L)//初始化顺序表{printf("请输入你要输入的个数:");scanf("%d",&n);while(n>20000){printf("超出范围(应小于20000),请重新输入\n");printf("请输入你要输入的个数:");scanf("%d",&n);}L.elem=(ElemType*)malloc(SIZE*sizeof(ElemType));if(!L.elem) exit(0);}void random(SqList &L)//随机数产生程序{int i,first=1;L.length=0;if(first){srand(time(0));first=0;}for(i=1;i<n+1;i++) //使输入相同个数时;每次产生的随机数不同{L.elem[i].key=rand();while(L.elem[i].key>20000){L.elem[i].key=rand();}++L.length;}}void memory(SqList &M,SqList &L)//记录L,使每个排序算法都用一组相同的随机数{int i;M.length=0;for(i=1;i<n+1;i++){M.elem[i].key=L.elem[i].key;++M.length;}}/***************冒泡排序***************/void BubbleSort(SqList &L){int i,j;for(i=1;i<L.length;i++){for(j=1;j<L.length-i+1;j++){c1++;if(L.elem[j].key>L.elem[j+1].key){L.elem[0].key=L.elem[j].key;L.elem[j].key=L.elem[j+1].key;L.elem[j+1].key=L.elem[0].key;m1+=3;}}}}/***************直接插入排序***************/void InsertSort(SqList &L){int i,j;for(i=2;i<=L.length;i++){if(L.elem[i].key<L.elem[i-1].key){L.elem[0].key=L.elem[i].key;m2++;j=i-1;c2++;while(L.elem[0].key<L.elem[j].key){L.elem[j+1].key=L.elem[j].key;j--;m2++;c2++;}L.elem[j+1].key=L.elem[0].key;m2++;}}}/***************简单选择排序***************/ void SelectSort(SqList &L){int i,j,k;for(i=1;i<L.length;i++){k=i;for(j=i+1;j<L.length;j++){c3++;if(L.elem[j].key<L.elem[k].key) k=j;}if(i!=k){L.elem[0].key=L.elem[i].key;L.elem[i].key=L.elem[k].key;L.elem[k].key=L.elem[0].key;m3+=3;}}}/***************快速排序***************/int Partition(SqList &L,int low,int high){int pivotkey;m4++;pivotkey=L.elem[low].key;while (low<high){m4++;while(low<high&&L.elem[high].key>=pivotkey)--high;L.elem[low]=L.elem[high];c4++;m4++;while (low<high&&L.elem[low].key<=pivotkey)++low;L.elem[high]=L.elem[low];c4++;m4++;}L.elem[low]=L.elem[0];m4++;return low;}void QSort(SqList &L,int low,int high){//对顺序表的子序列作快速排序int pivotloc;if(low<high){pivotloc=Partition(L,low,high);QSort(L,low,pivotloc-1);QSort(L,pivotloc+1,high);}}void QuickSort(SqList &L){//对顺序表L作快速排序QSort(L,1,L.length);}/***************希尔排序***************/void ShellPass(SqList &L,int d){//希尔排序中的一趟排序,d为当前增量int i,j;for(i=d+1;i<=n;i++) //将L.elem[d+1..n]分别插入各组当前的有序区{if(L.elem[i].key<L.elem[i-d].key){j=i-d;m5++;do {//查找L.elem[i]的插入位置L.elem[j+d]=L.elem[j]; //后移记录m5++;c5++;j=j-d; //查找前一记录}while(j>0&&L.elem[0].key<L.elem[j].key);L.elem[j+d]=L.elem[0]; //插入L.elem[i]到正确的位置上m5++;}c5++;}}void ShellSort(SqList &L){do{L.length=L.length/2; //求下一增量ShellPass(L,L.length); //一趟增量为L.length的Shell插入排序}while(L.length>1);}/*****************堆排序*****************/void AdjustHeap(SqList &L, int hLen, int i){int left = 2*i; //节点i的左孩子int right = 2*i+1; //节点i的右孩子节点int largest = i;while(left < hLen || right < hLen){if (left < hLen && L.elem[largest].key < L.elem[left].key){largest = left;}c6++;if (right < hLen && L.elem[largest].key < L.elem[right].key){largest = right;}c6++;if (i != largest) //如果最大值不是父节点{L.elem[0]= L.elem[largest]; //交换父节点和和拥有最大值的子节点交换L.elem[largest] = L.elem[i];L.elem[i] = L.elem[0];m6+=3;i = largest; //新的父节点,以备迭代调堆left = 2*i; //新的子节点right = 2*i+1;}else{break;}}}void BuildHeap(SqList &L, int hLen) //建堆{int i;int begin=hLen/2; //最后一个非叶子节点for (i = begin; i >= 0; i--){AdjustHeap(L, hLen, i);}}void HeapSort(SqList &L){int hLen=L.length;BuildHeap(L, hLen); //建堆while (hLen >= 1){L.elem[0]=L.elem[hLen]; //交换堆的第一个元素和堆的最后一个元素L.elem[hLen]=L.elem[1];L.elem[1]=L.elem[0];m6+=3;hLen--; //堆的大小减一AdjustHeap(L, hLen, 1); //调堆}}/***************折半插入排序***************/void BInsertSort(SqList &L){int i,low,high,m,j;for(i=2;i<=L.length;++i){L.elem[0]=L.elem[i];c7++;m7++;low=1;high=i-1;while(low<=high){m=(low+high)/2;if(L.elem[0].key<L.elem[m].key)high=m-1;else low=m+1;c7++;}for(j=i-1;j>=high+1;--j){L.elem[j+1]=L.elem[j];m7++;}L.elem[high+1]=L.elem[0];m7++;}}/*****************归并排序*****************/ void merge(SqList &L,SqList &L1,int low,int mid,int high) {int i,j,k;i=low;j=mid+1;k=low;while((i<=mid)&&(j<=high)){if(L.elem[i].key<=L.elem[j].key)L1.elem[k++]=L.elem[i++];elseL1.elem[k++]=L.elem[j++];c8++;m8++;}while(i<=mid){L1.elem[k++]=L.elem[i++];m8++;}while(j<=high){L1.elem[k++]=L.elem[j++];m8++;}}void mergepass(SqList &L,SqList &L1,int l){int i,j;i=0;while(i+2*l-1<L.length){merge(L,L1,i,i+l-1,i+2*l-1);i=i+2*l;}if((i+l-1)<(L.length-1))merge(L,L1,i,i+l-1,L.length-1);elsefor(j=i;j<L.length;j++)L1.elem[j++]=L.elem[j++];}void MergeSort(SqList &L){SqList L1;L1.elem=(ElemType*)malloc(SIZE*sizeof(ElemType));int l;l=1;while(l<L.length){mergepass(L,L1,l);l=2*l;mergepass(L1,L,l);l=2*l;}free(L1.elem);}void main(){printf(" ---------------------------------内部排序算法比较-----------------------------\n");printf("************************************欢迎使用***********************************\n");printf("**********************************(1)运行程序**********************************\n");printf("**********************************(0)退出系统**********************************\n");while(1){FILE *fp;SqList L,M;int choose,i;M.elem=(ElemType*)malloc(SIZE*sizeof(ElemType));if(!M.elem)exit(0);printf("请选择:");scanf("%d",&choose);switch(choose){case 1:addlist(L);random(L);fp=fopen("f:\\input.txt", "w+");//将产生的随机数存到文件open.txt中if(fp==NULL){printf("文件打开失败\n");fclose(fp);exit(1);}for(i=1;i<=L.length;i++){fprintf(fp,"%-10d",L.elem[i].key);if(i%10==0)fprintf(fp,"\n");}fprintf(fp,"\n\n");fclose(fp);memory(M,L);BubbleSort(M);memory(M,L);InsertSort(M);memory(M,L);SelectSort(M);memory(M,L);QuickSort(M);memory(M,L);ShellSort(M);memory(M,L);HeapSort(M);memory(M,L);BInsertSort(M);memory(M,L);MergeSort(L);printf(" *********比较次数**********移动次数*********\n");printf("冒泡排序:%10d %10d\n",c1,m1);printf("直接插入:%10d %10d\n",c2,m2);printf("简单选择: %10d %10d\n",c3,m3);printf("快速排序: %10d %10d\n",c4,m4);printf("希尔排序: %10d %10d\n",c5,m5);printf("堆排序:%10d %10d\n",c6,m6);printf("折半插入: %10d %10d\n",c7,m7);printf("归并排序: %10d %10d\n",c8,m8);if((fp=fopen("f:\\out.txt","w+"))==NULL)//各个算法的关键字比较次数和关键字移动次数保存到Out.txt文件中{printf("文件打开失败\n");fclose(fp);exit(1);}fprintf(fp," *********比较次数**********移动次数*********\n");fprintf(fp,"冒泡排序:%10d %10d\n",c1,m1);fprintf(fp,"直接插入:%10d %10d\n",c2,m2);fprintf(fp,"简单选择: %10d %10d\n",c3,m3);fprintf(fp,"快速排序: %10d %10d\n",c4,m4);fprintf(fp,"希尔排序: %10d %10d\n",c5,m5);fprintf(fp,"堆排序: %10d %10d\n",c6,m6);fprintf(fp,"折半插入: %10d %10d\n",c7,m7);fprintf(fp,"归并排序: %10d %10d\n",c8,m8);fprintf(fp,"\n\n");fclose(fp);c1=0;m1=0;c2=0;m2=0;c3=0;m3=0;c4=0;m4=0;c5=0;m5=0;c6=0;m6=0;c7=0;m7=0;c8=0;m8=0;break;case 0:printf("谢谢使用\n");exit(0);break;default:printf("输入有问题,请重新输入!\n");}}}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
2) 再选择菜单:Project->Settings 在对话框中选择 Link,在 Object\Library Modules 中添加:libmx.lib,libmat.lib,libeng.lib 三项。此操作每次打开编 译器都要修改一次。
engEvalString(ep,"r=a*t;"); engEvalString(ep,"FA=compose(FA,r);"); engEvalString(ep, " syms t;"); engEvalString(ep,"u=u+diff(FA,t)"); } cout<<"please input du/dt(x,y,z,0)"<<endl; 输 入 du/dt(x,y,z,0) 的 解 析 表 达式,处理过程与处理 u(x,y,z,0)类似。 int legs=SaveList(s); // if(legs){ double sai[40]; b=s; for(i=0;i<legs;i++){ sai[i]=b->data;cout<<i<<"\t"<<sai[i]<<(char)sai[i]<<endl; b=b->next; } Delete(s); SAI=mxCreateDoubleMatrix(1,legs,mxREAL); memcpy((char*)mxGetPr(SAI),(char*)sai,legs*sizeof(double)); engPutVariable(ep,"SAI",SAI); engEvalString(ep,"SA=trilinear(SAI);"); engEvalString(ep,"r=a*t;"); engEvalString(ep,"S=compose(SA,r);"); engEvalString(ep, " u=u+S;"); } cout<<"please input f(x,y,z,t)"<<endl;输入非齐次项 int lege=SaveList(e); / 将非齐次项 f(x,y,z)按照上面类似方式处理存入 MATLAB 计算引擎。 if(lege){ double ef[40]; b=e; for(i=0;i<lege;i++){ ef[i]=b->data; b=b->next; } Delete(e); EF=mxCreateDoubleMatrix(1,lege,mxREAL);
1)
在 开 始 编 译 之 前 , 要 先 选 择 菜 单 : Toos->Options 在 对 话 框 中 选 择 Directories,在 include files 项中添加:C:\...\matlab\extern\include(请读 者 自 行 修 改 为 自 己 的 MATLAB 安 装 路 径 ) , 再 在 library files 中 添 加 C:\...\matlab\extern\lib\win32\microsoft\msvc60(请读者自行修改为自己 的 MATLAB 安装路径),本操作对每个项目修改一次即可。
2、
MATLAB 下的 M 文件部分:
说明:这里由于时间原因,我们没能给出三维非齐次波动方程的求 解 M 文件。
function Q=trilinear(T) ascii_T=double(T); p=char(ascii_T);//将数组 T的 ASCII标准码转换成字符形式的函数解析 表达式。 syms r m n x y z a t X Y Z;//设置符号变量 X=x+r*sin(m)*cos(n);//球坐标代换。 Y=y+#include<iostream> using namespace std; struct List{//创建链表数据结构。 double data; struct List *next; }; typedef List L,*LI; extern void Init(LI &l){//新建链表。 l=NULL; } extern void Save(LI &head,L *p){// 将 输 入 的 字 符 所 转 化 的 ASCII 标 准 代码存入链表。 l=head; if(!head){ head=p; } else{ while(l->next)l=l->next; l->next=p; } } extern void Print(LI head){//输出链表以便测试检查。 L *l;l=head; while(l){ cout<<"l="<<l->data<<"address"<<l<<"\t"<<l->next<<endl; l=l->next; } } extern void Delete(L *head){//销毁链表以保护内存。 L *l; l=head; while(head){ head=head->next; delete l;
memcpy((char*)mxGetPr(EF),(char*)ef,lege*sizeof(double)); engPutVariable(ep,"EF",EF); engEvalString(ep,"EF=triunlinear(EF);"); 与前两个条件处理方式不 同的是这一次调用 triunlinear 的 M 文件求解。但是由于时间愿意,这 个 M 文件还没有完成。 engEvalString(ep, " u=u+EF;"); 将 计 算 所 得 结 果 与 齐 次 方 程 的 解 相加。 } if(legf)mxDestroyArray(FAI);释放所有内存空间。 if(legs)mxDestroyArray(SAI); if(lege)mxDestroyArray(EF); int ch; cout<<"close engine?"<<endl; cin>>ch; if(ch) engClose(ep); //关闭 MATLAB 引擎。 }
int i=0; LI f,s,e,b; Engine *ep; //打开 MATLAB 计算引擎,赋指针为 EP mxArray *FAI=NULL,*SAI=NULL,*EF=NULL; if (!(ep=engOpen(NULL))) //测试引擎是否打开。 { cout <<"Can't start Matlab engine!" <<endl; exit(1); } engEvalString(ep, " syms X Y Z x y z m n a t;"); engEvalString(ep, " u='0';"); cout<<"please input the type of the qutation:"<<endl;// 输 入 方 程 的 初 值 条 件 u(x,y,z,0),以 ’0’字符结束。 cout<<"please input u(x,y,z,0)"<<endl; int legf=SaveList(f); //生成解析表达式的字符链表并返回字符个数。 if(legf){//将解析表达式的 ASCII 代码存入数组 fai[40] b=f; double fai[40]; for(i=0;i<legf;i++){ fai[i]=b->data; b=b->next; } Delete(f);清除链表。 FAI=mxCreateDoubleMatrix(1,legf,mxREAL); 在 MATLAB 引 擎 里 创建一个一维矩阵,长度为所输入的解析表达式的字符个数 memcpy((char*)mxGetPr(FAI),(char*)fai,legf*sizeof(double)); ASCII 标准代码数组复制进入 MATLAB 引擎。 engPutVariable(ep,"FAI",FAI);为 MATLAB 引擎赋予变量。 engEvalString(ep,"FA=trilinear(FAI);"); 调 用 trilinear 文 件 将 ASCII 标准代码转换为字符的解析函数表达式并积分求解。 将
l=head; } delete head; } extern int SaveList(LI &a)// 输 入 解 析 表 达 式 , 并 将 其 以 字 符 的 ASCII 标准码形式存入链表。 { Init(a); char le; int length=0; cout<<"please input"<<endl; cin>>le; while(le!='0'){ L *temp=new L; temp->data=(double)le; temp->next=NULL; Save(a,temp); length++; cin>>le; } return length; } 文件 3:三维波动方程求解计算核心模块 #include<iostream> #include"engine.h" #include<string.h> #include<cmath> using namespace std; struct List{ double data; struct List *next; }; typedef List L,*LI; extern int SaveList(LI &a);/对调用的外部函数进行声明。 extern void Delete(L *head); extern void Print(LI head); extern void Save(LI &head,L *p); extern void Print(LI head); extern void TRI(){//三维方程求解计算核心。