计算机软件实验报告文档格式.docx
- 文档编号:18914368
- 上传时间:2023-01-02
- 格式:DOCX
- 页数:23
- 大小:539.78KB
计算机软件实验报告文档格式.docx
《计算机软件实验报告文档格式.docx》由会员分享,可在线阅读,更多相关《计算机软件实验报告文档格式.docx(23页珍藏版)》请在冰豆网上搜索。
scanf("
%d"
&
nIn);
//std:
cin>
>
nIn;
nLinearList[i]=nIn;
nLen++;
}
LSort();
//排序线性表
LOut();
//输出结果
Pleaseinputadatatoinsert\n"
scanf("
LInsert(nIn);
//输入一个数字,并插入到线性表中
Pleaseinputadatatodelete\n"
LDelete(nIn);
//输入一个数字,并从线性表中删除
charchTmp;
Pleaseinputachartofinishthisprogram."
chTmp=getch();
//return0;
}
voidLSort()//冒泡排序,由大到小
intj,F,k,M;
F=(nLen-1);
while(F<
16)
k=F-1;
F=16;
for(j=0;
j<
=k;
j++)
{
if(nLinearList[j]<
nLinearList[j+1])
{
M=nLinearList[j];
nLinearList[j]=nLinearList[j+1];
nLinearList[j+1]=M;
F=j;
}
}
voidLOut()
printf("
\n"
nLen;
printf("
%d,"
nLinearList[i]);
voidLInsert(intn)
inti,j;
i=0;
while(i<
nLen)
if(nLinearList[i]<
=n)
nLen++;
for(j=nLen;
j>
=i;
j--)
nLinearList[j+1]=nLinearList[j];
nLinearList[i]=n;
break;
i++;
voidLDelete(intn)
for(i=0;
i<
nLen;
i++)
if(nLinearList[i]==n)
for(j=i;
(nLen-1);
nLen--;
运行结果:
实验二:
键盘输入算数表达式,并放入队列当中;
应用栈的概念设计表达式求值算法;
输出表达式求值结果;
程序清单:
//Experiment2.cpp:
string.h"
complex>
constintMAX_LEN=10;
//字符串的长度
constintMAX_SIZE=30;
//栈或队的最大元素个数
charpitem[10]={'
\0'
};
intnumbers=0;
//定义一个队列的结构
structQUEUE{
intnMaxSize;
intnCount;
//个数
intnFront;
//头
intnRear;
//尾
charszQueue[MAX_SIZE][MAX_LEN];
//定义一个栈的结构
structSTACK{
intnTop;
//栈顶
charszStack[MAX_SIZE][MAX_LEN];
//队列的操作
voidInitQueue(QUEUE*q,intnMaxSize);
intInQueue(QUEUE*q,char*pItem);
intOutQueue(QUEUE*q,char*pItem);
//栈的操作
voidInitStack(STACK*s,intnMaxSize);
intPushStack(STACK*s,char*pItem);
intPopStack(STACK*s,char*pItem);
voidGetTopStack(STACK*s,char*pItem);
intPriority(char*op);
//获得操作符的优先级
voidCompute(char*num1,char*num2,char*op,char*chResult);
//计算表达式的值
intisdigit(charisnum);
intmain()
//声明一个队列
structQUEUEque;
InitQueue(&
que,MAX_SIZE);
//声明OS栈和NS栈
structSTACKOS,NS;
InitStack(&
OS,MAX_SIZE);
NS,MAX_SIZE);
//输入表达式,并放入到队列当中
Pleaseinputexpression.\n"
do
for(intj=0;
10;
pitem[j]='
gets(pitem);
InQueue(&
que,pitem);
}while(pitem[0]!
='
'
//显示表达式
printf("
%s"
que.szQueue[numbers]);
numbers++;
}while(que.szQueue[numbers][0]!
//表达式求值
charx[MAX_LEN];
//扫描的表达式
charop[MAX_LEN];
//栈顶运算符
charnum1[MAX_LEN],num2[MAX_LEN];
//两个操作数
charchResult[MAX_LEN];
//运算结果
OutQueue(&
que,x);
//扫描表达式
PushStack(&
OS,"
"
//;
压栈
while
(1)
if(isdigit(x[0]))//是数
PushStack(&
NS,x);
//数字压栈
else//认为是运算符,没有考虑空格等
GetTopStack(&
OS,op);
//获得OS栈顶运算符
if(Priority(x)>
Priority(op))//运算符的优先级〉栈顶运算符
PushStack(&
OS,x);
//高优先级运算符压栈
if(x[0]=='
&
&
op[0]=='
)//扫描结束
break;
if(Priority(x)<
=Priority(op))//不大于栈顶运算符
{
PopStack(&
OS,op);
NS,num2);
NS,num1);
Compute(num1,num2,op,chResult);
NS,chResult);
continue;
OutQueue(&
=%s\n"
chResult);
system("
pause"
return0;
voidInitQueue(QUEUE*q,intnMaxSize)
q->
nMaxSize=nMaxSize;
nCount=0;
nFront=0;
nRear=0;
for(inti=0;
30;
i++)
q->
szQueue[i][j]='
intInQueue(QUEUE*q,char*pItem)
if(q->
nFront>
nMaxSize)
列队已满,不能插入!
return0;
else
strcpy(q->
szQueue[q->
nFront],pItem);
q->
nFront++;
return1;
intOutQueue(QUEUE*q,char*pItem)
nRear>
nFront)
列队已空,不能出队!
strcpy(pItem,q->
nRear]);
nRear++;
voidInitStack(STACK*s,intnMaxSize)
s->
nTop=0;
s->
szStack[i][j]='
intPushStack(STACK*s,char*pItem)
if(s->
nTop>
栈已满,不能插入!
strcpy(s->
szStack[s->
nTop],pItem);
s->
nTop++;
intPopStack(STACK*s,char*pItem)
nTop<
0)
strcpy(pItem,s->
nTop-1]);
nTop--;
voidGetTopStack(STACK*s,char*pItem)
strcpy(pItem,s->
intisdigit(charisnum)
switch(isnum)
case'
^'
*'
/'
+'
-'
default:
intPriority(char*op)
intnPriority=0;
switch(op[0])
nPriority=3;
break;
nPriority=2;
nPriority=1;
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);
//把计算的结果转化为字符串
return;
实验三:
查询学生出生日期(Sno,Sname,BirthDay);
按学号顺序查询一个班级的所有学生(Class,Sname);
列出学生选择各门课程的成绩(Sname,Cname,Grade);
列出有过不及格成绩的学生名单(Sno,Sname,Class);
求学生的平均成绩和总成绩(Sname,PJCJ,ZCJ);
查找各科成绩都>
=85分的学生(Sname,Class);
将课程号为“01”的课程名称修改为“软件技术”;
修改一名学生的姓名、性别、年龄;
将成绩为55~59分的男生的成绩修改为60分;
删除90年以后、80年以前出生的学生的所有信息(包括选课和成绩);
删除一个班级的所有学生;
删除所有数据表和数据库。
程序清单及结果:
1.创建数据库MyDB
IFEXISTS(SELECT*
FROMmaster..sysdatabases
WHEREname=N'
database_name,sysname,test_db>
)
DROPDATABASEMyDB;
GO
CREATEDATABASEMYDB;
2.创建对象:
Stu,Course,Score。
CREATETABLEStu(
SnoCHAR(4)PRIMARYKEY,
SnameCHAR(10),
SexCHAR
(2),
AgeNUMERIC,
BirthDayDATETIME,
ClassCHAR(10),
CREATETABLECourse(
CnoCHAR
(2)PRIMARYKEY,
CnameCHAR(10),
ChourNUMERIC,
CREATETABLEScore(
SnoCHAR(4),
CnoCHAR
(2),
PRIMARYKEY(Sno,Cno),
GradeNUMERIC,
3.插入信息
InsertintoStu(Sno,Sname,Sex,Age,BirthDay,Class)
values('
2561'
'
王五'
wm'
10'
1990-03-30'
电子1002'
2562'
'
李四'
m'
21'
1992-03-23'
电子1001'
2563'
陈七'
25'
1987-05-14'
2564'
赵八'
20'
1993-12-24'
2565'
陆游'
1978-12-5'
SelectSno,Sname,Sex,Age,BirthDay,ClassfromStu;
InsertintoCourse(Cno,Cname,Chour)
01'
语文'
32'
02'
数学'
64'
03'
英语'
40'
SelectCno,Cname,ChourfromCourse;
InsertintoScore(Sno,Cno,Grade)
2567'
97'
2568'
54'
2569'
56'
2560'
88'
87'
79'
68'
58'
98'
SelectSno,Cno,GradefromScore;
1.查询学生出生日期(Sno,Sname,BirthDay);
SelectSno,Sname,BirthDayfromStu;
2.按学号顺序查询一个班级的所有学生(Class,Sname);
SelectClass,SnamefromStuorderbySno;
3.列出学生选择各门课程的成绩(Sname,Cname,Grade);
SelectSname,Cname,GradefromStu,Course,Score
whereStu.Sno=Score.SnoandCourse.Cno=Score.Cno;
4.列出有过不及格成绩的学生名单(Sno,Sname,Class);
SelectdistinctStu.Sno,Sname,ClassfromStu,Score
whereStu.Sno=Score.SnoandGrade<
60;
5.求学生的平均成绩和总成绩(Sname,数学,英语);
SelectSname,avg(Grade)数学,sum(Grade)英语fromStu,ScorewhereScore.Sno=Stu.SnogroupbyStu.Sname;
6.查找各科成绩都>
SelectSname,ClassfromStuwhereexists(Select*fromScorewhereStu.Sno=Score.SnoandScore.Cno='
andScore.Grade>
=85)
andexists(Select*fromScorewhereStu.Sno=Score.SnoandScore.Cno='
=85)
=85);
7.将课程号为“01”的课程名称修改为“软件技术”
UpdateCoursesetCname='
软件技术'
whereCno='
SelectCno,CnamefromCourse;
8.修改一名学生的姓名、性别、年龄;
UpdateStusetSname='
张三'
Sex='
age='
22'
whereSno='
SelectSno,Sname,Sex,agefromStuorderbySno;
9.将成绩为55~59分的男生的成绩修改为60分
UpdateScoresetGrade=60whereSnoin(SelectSnofromStuwhere
Sex='
)andGra
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机软件 实验 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)