数据结构课程设计实习报告.docx

上传人:b****1 文档编号:10256098 上传时间:2023-05-24 格式:DOCX 页数:47 大小:26.15KB
下载 相关 举报
数据结构课程设计实习报告.docx_第1页
第1页 / 共47页
数据结构课程设计实习报告.docx_第2页
第2页 / 共47页
数据结构课程设计实习报告.docx_第3页
第3页 / 共47页
数据结构课程设计实习报告.docx_第4页
第4页 / 共47页
数据结构课程设计实习报告.docx_第5页
第5页 / 共47页
数据结构课程设计实习报告.docx_第6页
第6页 / 共47页
数据结构课程设计实习报告.docx_第7页
第7页 / 共47页
数据结构课程设计实习报告.docx_第8页
第8页 / 共47页
数据结构课程设计实习报告.docx_第9页
第9页 / 共47页
数据结构课程设计实习报告.docx_第10页
第10页 / 共47页
数据结构课程设计实习报告.docx_第11页
第11页 / 共47页
数据结构课程设计实习报告.docx_第12页
第12页 / 共47页
数据结构课程设计实习报告.docx_第13页
第13页 / 共47页
数据结构课程设计实习报告.docx_第14页
第14页 / 共47页
数据结构课程设计实习报告.docx_第15页
第15页 / 共47页
数据结构课程设计实习报告.docx_第16页
第16页 / 共47页
数据结构课程设计实习报告.docx_第17页
第17页 / 共47页
数据结构课程设计实习报告.docx_第18页
第18页 / 共47页
数据结构课程设计实习报告.docx_第19页
第19页 / 共47页
数据结构课程设计实习报告.docx_第20页
第20页 / 共47页
亲,该文档总共47页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

数据结构课程设计实习报告.docx

《数据结构课程设计实习报告.docx》由会员分享,可在线阅读,更多相关《数据结构课程设计实习报告.docx(47页珍藏版)》请在冰点文库上搜索。

数据结构课程设计实习报告.docx

数据结构课程设计实习报告

#include

#include

