数据结构课程设计实习报告.docx
- 文档编号:24114710
- 上传时间:2023-05-24
- 格式:DOCX
- 页数:47
- 大小:26.15KB
数据结构课程设计实习报告.docx
《数据结构课程设计实习报告.docx》由会员分享,可在线阅读,更多相关《数据结构课程设计实习报告.docx(47页珍藏版)》请在冰豆网上搜索。
数据结构课程设计实习报告
球
#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 LinkNode(LinkNode {link=ptr;} LinkNode(constT&item,LinkNode {data=item;link=ptr;} }; template classList//单链表类 {protected: LinkNode public: List(){first=newLinkNode ~List(){makeEmpty();} voidmakeEmpty(); LinkNode voidinverse(); voidinput(TendTag); voidoutput(); voidUnion(List voidjishu(List voidoushu(List }; template voidList : makeEmpty() {LinkNode while(first->link! =NULL) {q=first->link; first->link=q->link; deleteq; } } template voidList : output() {LinkNode while(current! =NULL) {cout< current=current->link; } cout< } template voidList : input(TendTag){ LinkNode Tval; makeEmpty(); cin>>val;last=first; while(val! =endTag){ newNode=newLinkNode if(newNode==NULL){cerr<<"存储分配错误! "< (1);} last->link=newNode; last=newNode; cin>>val; } last->link=NULL; } template voidList : inverse(){ if(first==NULL)return; LinkNode while(p! =NULL){ r=p->link; p->link=pr; pr=p; p=r; } first->link=pr; } template voidList : Union(List { LinkNode LinkNode LinkNode 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 { Tvalue; LinkNode LinkNode last=first; p1=p1->link; while(p1! =NULL) { value=p1->data; p1=p1->link; if(value%2! =0) {last->link=newNode=newLinkNode last=last->link;} } last=first; } template voidList : oushu(List { Tvalue; LinkNode LinkNode last=first; p1=p1->link; while(p1! =NULL) { value=p1->data; p1=p1->link; if(value%2==0) {last->link=newNode=newLinkNode last=last->link;} } last=first; } #endif voidmain() { List 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() { SeqStack 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< 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<
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 课程设计 实习 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)