c语言栈的应用实验报告,c语言实验报告3.doc

44cb7578e1df5412b94317daaa3307ba.gifc语言实验报告3.doc

计算机软件技术基础实验报告实验一:线性表的排序与查找 一实验内容a) 键盘输入一组无序数据,添加到线性表中;b) 排序线性表并输出排序结果;c) 键盘输入一个数,并插入到排好序的线性表中(要求插入后的表仍为有序表),输出结果;d) 键盘输入一个数,并从线性表中删除相应的数据,输出结果。二,源程序/ Experiment1.cpp : 定义控制台应用程序的入口点。/#include stdafx.h#include iostream#include / 程序实现有各种方法,这里给出一个实例。/ 定义一个线性表const int nMaxSize = 15;/ 最大值int nLen = 0;/ 表中元素个数int nLinearListnMaxSize;/ 定义操作void LSort();void LOut();void LInsert(int n);void LDelete(int n);int main(int argc,TCHAR*argv)/ 输入数据并放入线性表中printf(Please input datan);/ std:cout nIn;nLinearListi = nIn;nLen+;LSort();/ 排序线性表LOut();/ 输出结果printf(Please input a data to insert n);scanf(%d,&nIn);LInsert(nIn);/ 输入一个数字,并插入到线性表中LOut();printf(Please input a data to delete n);scanf(%d,&nIn);LDelete(nIn);/ 输入一个数字,并从线性表中删除LOut();char chTmp;printf(Please input a char to finish this program.);chTmp = getch();return 0;void LSort()/ 冒泡排序,由大到小int j,F,k,M; F=nLen;while(F0) k=F-1;F=0;for(j=1;j=i;j-)nLinearListj+1=nLinearListj;nLinearListi=n;break;i+;void LDelete(int n)int i,j;for(i=1;i#include #include / 程序实现有各种方法,这里给出一个实例。const int MAX_LEN = 10;/ 字符串的长度const int MAX_SIZE = 30;/ 栈或队的最大元素个数/ 定义一个队列的结构struct QUEUE int nMaxSize;/ 最大值int nCount;/ 个数int nFront;/ 头int nRear;/ 尾char szQueueMAX_SIZEMAX_LEN;/定义一个栈的结构struct STACK int nMaxSize;/ 最大值int nTop;/ 栈顶char szStackMAX_SIZEMAX_LEN;/ 队列的操作void InitQueue(QUEUE *q,int nMaxSize)q-nMaxSize=nMaxSize;q-nCount=0;q-nFront=0;q-nRear=0;q-szQueueMAX_SIZEMAX_LEN=0;void InQueue(QUEUE *q, char *pItem)if(q-nCount=q-nMaxSize)printf(The Queue is full!n);return;strcpy(q-szQueueq-nRear,pItem);if(q-nRear+=MAX_SIZE)q-nRear=0;q-nCount+;void OutQueue(QUEUE *q, char *pItem)if(q-nCount=0)printf(The Queue is empty!n);return;strcpy(pItem,q-szQueueq-nFront);if(q-nFront+=MAX_SIZE)q-nFront=0;q-nCount-;/栈的操作void InitStack(STACK *s,int nMaxSize)s-nMaxSize=nMaxSize;s-nTop=0;s-szStackMAX_SIZEMAX_LEN=0;void PushStack(STACK *s, char *pItem)char *p;if (s-nTopnMaxSize)p=s-szStacks-nTop;strcpy(p,pItem);s-nTop+;elseprintf(The stack overflow!n);return;void PopStack(STACK *s, char *pItem)char *p;if (s-nTop=0)printf(stack is empty!n);return;elsep=s-szStack-s-nTop;strcpy(pItem,p);void GetTopStack(STACK *s, char *pItem)char *p;char a10=0;if (s-nTop=0)a0=;strcpy(pItem,a);elsep=s-szStacks-nTop-1;strcpy(pItem,p);/字符判断int isdigit(char x)if (x=0&xnCount!=0)OutQueue(q, x);printf(%s,x);if (isdigit(x0)/ 是数 PushStack(n,x);else/ 认为是运算符,没有考虑空格等GetTopStack(o,op);/ 获得OS栈顶运算符if (x0 = ; & op0 = ;)/ 扫描结束 printf(n result is );break;if (Priority(x) Priority(op)/ 运算符的优先级栈顶运算符PushStack(o,x);continue;while (Priority(x) = 85 分的学生(Sname, Class);将课程号为“01”的课程名称修改为“软件技术”;修改一名学生的姓名、性别、年龄;将成绩为5559分的男生的成绩修改为60分;删除90年以后、80年以前出生的学生的所有信息(包括选课和成绩);删除一个班级的所有学生;删除所有数据表和数据库。二 程序清单及结果:CREATE TABLE Stu(Sno CHAR(4)PRIMARY KEY,Sname CHAR(10),Sex CHAR(2),Age NUMERIC,BirthDay DATETIME,Class CHAR(10),);CREATE TABLE Course(Cno CHAR(2)PRIMARY KEY,Cname CHAR(10),Chour NUMERIC,);CREATE TABLE Score(Sno CHAR(4),Cno CHAR(2),PRIMARY KEY(Sno,Cno),Grade NUMERIC,)Insert into Stu(Sno,Sname,Sex,Age,BirthDay,Class)values (3626,张小唯,女,18,1995-09-24,电科1202);Insert into Stu(Sno,Sname,Sex,Age,BirthDay,Class)values (3628,王红,女,19,1994-06-27,电科1202);Insert into Stu(Sno,Sname,Sex,Age,BirthDay,Class)values (3634,李雷,男,20,1992-11-30,电科1202);Insert into Stu(Sno,Sname,Sex,Age,BirthDay,Class)values (3635,张明,男,18,1994-06-03,电科1202);Insert into Stu(Sno,Sname,Sex,Age,BirthDay,Class)values (3641,赵小东,男,20,1993-03-15,电科1202);Insert into Course (Cno,Cname,Chour)values (01,asdf,12);Insert into Course (Cno,Cname,Chour)values (02,qwer,23);Insert into Course (Cno,Cname,Chour)values (03,zxcv,34Insert into Score (Sno,Cno,Grade)values (3570,01,97);Insert into Score (Sno,Cno,Grade)values (3580,01,54);Insert into Score (Sno,Cno,Grade)values (3584,01,56);Insert into Score (Sno,Cno,Grade)values (3583,01,88);Insert into Score (Sno,Cno,Grade)values (3574,02,87);Insert into Score (Sno,Cno,Grade)values (3575,03,79);Insert into Score (Sno,Cno,Grade)values (3576,02,68);Insert into Score (Sno,Cno,Grade)values (3577,03,58);Insert into Score (Sno,Cno,Grade)Values (3578,03,98);Insert into Score (Sno,Cno,Grade)values (3626,01,97);Insert into Score (Sno,Cno,Grade)values (3628,01,54);Insert into Score (Sno,Cno,Grade)values (3637,01,56);Insert into Score (Sno,Cno,Grade)values (3640,01,88);Insert into Score (Sno,Cno,Grade)values (3657,02,87);Insert into Score (Sno,Cno,Grade)values (3675,03,79);Insert into Score (Sno,Cno,Grade)values (3676,02,68);Insert into Score (Sno,Cno,Grade)values (3677,03,58);Insert into Score (Sno,Cno,Grade)Values (3678,03,98);1. 查询学生出生日期(Sno, Sname, BirthDay);Select Sno,Sname,BirthDay from Stu;2.按学号顺序查询一个班级的所有学生(Class, Sname);Select Class,Sname from Stu order by Sno;3.列出学生选择各门课程的成绩(Sname, Cname, Grade) ;Select Sname,Cname,Grade from Stu,Course,Score where Stu.Sno=Score.Sno and Course.Cno=Score.Cno;4.列出有过不及格成绩的学生名单(Sno, Sname, Class);Select distinct Stu.Sno,Sname,Class from Stu,Score where Stu.Sno=Score.Sno and Grade= 85 分的学生(Sname, Class);Select Sname,Class from Stu where exists (Select * from Score where Stu.Sno=Score.Sno and Score.Cno=01 and Score.Grade=85)and exists(Select * from Score where Stu.Sno=Score.Sno and Score.Cno=02 and Score.Grade=85 )and exists(Select * from Score where Stu.Sno=Score.Sno and Score.Cno=03 and Score.Grade=85 ) ;7. 将课程号为“01”的课程名称修改为“软件技术”Update Course set Cname=软件技术 where Cno=01;8.修改一名学生的姓名、性别、年龄;Update Stu set Sname=aha,Sex=wm,age=10where Sno=3626;9.将成绩为5559分的男生的成绩修改为60分Update Score set Grade=60 where Sno in(Select Sno from Stu whereSex=女) and Grade between 55 and 59;10.删除90年以后、80年以前出生的学生的所有信息(包括选课和成绩)Delete Stu where Sno in(select Sno from Stu where BirthDay 1990-12-31)11.删除一个班级的所有学生Delete from Stu where Class=电科1202;12. 删除所有数据表和数据库Drop database MyDB;部分内容来源于网络,有侵权请联系删除

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值