(实验报告模板)实验二数据库

实验报告

学院(系)名称:计算机与通信工程学院

【实验过程记录(源程序、测试用例、测试结果及心得体会等)】

2、

1)update SC set Grade=Grade-5 where '数据库'=

(select Cname from Course where  SC.Cno=Course.Cno)

select * from SC;

2)update SC set Grade =0 where 'CS'=

(select Sdept from Student Where Student.Sno=SC.Sno and  '2'=

(select Cno from Course where Course.Cno=SC.Cno))

select * from SC;

3)update SC set Grade=85 where '李勇'=

(select Sname from Student where Student.Sno=SC.Sno and '数据库'=

(select Cname from Course where Course.Cno=SC.Cno))

select * from SC;

4)delete from SC where Cno=2 and Grade=NUll;

select  * from SC;

5)delete from Course where Cno not in (select Cno from SC);

select * from Course;

6)delete from SC where 'CS'=

(select Sdept from Student where Student.Sno=SC.Sno and '数据库'=

(select Cname from Course where Course.Cno=SC.Cno));

select * from SC;

7)create table Ssexcount(Sdept char(20),Ssex char(2),Scount smallint)

insert into Ssexcount(Sdept,Ssex,Scount)

select Sdept,Ssex,COUNT(Sno) from Student group by Sdept,Ssex;

select * from Ssexcount; Select * from Student;

8)create table Snocno(Sno char(9),Coursecount smallint,Savg float)

insert into Snocno(Sno,Coursecount,Savg)

select Sno,COUNT(Cno),AVG(Grade) from SC group by sno having avg(grade)>=80; select*from Snocno; select * from sc;

9)create view IS_Student(Sno,Sname,Sdept)as select Sno,Sname,Sdept from Student

 where not exists(select * from SC where Sno=Student.Sno);  select * from IS_Student;

10)create view IS_S2(Sname,Cname,Grade)

 as select Sname,Cname,Grade from Student,Course,SC

 where Student.Sno=SC.Sno and Course.Cno=SC.Cno;

 select * from IS_S2;

11)create view IS_S3(Cno,Ccount,Avggrade,Maxgrade)

 as select Cno,COUNT(Sno),AVG(Grade),MAX(Grade)

 from SC group by Cno;

 select Ccount,Avggrade,Maxgrade from IS_S3 where Cno='1';

select Ccount,Avggrade,Maxgrade from IS_S3 where Cno='3';

12)create view IS_S4(Cno,Grade) as select Cno,Grade from SC

 where Cno='2' and Grade> (select avg(Grade) from SC where Cno='2');  select * from IS_S4;

13)create role user1  grant select on Student to user1;

14)revoke select on Student from user1;

 

第二篇:实验报告_实验14 标准模板库 STL(1)

实验报告_实验14 标准模板库 STL(1)(学

生学号_姓名)

实验目的:

1、理解标准模板库STL的基本概念:容器、迭代器和算法;

2、熟悉顺序容器:vector、list和deque的基本用法;

3、熟悉函数对象的概念、基本应用。

实验内容

1、(基础题)请分析、运行下列程序代码,回答相关问题,体会vector用法:

(1)代码1

问题:

1) 创建vector对象常有哪些方法?

答:用 vector <类型> 对象名 创建。

2) 写出访问vcctor元素的4种不同方法;

答:使用迭代器访问。 用数组的形式访问。

3) 如何在vector尾部插入元素?

答:使用迭代器名.push_back()函数。

2、(基础题)请根据题意,填写程序所缺代码,并运行、验证: 答:

(1):int i=0

(2):i<_str.size()

(3):i++

(4):_str[i]

(5):vec1.begin()

(6):vec1.end()

(7):erase(vec1.begin(),vec1.end())

(8):erase(vec2.end()-1)

3、(基础题)请分析、运行下列程序代码,回答相关问题,体会list用法: 问题:

1) 如何创建list对象?

答:list<类型 对象名;

2) 怎样访问list元素?

答:使用迭代器访问

3) 如何将list排序?

答:使用 list对象.sort()函数。

4.

#include<list>

#include<iostream>

using namespace std;

void main()

{

int i,t;

int temp[30];

for(i=0;i<30;i++)

temp[i]=1;

list<int> go;

go.clear();

for(i=0;i<30;i++)

go.push_back(i);

list<int>::iterator g = go.begin();

while(go.size()>15)

{

for(i=1;i<9;++i)

{

++g;

if(g==go.end())

g=go.begin();

}

t=*g;

temp[t]=0;

g=go.erase(g);

} } if(g==go.end()) g=go.begin(); cout<<"1:基督徒\n2:非基督徒\n"; cout<<"当初的排列顺序为:\n"; for(i=0;i<30;i++) { static int c=0; ++c; cout<<temp[i]<<" "; if(c%5==0) cout<<" "; } cout<<endl;

相关推荐