好好学习,天天向上,学科吧欢迎您!
当前位置:首页 >> 最新范文 内容页

《课程实验报告》

《课程实验报告》word版 本文关键词:课程,实验,报告,word

《课程实验报告》word版 本文简介:课程实验报告实验一STL的熟悉与使用实验名称实验一STL的熟悉与使用姓名汪子成系院专业信息工程系班级计算机15-1班学号2015216758实验日期指导教师徐本柱成绩一、实验目的和要求1.掌握C++中STL的容器类的使用;2.掌握C++中STL的算法类的使用.二、实验预习内容1.预习ICPC讲义,大

《课程实验报告》word版 本文内容:

课程实验报告

实验一

STL的熟悉与使用

实验名称

实验一

STL

的熟悉与使用

汪子成

系院专业

信息工程系

计算机15-1班

2015216758

实验日期

指导教师

徐本柱

一、实验目的和要求

1.掌握C++中STL的容器类的使用;

2.掌握C++中STL的算法类的使用.

二、实验预习内容

1.预习ICPC讲义,大致了解STL的相关内容。

2.了解STL中一些类

vector

list类的使用方法

3.了解泛型算法的使用

三、实验项目摘要

(1)

练习vector

和list

的使用。定义一个空的vector,元素类型为int,生成10

个随机数插入到vector

中,用迭代器遍历vector

并输出其中的元素值。在vector

头部插入一个随机数,用迭代器遍历vector并输出其中的元素值。用泛型算法find

查找某个随机数,如果找到便输出,否则将此数插入vector

尾部。用泛型算法sort

将vector

排序,用迭代器遍历vector

并输出其中的元素值。删除vector

尾部的元素,用迭代器遍历vector

并输出其中的元素值。将vector

清空。定义一个list,并重复上述实验,并注意观察结果。

(2)

练习泛型算法的使用。定义一个vector,元素类型为int,插入10

个随机数,使用sort

按升序排序,输出每个元素的值,再按降叙排序,输出每个元素的值。练习用find

查找元素。用min

和max

找出容器中的最小元素和最大元素,并输出。

四、实验结果与分析(源程序及相关说明)

1.

练习vector

和list

的使用:

#include

#include

#include

#include

#include

using

namespace

std;

vector

myV;

bool

sortup(int

v1,int

v2)

{

return

v1::iterator

it1;

for

(it1=myV.begin();it1!=myV.end();it1++)

{

coutmax)max=(*it1);

cout

#include

using

namespace

std;

typedef

list

lin;

int

value[]={1,6,7,8,9};

void

print(lin

lin::iterator

lit;

for(lit=l.begin();lit!=l.end();lit++)

coutv2;

}

int

main(){

lin

lin2;

lin2.push_front(3);

lin2.push_front(4);

lin2.insert(lin2.begin(),value,value+5);

cout

#define

N

8

#define

NUM

8

int

h[N][N],n[N],H[N][N];

int

count=0;

void

tryit(int,int);

void

outputArray(int[][N]);

main()

{

int

x=0,y=0,i,j;

for(i=0;i=0i=0)

tryit(x-1,n[x-1]+1);

else

tryit(0,0);

}

else

tryit(x,y+1);

}

}

}

}

void

outputArray(int

h[][N])

{

int

i,j;

for(i=0;i

int

board[8][8]

=

{0};

int

travel(int

x,int

y)

{

int

ktmove1[8]

=

{-2,-1,1,2,2,1,-1,-2};

int

ktmove2[8]

=

{1,2,2,1,-1,-2,-2,-1};

int

nexti[8]

=

{0};

int

nextj[8]

=

{0};

int

exists[8]

=

{0};

int

i,j,k,m,l;

int

tmpi,tmpj;

int

count,min,tmp;

i

=

x;

j

=

y;

board[i][j]

=

1;

for(m

=

2;

m

7

||

tmpj

>

7)

continue;

if(board[tmpi][tmpj]

==

0)

{

nexti[l]

=

tmpi;

nextj[l]

=

tmpj;

l++;

}

}

count

=

l;

if(count

==

0)

{

return

0;

}

else

if(count

==

1)

{

min

=

0;

}

else

{

for(l

=

0;

l

7

||

tmpj

>

7)

{

continue;

}

if(board[tmpi][tmpj]

==

0)

exists[l]++;

}

}

tmp

=

exists[0];

min

=

0;

for(l

=

1;

l

0。当(

p1

–p3

)

×

(

p4–p3

)

=

0

时,说明(

p1

p3

)

(

p4

p3

)共线,但是因为已经通过快速排斥试验,所以

p1

一定在线段

p3p4上;同理,(

p4

p3

)

×(p2

p3

)

=

0

说明

p2

一定在

p3p4上。所以判断p1p2跨立Q1Q2的依据是:(

p1

p3

)

×

(

p4

p3

)

(

p4

p3

)

×

(

p2–p3

)

>=

0。同理判断Q1Q2跨立P1P2的依据是:(

p3

-

p1

)

×

(

p2

-

p1

)

(

p2

-

p1

)

×

(

p4

-

p1

)

>=

0。代码中函数bool

segment_intersect()用于判断p1、p2构成的线段和p3、p4构成的线段是否相交。可以看出共五种情况两线段是相交的,反之就输出“The

two

are

Not

intersected!”

4.房间最短路问题:

#include

#include

#include

#include

using

namespace

std;

typedef

pair

POINT;

double

direction(POINT

p,POINT

p1,POINT

p2){

POINT

v1,v2;

v1.first=p2.first-p1.first;

v1.second=p2.second-p1.first;

v2.first=p1.first-p.first;

v2.second=p1.second-p.second;

return

v1.first*v2.second-v1.second*v2.second;}

bool

on_segment(POINT

p,POINT

p1,POINT

p2){

double

min_x=p1.firstp2.first?p1.first:p2.first;

double

min_y=p1.secondp2.second?p1.second:p2.second;

if(p.first>=min_x

if(d==0

if(d=

=0

return

false;

}

void

find_convex_hull(vector

int

k=0;

for(int

i=0;iconvex_hull;

do{

convex_hull.push_back(point[0]);

startPoint=point[0];

point.erase(point.begin());

sort(point.begin(),point.end(),sortByPolorAngle);

if(point[0]==convex_hull[0])break;

point.push_back(convex_hull[convex_hull.size()-1]);

}while(1);

for(int

j=0;j

pv;

double

x,y;

int

i;

cout:“>x>>y;

pv.push_back(make_pair(x,y));

}

cout

#include

using

namespace

std;

void

longest(string

s1,string

s2)

{

int

max,tep,i,j;

int

a[100][100];

for(i=0;i>s1;

cout>s2;

longest(s1,s2);

cout

#include

using

namespace

std;

int

min(int

x1,int

x2,int

x3)

{

if(x2>s1;

cout

>

s2;

change(s1,s2);

cout<

return

0;

}

24

TAG标签: