东北大学软件技术基础实验报告.docx
《东北大学软件技术基础实验报告.docx》由会员分享,可在线阅读,更多相关《东北大学软件技术基础实验报告.docx(24页珍藏版)》请在冰豆网上搜索。
东北大学软件技术基础实验报告
实验一
代码:
#include"iostream"
#include
//定义一个线性表
constintnMaxSize=15;//最大值
intnLen=0;//表中元素个数
intnLinearList[nMaxSize];
//定义操作
voidLSort();
voidLOut();
voidLInsert(intn);
voidLDelete(intn);
voidmain()
{
//输入数据并放入线性表中
printf("Pleaseinputdata\n");//std:
:
cout<<"Pleaseinputdata\n";
intnIn=0;
for(inti=0;i<=9;i++)
scanf("%d",&nIn);//std:
cin>>nIn;
nLinearList[i]=nIn;
nLen++;
}
LSort();//排序线性表
LOut();//输出结果
printf("Pleaseinputadatatoinsert\n");
scanf("%d",&nIn);
LInsert(nIn);//输入一个数字,并插入到线性表中
LOut();
LSort();
printf("sorted:
\n");
while
(1)
printf("Pleaseinputanumberofdatatodelete\n");
if(nIn>nLen)
printf("numbermustlessthan%d\n",nLen);
else
break;
LDelete(nIn);//输入一个数字,并从线性表中删除
charchTmp;
printf("Pleaseinputachartofinishthisprogram.");
chTmp=getch();
voidLSort()//冒泡排序,由大到小
inti,j,temp;
for(j=0;j{for(i=0;i{if(nLinearList[i]{temp=nLinearList[i];nLinearList[i]=nLinearList[i+1];nLinearList[i+1]=temp;}}}}voidLOut(){printf("\n");for(inti=0;i<=nLen;i++){printf("%d,",nLinearList[i]);}printf("\n");}voidLInsert(intk){inti,j;while(1){printf("numberoftheplace:");scanf("%d",&j);if(j>nLen)printf("placenumbermustlessthan%d\n",nLen);elsebreak;}for(i=nLen;i>=j;--i)nLinearList[i]=nLinearList[i-1];nLinearList[j-1]=k;nLen++;}voidLDelete(intm){inti;for(i=m;i<=nLen;++i)nLinearList[i-1]=nLinearList[i];nLen--;}实验二代码:#include#include#include#includeconstintMAX_LEN=10;//字符串的长度constintMAX_SIZE=30;//栈或队的最大元素个数//定义一个队列的结构structQUEUE{intnMaxSize;//最大值intnCount;//个数intnFront;//头intnRear;//尾charszQueue[MAX_SIZE][MAX_LEN];};//定义一个栈的结构structSTACK{intnMaxSize;//最大值intnTop;//栈顶charszStack[MAX_SIZE][MAX_LEN];};//队列的操作voidInitQueue(QUEUE*q,intnMaxSize){q->nMaxSize=nMaxSize;q->nCount=0;q->nFront=0;q->nRear=0;q->szQueue[MAX_SIZE][MAX_LEN]=0;}voidInQueue(QUEUE*q,char*pItem){if(q->nCount==q->nMaxSize){printf("Queueisfull!\n");return;}strcpy(q->szQueue[q->nRear],pItem);if(q->nRear++==MAX_SIZE)q->nRear=0;q->nCount++;}voidOutQueue(QUEUE*q,char*pItem){if(q->nCount==0){printf("Queueisempty!\n");return;}strcpy(pItem,q->szQueue[q->nFront]);if(q->nFront++==MAX_SIZE)q->nFront=0;q->nCount--;}//栈的操作voidInitStack(STACK*s,intnMaxSize){s->nMaxSize=nMaxSize;s->nTop=0;s->szStack[MAX_SIZE][MAX_LEN]=0;}voidPushStack(STACK*s,char*pItem){char*p;if(s->nTopnMaxSize){p=s->szStack[s->nTop];strcpy(p,pItem);s->nTop++;}else{printf("stackoverflow!\n");return;}}voidPopStack(STACK*s,char*pItem){char*p;if(s->nTop==0){printf("stackisempty!\n");return;}else{p=s->szStack[--s->nTop];strcpy(pItem,p);}}voidGetTopStack(STACK*s,char*pItem){char*p;chara[10]={0};if(s->nTop==0){a[0]=';';strcpy(pItem,a);}else{p=s->szStack[s->nTop-1];strcpy(pItem,p);}}//字符判断intisdigit(charx){if(x>='0'&&x<='9')return1;return0;}intPriority(char*op);//获得操作符的优先级voidCompute(char*num1,char*num2,char*op,char*chResult);//计算表达式的值//主函数voidmain(){charx[MAX_LEN];//扫描的表达式charop[MAX_LEN];//栈顶运算符charnum1[MAX_LEN],num2[MAX_LEN];//两个操作数charchResult[MAX_LEN];//运算结果//***声明一个队列structQUEUEq1;structQUEUE*q;//***声明OS栈和NS栈structSTACKOS;structSTACKNS;structSTACK*o;structSTACK*n;inti=0;intj=0;intk=0;//****初始化q=&q1;o=&OS;n=&NS;InitStack(o,20);InitStack(n,20);InitQueue(q,20);printf("pleaseinputtheexpressionendwith\";\"\n");//录入表达式do{printf("next\n");scanf("%s",x);InQueue(q,x);}while(x[0]!=';');printf("expression\n");while(true){if(q->nCount!=0){OutQueue(q,x);printf("%s",x);}if(isdigit(x[0]))//是数PushStack(n,x);else//认为是运算符,没有考虑空格等{GetTopStack(o,op);//获得OS栈顶运算符if(x[0]==';'&&op[0]==';')//扫描结束{printf("\nresultis");break;}if(Priority(x)>Priority(op))//运算符的优先级〉栈顶运算符{PushStack(o,x);continue;}while((Priority(x)<=Priority(op))&&Priority(op))//不大于栈顶运算符{PopStack(n,num1);PopStack(n,num2);PopStack(o,op);Compute(num2,num1,op,chResult);PushStack(n,chResult);GetTopStack(o,op);}PushStack(o,x);}}PopStack(n,chResult);printf("%s\n",chResult);}intPriority(char*op){intnPriority=0;switch(op[0]){case'^':nPriority=3;break;case'*':case'/':nPriority=2;break;case'+':case'-':nPriority=1;break;case';':nPriority=0;}returnnPriority;}voidCompute(char*num1,char*num2,char*op,char*chResult){doublefNum1,fNum2;doublefResult=0;fNum1=atof(num1);fNum2=atof(num2);switch(op[0]){case'^':fResult=pow(fNum1,fNum2);break;case'*':fResult=fNum1*fNum2;break;case'/':fResult=fNum1/fNum2;break;case'+':fResult=fNum1+fNum2;break;case'-':fResult=fNum1-fNum2;break;}sprintf(chResult,"%.4f",fResult);//把计算的结果转化为字符串return;}运行结果实验三程序CREATEDATABASEmyDBCREATETABLEstub(SnoCHAR(8)PRIMARYKEY,SNAMECHAR(10),SexCHAR(2),Ageint,Birthdaydatetime,classCHAR(10));CreatetableCourseb(Cnochar(2)primarykey,Cnamechar(10),Chourint);CreatetableScoreb(Snochar(8),CnOchar(2),Gradeint,Primarykey(Sno,CnO),Foreignkey(Sno)referencesStub(Sno),Foreignkey(CnO)referencesCourseb(CnO));Insertintostub(Sno,sname,sex,age,birthday,class)values('0101','zhangqiang','m','20','19940220','zdh01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0102','lihong','f','20','19940810','zdh01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0103','wangtao','m','21','19930518','zdh01')Insertintostub(Sno,sname,sex,age,birthday,class)values('0104','liuli','f','19','19950305','zdh02');Insertintostub(Sno,sname,sex,age,birthday,class)values('0105','sundong','m','21','19931217','zdh02');Insertintostub(Sno,sname,sex,age,birthday,class)values('0106','wangping','m','22','19921130','zdh02');Insertintostub(Sno,sname,sex,age,birthday,class)values('0201','ouyangyan','f','20','19940411','dz01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0202','ouyangyan','f','20','19940411','dz01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0203','liuyan','f','18','19960121','dz01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0204','zhouyu','m','20','19940710','dz01');InsertintoCourseb(Cno,Cname,Chour)values('01','jsj','48');InsertintoCourseb(Cno,Cname,Chour)values('02','java','32');InsertintoScoreb(Sno,CnO,Grade)values('0101','01','87');InsertintoScoreb(Sno,CnO,Grade)values('0102','01','90');InsertintoScoreb(Sno,CnO,Grade)values('0103','01','79');InsertintoScoreb(Sno,CnO,Grade)values('0104','01','89');InsertintoScoreb(Sno,CnO,Grade)values('0105','01','58');InsertintoScoreb(Sno,CnO,Grade)values('0106','01','77');InsertintoScoreb(Sno,CnO,Grade)values('0201','01','95');InsertintoScoreb(Sno,CnO,Grade)values('0202','01','80');InsertintoScoreb(Sno,CnO,Grade)values('0203','01','76');InsertintoScoreb(Sno,CnO,Grade)values('0204','01','70');InsertintoScoreb(Sno,CnO,Grade)values('0101','02','91');InsertintoScoreb(Sno,CnO,Grade)values('0102','02','88');InsertintoScoreb(Sno,CnO,Grade)values('0103','02','75');InsertintoScoreb(Sno,CnO,Grade)values('0104','02','91');InsertintoScoreb(Sno,CnO,Grade)values('0105','02','76');InsertintoScoreb(Sno,CnO,Grade)values('0106','02','76');InsertintoScoreb(Sno,CnO,Grade)values('0201','02','90');InsertintoScoreb(Sno,CnO,Grade)values('0202','02','84');InsertintoScoreb(Sno,CnO,Grade)values('0203','02','83');InsertintoScoreb(Sno,CnO,Grade)values('0204','02','57');1、查询学生出生日期(Sno,Sname,BirthDay);selectdistinctsno,sname,birthdayfromstub2、按学号顺序查询自动化02班的所有学生(Class,Sname);selectdistinctsno,sname,classfromstubwhereclass='zdh02'orderbysno3、列出学生选择各门课程的成绩(Sname,Cname,Grade);selectdistinctSNAME,Cname,GradefromStub,Courseb,ScorebwhereStub.Sno=Scoreb.SnoANDCourseb.Cno=Scoreb.Cno;4、列出有过不及格成绩的学生名单(Sno,Sname,Class);selectdistinctstub.Sno,sname,CLASSfromstub,Scorebwherestub.Sno=Scoreb.SnoandGrade<605、求学生的平均成绩和总成绩(Sname,PJCJ,ZCJ);selectsname,avg(Grade)PJCJ,sum(Grade)ZCJFROMstub,scorebwherescoreb.sno=stub.snogroupbystub.sname6、查找各科成绩都>=85分的学生(Sname,Class);selectdistinctstub.Sno,sname,CLASSfromstub,Scorebwherestub.Sno=Scoreb.SnoandGrade>=857、将课程号为“01”的课程名称修改为“软件技术”;updateCoursebsetCname='RJJS'whereCno=01selectdistinct*fromCourseb8、修改一名学生的姓名、性别、年龄;updatestubsetSname='xuyiyang',sex='f',age='20'whereSno='0101'9、将成绩为55~59分的男生的成绩修改为60分;updateScorebsetGrade=60whereSnoin(SELECTSnoFROMStubwhereSex='m')ANDGradeBETWEEN55AND59;10、删除年龄不是20的学生的所有信息(包括选课和成绩);DELETEStubWHERES
for(i=0;i{if(nLinearList[i]{temp=nLinearList[i];nLinearList[i]=nLinearList[i+1];nLinearList[i+1]=temp;}}}}voidLOut(){printf("\n");for(inti=0;i<=nLen;i++){printf("%d,",nLinearList[i]);}printf("\n");}voidLInsert(intk){inti,j;while(1){printf("numberoftheplace:");scanf("%d",&j);if(j>nLen)printf("placenumbermustlessthan%d\n",nLen);elsebreak;}for(i=nLen;i>=j;--i)nLinearList[i]=nLinearList[i-1];nLinearList[j-1]=k;nLen++;}voidLDelete(intm){inti;for(i=m;i<=nLen;++i)nLinearList[i-1]=nLinearList[i];nLen--;}实验二代码:#include#include#include#includeconstintMAX_LEN=10;//字符串的长度constintMAX_SIZE=30;//栈或队的最大元素个数//定义一个队列的结构structQUEUE{intnMaxSize;//最大值intnCount;//个数intnFront;//头intnRear;//尾charszQueue[MAX_SIZE][MAX_LEN];};//定义一个栈的结构structSTACK{intnMaxSize;//最大值intnTop;//栈顶charszStack[MAX_SIZE][MAX_LEN];};//队列的操作voidInitQueue(QUEUE*q,intnMaxSize){q->nMaxSize=nMaxSize;q->nCount=0;q->nFront=0;q->nRear=0;q->szQueue[MAX_SIZE][MAX_LEN]=0;}voidInQueue(QUEUE*q,char*pItem){if(q->nCount==q->nMaxSize){printf("Queueisfull!\n");return;}strcpy(q->szQueue[q->nRear],pItem);if(q->nRear++==MAX_SIZE)q->nRear=0;q->nCount++;}voidOutQueue(QUEUE*q,char*pItem){if(q->nCount==0){printf("Queueisempty!\n");return;}strcpy(pItem,q->szQueue[q->nFront]);if(q->nFront++==MAX_SIZE)q->nFront=0;q->nCount--;}//栈的操作voidInitStack(STACK*s,intnMaxSize){s->nMaxSize=nMaxSize;s->nTop=0;s->szStack[MAX_SIZE][MAX_LEN]=0;}voidPushStack(STACK*s,char*pItem){char*p;if(s->nTopnMaxSize){p=s->szStack[s->nTop];strcpy(p,pItem);s->nTop++;}else{printf("stackoverflow!\n");return;}}voidPopStack(STACK*s,char*pItem){char*p;if(s->nTop==0){printf("stackisempty!\n");return;}else{p=s->szStack[--s->nTop];strcpy(pItem,p);}}voidGetTopStack(STACK*s,char*pItem){char*p;chara[10]={0};if(s->nTop==0){a[0]=';';strcpy(pItem,a);}else{p=s->szStack[s->nTop-1];strcpy(pItem,p);}}//字符判断intisdigit(charx){if(x>='0'&&x<='9')return1;return0;}intPriority(char*op);//获得操作符的优先级voidCompute(char*num1,char*num2,char*op,char*chResult);//计算表达式的值//主函数voidmain(){charx[MAX_LEN];//扫描的表达式charop[MAX_LEN];//栈顶运算符charnum1[MAX_LEN],num2[MAX_LEN];//两个操作数charchResult[MAX_LEN];//运算结果//***声明一个队列structQUEUEq1;structQUEUE*q;//***声明OS栈和NS栈structSTACKOS;structSTACKNS;structSTACK*o;structSTACK*n;inti=0;intj=0;intk=0;//****初始化q=&q1;o=&OS;n=&NS;InitStack(o,20);InitStack(n,20);InitQueue(q,20);printf("pleaseinputtheexpressionendwith\";\"\n");//录入表达式do{printf("next\n");scanf("%s",x);InQueue(q,x);}while(x[0]!=';');printf("expression\n");while(true){if(q->nCount!=0){OutQueue(q,x);printf("%s",x);}if(isdigit(x[0]))//是数PushStack(n,x);else//认为是运算符,没有考虑空格等{GetTopStack(o,op);//获得OS栈顶运算符if(x[0]==';'&&op[0]==';')//扫描结束{printf("\nresultis");break;}if(Priority(x)>Priority(op))//运算符的优先级〉栈顶运算符{PushStack(o,x);continue;}while((Priority(x)<=Priority(op))&&Priority(op))//不大于栈顶运算符{PopStack(n,num1);PopStack(n,num2);PopStack(o,op);Compute(num2,num1,op,chResult);PushStack(n,chResult);GetTopStack(o,op);}PushStack(o,x);}}PopStack(n,chResult);printf("%s\n",chResult);}intPriority(char*op){intnPriority=0;switch(op[0]){case'^':nPriority=3;break;case'*':case'/':nPriority=2;break;case'+':case'-':nPriority=1;break;case';':nPriority=0;}returnnPriority;}voidCompute(char*num1,char*num2,char*op,char*chResult){doublefNum1,fNum2;doublefResult=0;fNum1=atof(num1);fNum2=atof(num2);switch(op[0]){case'^':fResult=pow(fNum1,fNum2);break;case'*':fResult=fNum1*fNum2;break;case'/':fResult=fNum1/fNum2;break;case'+':fResult=fNum1+fNum2;break;case'-':fResult=fNum1-fNum2;break;}sprintf(chResult,"%.4f",fResult);//把计算的结果转化为字符串return;}运行结果实验三程序CREATEDATABASEmyDBCREATETABLEstub(SnoCHAR(8)PRIMARYKEY,SNAMECHAR(10),SexCHAR(2),Ageint,Birthdaydatetime,classCHAR(10));CreatetableCourseb(Cnochar(2)primarykey,Cnamechar(10),Chourint);CreatetableScoreb(Snochar(8),CnOchar(2),Gradeint,Primarykey(Sno,CnO),Foreignkey(Sno)referencesStub(Sno),Foreignkey(CnO)referencesCourseb(CnO));Insertintostub(Sno,sname,sex,age,birthday,class)values('0101','zhangqiang','m','20','19940220','zdh01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0102','lihong','f','20','19940810','zdh01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0103','wangtao','m','21','19930518','zdh01')Insertintostub(Sno,sname,sex,age,birthday,class)values('0104','liuli','f','19','19950305','zdh02');Insertintostub(Sno,sname,sex,age,birthday,class)values('0105','sundong','m','21','19931217','zdh02');Insertintostub(Sno,sname,sex,age,birthday,class)values('0106','wangping','m','22','19921130','zdh02');Insertintostub(Sno,sname,sex,age,birthday,class)values('0201','ouyangyan','f','20','19940411','dz01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0202','ouyangyan','f','20','19940411','dz01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0203','liuyan','f','18','19960121','dz01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0204','zhouyu','m','20','19940710','dz01');InsertintoCourseb(Cno,Cname,Chour)values('01','jsj','48');InsertintoCourseb(Cno,Cname,Chour)values('02','java','32');InsertintoScoreb(Sno,CnO,Grade)values('0101','01','87');InsertintoScoreb(Sno,CnO,Grade)values('0102','01','90');InsertintoScoreb(Sno,CnO,Grade)values('0103','01','79');InsertintoScoreb(Sno,CnO,Grade)values('0104','01','89');InsertintoScoreb(Sno,CnO,Grade)values('0105','01','58');InsertintoScoreb(Sno,CnO,Grade)values('0106','01','77');InsertintoScoreb(Sno,CnO,Grade)values('0201','01','95');InsertintoScoreb(Sno,CnO,Grade)values('0202','01','80');InsertintoScoreb(Sno,CnO,Grade)values('0203','01','76');InsertintoScoreb(Sno,CnO,Grade)values('0204','01','70');InsertintoScoreb(Sno,CnO,Grade)values('0101','02','91');InsertintoScoreb(Sno,CnO,Grade)values('0102','02','88');InsertintoScoreb(Sno,CnO,Grade)values('0103','02','75');InsertintoScoreb(Sno,CnO,Grade)values('0104','02','91');InsertintoScoreb(Sno,CnO,Grade)values('0105','02','76');InsertintoScoreb(Sno,CnO,Grade)values('0106','02','76');InsertintoScoreb(Sno,CnO,Grade)values('0201','02','90');InsertintoScoreb(Sno,CnO,Grade)values('0202','02','84');InsertintoScoreb(Sno,CnO,Grade)values('0203','02','83');InsertintoScoreb(Sno,CnO,Grade)values('0204','02','57');1、查询学生出生日期(Sno,Sname,BirthDay);selectdistinctsno,sname,birthdayfromstub2、按学号顺序查询自动化02班的所有学生(Class,Sname);selectdistinctsno,sname,classfromstubwhereclass='zdh02'orderbysno3、列出学生选择各门课程的成绩(Sname,Cname,Grade);selectdistinctSNAME,Cname,GradefromStub,Courseb,ScorebwhereStub.Sno=Scoreb.SnoANDCourseb.Cno=Scoreb.Cno;4、列出有过不及格成绩的学生名单(Sno,Sname,Class);selectdistinctstub.Sno,sname,CLASSfromstub,Scorebwherestub.Sno=Scoreb.SnoandGrade<605、求学生的平均成绩和总成绩(Sname,PJCJ,ZCJ);selectsname,avg(Grade)PJCJ,sum(Grade)ZCJFROMstub,scorebwherescoreb.sno=stub.snogroupbystub.sname6、查找各科成绩都>=85分的学生(Sname,Class);selectdistinctstub.Sno,sname,CLASSfromstub,Scorebwherestub.Sno=Scoreb.SnoandGrade>=857、将课程号为“01”的课程名称修改为“软件技术”;updateCoursebsetCname='RJJS'whereCno=01selectdistinct*fromCourseb8、修改一名学生的姓名、性别、年龄;updatestubsetSname='xuyiyang',sex='f',age='20'whereSno='0101'9、将成绩为55~59分的男生的成绩修改为60分;updateScorebsetGrade=60whereSnoin(SELECTSnoFROMStubwhereSex='m')ANDGradeBETWEEN55AND59;10、删除年龄不是20的学生的所有信息(包括选课和成绩);DELETEStubWHERES
if(nLinearList[i]{temp=nLinearList[i];nLinearList[i]=nLinearList[i+1];nLinearList[i+1]=temp;}}}}voidLOut(){printf("\n");for(inti=0;i<=nLen;i++){printf("%d,",nLinearList[i]);}printf("\n");}voidLInsert(intk){inti,j;while(1){printf("numberoftheplace:");scanf("%d",&j);if(j>nLen)printf("placenumbermustlessthan%d\n",nLen);elsebreak;}for(i=nLen;i>=j;--i)nLinearList[i]=nLinearList[i-1];nLinearList[j-1]=k;nLen++;}voidLDelete(intm){inti;for(i=m;i<=nLen;++i)nLinearList[i-1]=nLinearList[i];nLen--;}实验二代码:#include#include#include#includeconstintMAX_LEN=10;//字符串的长度constintMAX_SIZE=30;//栈或队的最大元素个数//定义一个队列的结构structQUEUE{intnMaxSize;//最大值intnCount;//个数intnFront;//头intnRear;//尾charszQueue[MAX_SIZE][MAX_LEN];};//定义一个栈的结构structSTACK{intnMaxSize;//最大值intnTop;//栈顶charszStack[MAX_SIZE][MAX_LEN];};//队列的操作voidInitQueue(QUEUE*q,intnMaxSize){q->nMaxSize=nMaxSize;q->nCount=0;q->nFront=0;q->nRear=0;q->szQueue[MAX_SIZE][MAX_LEN]=0;}voidInQueue(QUEUE*q,char*pItem){if(q->nCount==q->nMaxSize){printf("Queueisfull!\n");return;}strcpy(q->szQueue[q->nRear],pItem);if(q->nRear++==MAX_SIZE)q->nRear=0;q->nCount++;}voidOutQueue(QUEUE*q,char*pItem){if(q->nCount==0){printf("Queueisempty!\n");return;}strcpy(pItem,q->szQueue[q->nFront]);if(q->nFront++==MAX_SIZE)q->nFront=0;q->nCount--;}//栈的操作voidInitStack(STACK*s,intnMaxSize){s->nMaxSize=nMaxSize;s->nTop=0;s->szStack[MAX_SIZE][MAX_LEN]=0;}voidPushStack(STACK*s,char*pItem){char*p;if(s->nTopnMaxSize){p=s->szStack[s->nTop];strcpy(p,pItem);s->nTop++;}else{printf("stackoverflow!\n");return;}}voidPopStack(STACK*s,char*pItem){char*p;if(s->nTop==0){printf("stackisempty!\n");return;}else{p=s->szStack[--s->nTop];strcpy(pItem,p);}}voidGetTopStack(STACK*s,char*pItem){char*p;chara[10]={0};if(s->nTop==0){a[0]=';';strcpy(pItem,a);}else{p=s->szStack[s->nTop-1];strcpy(pItem,p);}}//字符判断intisdigit(charx){if(x>='0'&&x<='9')return1;return0;}intPriority(char*op);//获得操作符的优先级voidCompute(char*num1,char*num2,char*op,char*chResult);//计算表达式的值//主函数voidmain(){charx[MAX_LEN];//扫描的表达式charop[MAX_LEN];//栈顶运算符charnum1[MAX_LEN],num2[MAX_LEN];//两个操作数charchResult[MAX_LEN];//运算结果//***声明一个队列structQUEUEq1;structQUEUE*q;//***声明OS栈和NS栈structSTACKOS;structSTACKNS;structSTACK*o;structSTACK*n;inti=0;intj=0;intk=0;//****初始化q=&q1;o=&OS;n=&NS;InitStack(o,20);InitStack(n,20);InitQueue(q,20);printf("pleaseinputtheexpressionendwith\";\"\n");//录入表达式do{printf("next\n");scanf("%s",x);InQueue(q,x);}while(x[0]!=';');printf("expression\n");while(true){if(q->nCount!=0){OutQueue(q,x);printf("%s",x);}if(isdigit(x[0]))//是数PushStack(n,x);else//认为是运算符,没有考虑空格等{GetTopStack(o,op);//获得OS栈顶运算符if(x[0]==';'&&op[0]==';')//扫描结束{printf("\nresultis");break;}if(Priority(x)>Priority(op))//运算符的优先级〉栈顶运算符{PushStack(o,x);continue;}while((Priority(x)<=Priority(op))&&Priority(op))//不大于栈顶运算符{PopStack(n,num1);PopStack(n,num2);PopStack(o,op);Compute(num2,num1,op,chResult);PushStack(n,chResult);GetTopStack(o,op);}PushStack(o,x);}}PopStack(n,chResult);printf("%s\n",chResult);}intPriority(char*op){intnPriority=0;switch(op[0]){case'^':nPriority=3;break;case'*':case'/':nPriority=2;break;case'+':case'-':nPriority=1;break;case';':nPriority=0;}returnnPriority;}voidCompute(char*num1,char*num2,char*op,char*chResult){doublefNum1,fNum2;doublefResult=0;fNum1=atof(num1);fNum2=atof(num2);switch(op[0]){case'^':fResult=pow(fNum1,fNum2);break;case'*':fResult=fNum1*fNum2;break;case'/':fResult=fNum1/fNum2;break;case'+':fResult=fNum1+fNum2;break;case'-':fResult=fNum1-fNum2;break;}sprintf(chResult,"%.4f",fResult);//把计算的结果转化为字符串return;}运行结果实验三程序CREATEDATABASEmyDBCREATETABLEstub(SnoCHAR(8)PRIMARYKEY,SNAMECHAR(10),SexCHAR(2),Ageint,Birthdaydatetime,classCHAR(10));CreatetableCourseb(Cnochar(2)primarykey,Cnamechar(10),Chourint);CreatetableScoreb(Snochar(8),CnOchar(2),Gradeint,Primarykey(Sno,CnO),Foreignkey(Sno)referencesStub(Sno),Foreignkey(CnO)referencesCourseb(CnO));Insertintostub(Sno,sname,sex,age,birthday,class)values('0101','zhangqiang','m','20','19940220','zdh01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0102','lihong','f','20','19940810','zdh01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0103','wangtao','m','21','19930518','zdh01')Insertintostub(Sno,sname,sex,age,birthday,class)values('0104','liuli','f','19','19950305','zdh02');Insertintostub(Sno,sname,sex,age,birthday,class)values('0105','sundong','m','21','19931217','zdh02');Insertintostub(Sno,sname,sex,age,birthday,class)values('0106','wangping','m','22','19921130','zdh02');Insertintostub(Sno,sname,sex,age,birthday,class)values('0201','ouyangyan','f','20','19940411','dz01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0202','ouyangyan','f','20','19940411','dz01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0203','liuyan','f','18','19960121','dz01');Insertintostub(Sno,sname,sex,age,birthday,class)values('0204','zhouyu','m','20','19940710','dz01');InsertintoCourseb(Cno,Cname,Chour)values('01','jsj','48');InsertintoCourseb(Cno,Cname,Chour)values('02','java','32');InsertintoScoreb(Sno,CnO,Grade)values('0101','01','87');InsertintoScoreb(Sno,CnO,Grade)values('0102','01','90');InsertintoScoreb(Sno,CnO,Grade)values('0103','01','79');InsertintoScoreb(Sno,CnO,Grade)values('0104','01','89');InsertintoScoreb(Sno,CnO,Grade)values('0105','01','58');InsertintoScoreb(Sno,CnO,Grade)values('0106','01','77');InsertintoScoreb(Sno,CnO,Grade)values('0201','01','95');InsertintoScoreb(Sno,CnO,Grade)values('0202','01','80');InsertintoScoreb(Sno,CnO,Grade)values('0203','01','76');InsertintoScoreb(Sno,CnO,Grade)values('0204','01','70');InsertintoScoreb(Sno,CnO,Grade)values('0101','02','91');InsertintoScoreb(Sno,CnO,Grade)values('0102','02','88');InsertintoScoreb(Sno,CnO,Grade)values('0103','02','75');InsertintoScoreb(Sno,CnO,Grade)values('0104','02','91');InsertintoScoreb(Sno,CnO,Grade)values('0105','02','76');InsertintoScoreb(Sno,CnO,Grade)values('0106','02','76');InsertintoScoreb(Sno,CnO,Grade)values('0201','02','90');InsertintoScoreb(Sno,CnO,Grade)values('0202','02','84');InsertintoScoreb(Sno,CnO,Grade)values('0203','02','83');InsertintoScoreb(Sno,CnO,Grade)values('0204','02','57');1、查询学生出生日期(Sno,Sname,BirthDay);selectdistinctsno,sname,birthdayfromstub2、按学号顺序查询自动化02班的所有学生(Class,Sname);selectdistinctsno,sname,classfromstubwhereclass='zdh02'orderbysno3、列出学生选择各门课程的成绩(Sname,Cname,Grade);selectdistinctSNAME,Cname,GradefromStub,Courseb,ScorebwhereStub.Sno=Scoreb.SnoANDCourseb.Cno=Scoreb.Cno;4、列出有过不及格成绩的学生名单(Sno,Sname,Class);selectdistinctstub.Sno,sname,CLASSfromstub,Scorebwherestub.Sno=Scoreb.SnoandGrade<605、求学生的平均成绩和总成绩(Sname,PJCJ,ZCJ);selectsname,avg(Grade)PJCJ,sum(Grade)ZCJFROMstub,scorebwherescoreb.sno=stub.snogroupbystub.sname6、查找各科成绩都>=85分的学生(Sname,Class);selectdistinctstub.Sno,sname,CLASSfromstub,Scorebwherestub.Sno=Scoreb.SnoandGrade>=857、将课程号为“01”的课程名称修改为“软件技术”;updateCoursebsetCname='RJJS'whereCno=01selectdistinct*fromCourseb8、修改一名学生的姓名、性别、年龄;updatestubsetSname='xuyiyang',sex='f',age='20'whereSno='0101'9、将成绩为55~59分的男生的成绩修改为60分;updateScorebsetGrade=60whereSnoin(SELECTSnoFROMStubwhereSex='m')ANDGradeBETWEEN55AND59;10、删除年龄不是20的学生的所有信息(包括选课和成绩);DELETEStubWHERES
temp=nLinearList[i];
nLinearList[i]=nLinearList[i+1];
nLinearList[i+1]=temp;
voidLOut()
printf("\n");
for(inti=0;i<=nLen;i++)
printf("%d,",nLinearList[i]);
voidLInsert(intk)
inti,j;
printf("numberoftheplace:
");
scanf("%d",&j);
if(j>nLen)
printf("placenumbermustlessthan%d\n",nLen);
for(i=nLen;i>=j;--i)
nLinearList[i]=nLinearList[i-1];
nLinearList[j-1]=k;
voidLDelete(intm)
inti;
for(i=m;i<=nLen;++i)
nLinearList[i-1]=nLinearList[i];
nLen--;
实验二
constintMAX_LEN=10;//字符串的长度
constintMAX_SIZE=30;//栈或队的最大元素个数
//定义一个队列的结构
structQUEUE{
intnMaxSize;//最大值
intnCount;//个数
intnFront;//头
intnRear;//尾
charszQueue[MAX_SIZE][MAX_LEN];
};
//定义一个栈的结构
structSTACK{
intnTop;//栈顶
charszStack[MAX_SIZE][MAX_LEN];
//队列的操作
voidInitQueue(QUEUE*q,intnMaxSize)
q->nMaxSize=nMaxSize;
q->nCount=0;
q->nFront=0;
q->nRear=0;
q->szQueue[MAX_SIZE][MAX_LEN]=0;
voidInQueue(QUEUE*q,char*pItem)
if(q->nCount==q->nMaxSize)
printf("Queueisfull!
return;
strcpy(q->szQueue[q->nRear],pItem);
if(q->nRear++==MAX_SIZE)
q->nCount++;
voidOutQueue(QUEUE*q,char*pItem)
if(q->nCount==0)
printf("Queueisempty!
strcpy(pItem,q->szQueue[q->nFront]);
if(q->nFront++==MAX_SIZE)
q->nCount--;
//栈的操作
voidInitStack(STACK*s,intnMaxSize)
s->nMaxSize=nMaxSize;
s->nTop=0;
s->szStack[MAX_SIZE][MAX_LEN]=0;
voidPushStack(STACK*s,char*pItem)
char*p;
if(s->nTopnMaxSize)
p=s->szStack[s->nTop];
strcpy(p,pItem);
s->nTop++;
printf("stackoverflow!
voidPopStack(STACK*s,char*pItem)
if(s->nTop==0)
printf("stackisempty!
p=s->szStack[--s->nTop];
strcpy(pItem,p);
voidGetTopStack(STACK*s,char*pItem)
chara[10]={0};
a[0]=';';
strcpy(pItem,a);
p=s->szStack[s->nTop-1];
//字符判断
intisdigit(charx)
if(x>='0'&&x<='9')
return1;
return0;
intPriority(char*op);//获得操作符的优先级
voidCompute(char*num1,char*num2,char*op,char*chResult);//计算表达式的值
//主函数
charx[MAX_LEN];//扫描的表达式
charop[MAX_LEN];//栈顶运算符
charnum1[MAX_LEN],num2[MAX_LEN];//两个操作数
charchResult[MAX_LEN];//运算结果
//***声明一个队列
structQUEUEq1;
structQUEUE*q;
//***声明OS栈和NS栈
structSTACKOS;
structSTACKNS;
structSTACK*o;
structSTACK*n;
inti=0;
intj=0;
intk=0;
//****初始化
q=&q1;
o=&OS;
n=&NS;
InitStack(o,20);
InitStack(n,20);
InitQueue(q,20);
printf("pleaseinputtheexpressionendwith\";\"\n");
//录入表达式
do
printf("next\n");
scanf("%s",x);
InQueue(q,x);
while(x[0]!
=';');
printf("expression\n");
while(true)
if(q->nCount!
=0)
OutQueue(q,x);
printf("%s",x);
if(isdigit(x[0]))//是数
PushStack(n,x);
else//认为是运算符,没有考虑空格等
GetTopStack(o,op);//获得OS栈顶运算符
if(x[0]==';'&&op[0]==';')//扫描结束
{printf("\nresultis");
if(Priority(x)>Priority(op))//运算符的优先级〉栈顶运算符
PushStack(o,x);
continue;
while((Priority(x)<=Priority(op))&&Priority(op))//不大于栈顶运算符
PopStack(n,num1);
PopStack(n,num2);
PopStack(o,op);
Compute(num2,num1,op,chResult);
PushStack(n,chResult);
GetTopStack(o,op);
PopStack(n,chResult);
printf("%s\n",chResult);
intPriority(char*op)
intnPriority=0;
switch(op[0])
case'^':
nPriority=3;
case'*':
case'/':
nPriority=2;
case'+':
case'-':
nPriority=1;
case';':
nPriority=0;
returnnPriority;
voidCompute(char*num1,char*num2,char*op,char*chResult)
doublefNum1,fNum2;
doublefResult=0;
fNum1=atof(num1);
fNum2=atof(num2);
fResult=pow(fNum1,fNum2);
fResult=fNum1*fNum2;
fResult=fNum1/fNum2;
fResult=fNum1+fNum2;
fResult=fNum1-fNum2;
sprintf(chResult,"%.4f",fResult);//把计算的结果转化为字符串
运行结果
实验三
程序
CREATEDATABASEmyDB
CREATETABLEstub(SnoCHAR(8)PRIMARYKEY,
SNAMECHAR(10),
SexCHAR
(2),
Ageint,
Birthdaydatetime,
classCHAR(10));
CreatetableCourseb(Cnochar
(2)primarykey,
Cnamechar(10),
Chourint);
CreatetableScoreb(Snochar(8),
CnOchar
Gradeint,
Primarykey(Sno,CnO),
Foreignkey(Sno)referencesStub(Sno),
Foreignkey(CnO)referencesCourseb(CnO));
Insertintostub(Sno,sname,sex,age,birthday,class)
values('0101','zhangqiang','m','20','19940220','zdh01');
values('0102','lihong','f','20','19940810','zdh01');
values('0103','wangtao','m','21','19930518','zdh01')
values('0104','liuli','f','19','19950305','zdh02');
values('0105','sundong','m','21','19931217','zdh02');
values('0106','wangping','m','22','19921130','zdh02');
values('0201','ouyangyan','f','20','19940411','dz01');
values('0202','ouyangyan','f','20','19940411','dz01');
values('0203','liuyan','f','18','19960121','dz01');
values('0204','zhouyu','m','20','19940710','dz01');
InsertintoCourseb(Cno,Cname,Chour)
values('01','jsj','48');
values('02','java','32');
InsertintoScoreb(Sno,CnO,Grade)
values('0101','01','87');
values('0102','01','90');
values('0103','01','79');
values('0104','01','89');
values('0105','01','58');
values('0106','01','77');
values('0201','01','95');
values('0202','01','80');
values('0203','01','76');
values('0204','01','70');
values('0101','02','91');
values('0102','02','88');
values('0103','02','75');
values('0104','02','91');
values('0105','02','76');
values('0106','02','76');
values('0201','02','90');
values('0202','02','84');
values('0203','02','83');
values('0204','02','57');
1、查询学生出生日期(Sno,Sname,BirthDay);
selectdistinctsno,sname,birthdayfromstub
2、按学号顺序查询自动化02班的所有学生(Class,Sname);
selectdistinctsno,sname,classfromstubwhereclass='zdh02'orderbysno
3、列出学生选择各门课程的成绩(Sname,Cname,Grade);
selectdistinctSNAME,Cname,GradefromStub,Courseb,ScorebwhereStub.Sno=Scoreb.SnoANDCourseb.Cno=Scoreb.Cno;
4、列出有过不及格成绩的学生名单(Sno,Sname,Class);
selectdistinctstub.Sno,sname,CLASSfromstub,Scoreb
wherestub.Sno=Scoreb.SnoandGrade<60
5、求学生的平均成绩和总成绩(Sname,PJCJ,ZCJ);
selectsname,avg(Grade)PJCJ,sum(Grade)ZCJFROMstub,scorebwherescoreb.sno=stub.snogroupbystub.sname
6、查找各科成绩都>=85分的学生(Sname,Class);
wherestub.Sno=Scoreb.SnoandGrade>=85
7、将课程号为“01”的课程名称修改为“软件技术”;
updateCoursebsetCname='RJJS'whereCno=01
selectdistinct*fromCourseb
8、修改一名学生的姓名、性别、年龄;
updatestubsetSname='xuyiyang',sex='f',age='20'whereSno='0101'
9、将成绩为55~59分的男生的成绩修改为60分;
updateScorebsetGrade=60whereSnoin(SELECTSnoFROMStubwhereSex='m')ANDGradeBETWEEN55AND59;
10、删除年龄不是20的学生的所有信息(包括选课和成绩);
DELETEStubWHERES
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1