classPoint{//二维坐标点类

protected:

doublex,y,z;

public:

Point(){x=0;y=0;z=0;}//缺省构造函数

Point(doublepx,doublepy,doublepz){x=px;y=py;z=pz;}//带参数的构造函数

doubleGetx(){returnx;}//返回坐标点的x值

doubleGety(){returny;}//返回坐标点的y值

doubleGetz(){returnz;}

voidMove(doublemx,doublemy,doublemz){x=mx;y=my;z=mz;}//移动坐标点的位置

voidShow(){cout<<"x="<

};

classTriangle:

publicPoint{//矩形类(Point的派生类,Point对象为矩形左下角的坐标点)

doubleradius;//矩形的宽度和高度

public:

Triangle(){x=0;y=0;z=0;radius=0;}//缺省构造函数

Triangle(doublea,doubleb,doublec,doubled):

Point(a,b,c){//带参数的构造函数

radius=d;

}

Triangle(Point&pn):

Point(pn){//带参数的构造函数,由点pn定义矩形左下角的位置

radius=1;

}

doubleVolume(){return3.14*4/3*radius*radius*radius;}//求矩形的面积

doubleArea(){return4*3.14*radius*radius;}

voidSet(doublea,doubleb,doublec){x=a;y=b;z=c;}//重置矩形的左下角坐标

intPosition(Point&pt);//求点pt相对于矩形的位置,返回-1(在矩形内),

//0(在矩形边上)和1(在矩形外)

voidJudge(Point&pt);//判断点pt相对于矩形的位置,给出提示

voidShow();//输出矩形的各属性值和面积

};

intTriangle:

:

Position(Point&pt){//求点pt相对于矩形的位置

if(sqrt((pt.Getx()-x)*(pt.Getx()-x)+(pt.Gety()-y)*(pt.Gety()-y)+(pt.Getz()-z)*(pt.Getz()-z))>radius)return1;//在矩形外

elseif(sqrt((pt.Getx()-x)*(pt.Getx()-x)+(pt.Gety()-y)*(pt.Gety()-y)+(pt.Getz()-z)*(pt.Getz()-z))

elsereturn0;//在矩形边上

}

voidTriangle:

:

Judge(Point&pt){

pt.Show();

Show();

switch(Position(pt)){

case0:

cout<<"点在圆边上"<

case-1:

cout<<"点在圆内"<

case1:

cout<<"点在圆外"<

}

}

voidTriangle:

:

Show(){//输出矩形的各属性值和面积

cout<<"rx="<

cout<<"radius="<

cout<<"area="<

cout<<"volume"<

}

voidmain(){

Trianglert1(0,0,0,8),rt2,rt3(rt1);//定义Rectangle对象

Pointp1(0,0,0),p2(1,2,3),p3(5,7,9);//定义Point对象

cout<<"描述rt1如下:

"<

rt1.Show();//输出矩形rt1的属性值

cout<<"描述rt2如下:

"<

rt2.Show();//输出矩形rt2的属性值

rt1.Set(3,5,7);//重置矩形rt1左下角的位置

rt2=rt1;//rt2复制矩形rt1

cout<<"rt2复制圆rt1并描述"<

rt2.Show();

cout<<"点p1和圆rt3并描述:

"<

rt3.Judge(p1);//判断点p1相对于矩形rt3的位置

rt3.Set(9,7,5);//重置矩形rt3左下角的位置

cout<<"点p2和圆rt3并描述:

"<

rt3.Judge(p2);//判断点p2相对于矩形rt3的位置

cout<<"由p3定义的圆rt4并描述:

"<

Trianglert4(p3);//由p3定义的矩形rt4

rt4.Show();

}

单链表

#ifndefLINKNODE_H

#defineLINKNODE_H

#include

#include"Linknode.h"

#include

template//结点类

structLinkNode

{Tdata;

LinkNode*link;

LinkNode(LinkNode*ptr=NULL)

{link=ptr;}

LinkNode(constT&item,LinkNode*ptr=NULL)

{data=item;link=ptr;}

};

template

classList//单链表类

{protected:

LinkNode*first;

public:

List(){first=newLinkNode;}

~List(){makeEmpty();}

voidmakeEmpty();

LinkNode*getHead()const{returnfirst;}

voidinverse();

voidinput(TendTag);

voidoutput();

voidUnion(List&LA,List&LB);

voidjishu(List&L);

voidoushu(List&L);

};

template//置空

voidList:

:

makeEmpty()

{LinkNode*q;

while(first->link!

=NULL)

{q=first->link;

first->link=q->link;

deleteq;

}

}

template//输出

voidList:

:

output()

{LinkNode*current=first->link;

while(current!

=NULL)

{cout<data<<"";

current=current->link;

}

cout<

}

template//后插法建立

voidList:

:

input(TendTag){

LinkNode*newNode,*last;

Tval;

makeEmpty();

cin>>val;last=first;

while(val!

=endTag){

newNode=newLinkNode(val);

if(newNode==NULL){cerr<<"存储分配错误!

"<

(1);}

last->link=newNode;

last=newNode;

cin>>val;

}

last->link=NULL;

}

template//自身逆序

voidList:

:

inverse(){

if(first==NULL)return;

LinkNode*p=first->link,*pr=NULL,*r;

while(p!

=NULL){

r=p->link;

p->link=pr;

pr=p;

p=r;

}

first->link=pr;

}

template//合并

voidList:

:

Union(List&LA,List&LB)

{

LinkNode*p1=LA.getHead();

LinkNode*p2=LB.getHead();

LinkNode*last;

last=first;

p1=p1->link;p2=p2->link;

while(p1!

=NULL&&p2!

=NULL)

{

last->link=p1;

p1=p1->link;

last=last->link;

last->link=p2;

p2=p2->link;

last=last->link;

}

while(p1!

=NULL)

{

last->link=p1;

p1=p1->link;

last=last->link;

}

while(p2!

=NULL)

{

last->link=p2;

p2=p2->link;

last=last->link;

}

last=NULL;

}

template//拆分出奇数

voidList:

:

jishu(List&L)

{

Tvalue;

LinkNode*p1=L.getHead();

LinkNode*newNode,*last;

last=first;

p1=p1->link;

while(p1!

=NULL)

{

value=p1->data;

p1=p1->link;

if(value%2!

=0)

{last->link=newNode=newLinkNode(value);

last=last->link;}

}

last=first;

}

template//拆分出偶数

voidList:

:

oushu(List&L)

{

Tvalue;

LinkNode*p1=L.getHead();

LinkNode*newNode,*last;

last=first;

p1=p1->link;

while(p1!

=NULL)

{

value=p1->data;

p1=p1->link;

if(value%2==0)

{last->link=newNode=newLinkNode(value);

last=last->link;}

}

last=first;

}

#endif

voidmain()

{

Listlist1,list2,list3,list4,list5;

cout<<"输入链表1,并以‘0’为结束符:

"<

list1.input(0);

cout<<"输入链表2,并以‘0’为结束符:

"<

list2.input(0);

list3.Union(list1,list2);

cout<<"输出合并后的链表3:

"<

list3.output();

list3.inverse();

cout<<"输出逆序后的链表3:

"<

list3.output();

list4.jishu(list3);

cout<<"输入拆分后的奇数链表4:

"<

list4.output();

list5.oushu(list3);

cout<<"输入拆分后的偶数链表5:

"<

list5.output();

}

中缀转后缀

#ifndefSEQSTACK_H

#defineSEQSTACK_H

#include

#include

constintstackIncreament=20;

template

classSeqStack

{//顺序栈类定义

private:

T*elements;

inttop;

intmaxSize;

voidoverflowProcess();

public:

SeqStack(intsz=50);

~SeqStack(){delete[]elements;}

voidPush(constT&x);

boolPop(T&x);

boolgetTop(T&x);

boolIsEmpty()const

{return(top==-1)?

true:

false;}

boolIsFull()const

{return(top==maxSize-1)?

true:

false;}

intgetSize()const{returntop+1;}

voidMakeEmpty(){top=-1;};

voidpostfix(charx);

boolisdigit(Tx)const;

intisp(charx);

inticp(charx);

};

template

SeqStack:

:

SeqStack(intsz)//构造函数

{

top=-1;

maxSize=sz;

elements=newT[maxSize];

assert(elements!

=NULL);

}

template

voidSeqStack:

:

overflowProcess()

//私有函数:

当栈满则执行扩充栈存储空间处理

{

T*newArray=newT[maxSize+stackIncreament];

if(newArray==NULL)

{cerr<<"存储分配失败!

"<

(1);}

for(inti=0;i<=top;i++)

newArray[i]=elements[i];

maxSize=maxSize+stackIncreament;

delete[]elements;

elements=newArray;

}

template//进栈

voidSeqStack:

:

Push(constT&x)

{

if(IsFull()==true)

overflowProcess();

elements[++top]=x;

}

template//退栈

boolSeqStack:

:

Pop(T&x)

{

if(IsEmpty()==true)

returnfalse;

x=elements[top--];

returntrue;

}

template//取栈顶

boolSeqStack:

:

getTop(T&x)

{

if(IsEmpty()==true)

returnfalse;

x=elements[top];

returntrue;

}

template//转换函数

voidSeqStack:

:

postfix(charx)

{

charch='#',ch1,op;

Push(ch);cin.get(ch);

while(IsEmpty()==false)

{

if(isdigit(ch))

{

cout<

cin.get(ch);

}

else

{

getTop(ch1);

if(isp(ch1)

{

Push(ch);

cin.get(ch);

}

elseif(isp(ch1)>icp(ch))

{

Pop(op);

cout<

}

else

{

Pop(op);

if(op=='(')

cin.get(ch);

}

}

}

}

template//判断函数

boolSeqStack:

:

isdigit(Tx)const

{

if(x>='A'&&x<='z')

returntrue;

elsereturnfalse;

}

template//栈内优先规定

intSeqStack:

:

isp(charx)

{

inttemp;

switch(x)

{case'#':

temp=0;break;

case'(':

temp=1;break;

case'*':

case'/':

case'%':

temp=5;break;

case'+':

case'-':

temp=3;break;

case')':

temp=6;break;

}

returntemp;

}

template//栈外优先规定

intSeqStack:

:

icp(charx)

{

inttemp;

switch(x)

{case'#':

temp=0;break;

case'(':

temp=6;break;

case'*':

case'/':

case'%':

temp=4;break;

case'+':

case'-':

temp=2;break;

case')':

temp=1;break;

}

returntemp;

}

#endif

voidmain()

{

SeqStacks;

cout<<"请输入中缀表达式,并以‘#’为结束符:

"<

s.postfix('#');

cout<

}

通讯本

#include

#include

#include

#include

#include

#include

#include

#include"mybook.h"

voidmain()

{

Phonebookphon1;

structitemnewitem;

charsearchname[30];

//chardailname[30];

intselect,find;

structitem*p;

intisthere;

while

(1)

{

system("cls");

isthere=0;

cout<

cout<

cout<

**"<

cout<

cout<

**"<

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cout<

";

cin>>select;cout<

switch(select)

{

case1:

phon1.additem(newitem);

break;

case2:

cout<

请选择(A.亲人B.朋友C.同学)";

charsel;

cout<>sel;

phon1[sel];

break;

case3:

phon1.showname();break;

case4:

cout<

";

cin>>searchname;

p=phon1.head;

while(p!

=NULL)

{

if(strcmp(p->name,searchname)==0)

{

isthere=1;

break;

}

p=p->next;

}

if(isthere==0)

{

cout<

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2