软件工程数据结构实验指导书.docx
- 文档编号:30327397
- 上传时间:2023-08-13
- 格式:DOCX
- 页数:31
- 大小:29.67KB
软件工程数据结构实验指导书.docx
《软件工程数据结构实验指导书.docx》由会员分享,可在线阅读,更多相关《软件工程数据结构实验指导书.docx(31页珍藏版)》请在冰豆网上搜索。
软件工程数据结构实验指导书
给大家的实验文档中分为一下几部分
1.实验准备:
其中是c++的一些内容,希望大家能借此好好复习c++。
因为大家现在使用的教材是c++版本的,所以,对于c++的一些基本语法,程序的编写都需要有些了解
2.c语言实验教案中是一些c语言的基础知识,包括VC环境的使用和程序的调试,希望对c语言已经忘记的同学好好看看复习一下。
(程序的编写调试是长年累月的过程,需要不断的积累,写得多了,程序调试的多了,自然就熟练了)
3.对应的flash课件:
其中是一些实验的flash课件演示,给大家做一下参考
4.实验指导书和实验教案大家在做每个实验前都需要看看。
阅读的时候,可以使用【视图】|【文档结构图】,可以比较自由跳到相应位置
5.总体实验难度比较大,时间紧,单靠实验课上的几个学时,作为初学者是无法完成的,需要大家在课前课后尽自己最大的努力。
实验一栈和队列(2学时)
实验二多项式加减法(2学时)
实验三迷宫(4学时)
实验四二叉树(4学时)
实验五图(2学时)
实验六归并排序(2学时)
ProgrammingProjectone:
ApplicationofStack&Queue
一、实验目的
通过几段代码的编写,熟悉栈和队列
二、实验内容
1、Reversingalist(必做,分3个小题目task1,task2,task3)
2、Smallairportsimulation(选作)
具体如下:
Task1:
Compileandrunthefollowingsampleapplicationofstackfromthetext.Youmayneedtomakechangestothecodeifnecessary.Writedownyourinputandoutput.
//Section2.1:
ReversingaList
#include
intmain()
/*Pre:
Theusersuppliesanintegernandndecimalnumbers.
Post:
Thenumbersareprintedinreverseorder.
Uses:
TheSTLclassstackanditsmethods*/
{
intn;
doubleitem;
stack
cout<<"Typeinanintegernfollowedbyndecimalnumbers."
< <<"Thenumberswillbeprintedinreverseorder." < cin>>n; for(inti=0;i cin>>item; numbers.push(item); } cout< while(! numbers.empty()){ cout< numbers.pop(); } cout< } Task2: Assembletheappropriatedeclarationsfromthetextintothefilesstack.handstack.cpp.Makeanynecessarychangesasre-compilingtheaboveapplicationReversingaListbyreplacingtheuseofSTLclassstackwiththeuseofuserdefinedclassStack. //Section2.2: constintmaxstack=10;//smallvaluefortesting classStack{ public: Stack(); boolempty()const; Error_codepop(); Error_codetop(Stack_entry&item)const; Error_codepush(constStack_entry&item); private: intcount; Stack_entryentry[maxstack]; }; Error_codeStack: : push(constStack_entry&item) /* Pre: None. Post: IftheStackisnotfull,itemisaddedtothetop oftheStack.IftheStackisfull, anError_codeofoverflowisreturnedandtheStackisleftunchanged. */ { Error_codeoutcome=success; if(count>=maxstack) outcome=overflow; else entry[count++]=item; returnoutcome; } Error_codeStack: : pop() /* Pre: None. Post: IftheStackisnotempty,thetopof theStackisremoved.IftheStack isempty,anError_codeofunderflowisreturned. */ { Error_codeoutcome=success; if(count==0) outcome=underflow; else--count; returnoutcome; } Error_codeStack: : top(Stack_entry&item)const /* Pre: None. Post: IftheStackisnotempty,thetopof theStackisreturnedinitem.IftheStack isemptyanError_codeofunderflowisreturned. */ { Error_codeoutcome=success; if(count==0) outcome=underflow; else item=entry[count-1]; returnoutcome; } boolStack: : empty()const /* Pre: None. Post: IftheStackisempty,trueisreturned. Otherwisefalseisreturned. */ { booloutcome=true; if(count>0)outcome=false; returnoutcome; } Stack: : Stack() /* Pre: None. Post: Thestackisinitializedtobeempty. */ { count=0; } Task3: Assumethefollowingdefinitionfileforanextendedstackdatastructure. classExtended_stack{ public: Extended_stack(); Error_codepop(); Error_codepush(Stack_entryitem); Error_codetop(Stack_entry&item)const; boolempty()const; voidclear();//Resetthestacktobeempty. boolfull()const;//Ifthestackisfull,returntrue;elsereturnfalse. intsize()const;//Returnthenumberofentriesinthestack. private: intcount; Stack_entryentry[maxstack]; }; Implementthefollowingmethods: (a)clear(b)full(c)size UsemethodsizeoftheclassExtended_stackinyourapplicationReversingaListtodisplaythenumberofdecimalnumbersyouimputed. Task4: Combineallthefunctionsandmethodsfortheairportsimulationintoacompleteprogram.Experimentwithseveralsamplerumsoftheairportsimulation,adjustingthevaluesfortheexpectednumbersofplanesreadytolandandtakeoff.Findapproximatevaluesfortheseexpectednumbersthatareaslargeaspossiblesubjecttotheconditionthatitisveryunlikelythataplanemustberefusedservice.Whathappenstothesevaluesifthemaximumsizeofthequeuesisincreasedordecreased? /*ProgramextractsfromChapter3of "DataStructuresandProgramDesigninC++" byRobertL.KruseandAlexanderJ.Ryba Copyright(C)1999byPrentice-Hall,Inc.Allrightsreserved. Extractsfromthisfilemaybeusedintheconstructionofotherprograms, butthiscodewillnotcompileorexecuteasgivenhere.*/ //Section3.3: constintmaxqueue=10;//smallvaluefortesting classQueue{ public: Queue(); boolempty()const; Error_codeserve(); Error_codeappend(constQueue_entry&item); Error_coderetrieve(Queue_entry&item)const; protected: intcount; intfront,rear; Queue_entryentry[maxqueue]; }; Queue: : Queue() /* Post: TheQueueisinitializedtobeempty. */ { count=0; rear=maxqueue-1; front=0; } boolQueue: : empty()const /* Post: ReturntrueiftheQueueisempty,otherwisereturnfalse. */ { returncount==0; } Error_codeQueue: : append(constQueue_entry&item) /* Post: itemisaddedtotherearoftheQueue.IftheQueueisfull returnanError_codeofoverflowandleavetheQueueunchanged. */ { if(count>=maxqueue)returnoverflow; count++; rear=((rear+1)==maxqueue)? 0: (rear+1); entry[rear]=item; returnsuccess; } Error_codeQueue: : serve() /* Post: ThefrontoftheQueueisremoved.IftheQueue isemptyreturnanError_codeofunderflow. */ { if(count<=0)returnunderflow; count--; front=((front+1)==maxqueue)? 0: (front+1); returnsuccess; } Error_codeQueue: : retrieve(Queue_entry&item)const /* Post: ThefrontoftheQueueretrievedtotheoutput parameteritem.IftheQueueisemptyreturnanError_codeofunderflow. */ { if(count<=0)returnunderflow; item=entry[front]; returnsuccess; } intExtended_queue: : size()const /* Post: ReturnthenumberofentriesintheExtended_queue. */ { returncount; } //Section3.5: intmain()//Airportsimulationprogram /* Pre: Theusermustsupplythenumberoftimeintervalsthesimulationisto run,theexpectednumberofplanesarriving,theexpectednumber ofplanesdepartingpertimeinterval,andthe maximumallowedsizeforrunwayqueues. Post: Theprogramperformsarandomsimulationoftheairport,showing thestatusoftherunwayateachtimeinterval,andprintsouta summaryofairportoperationattheconclusion. Uses: ClassesRunway,Plane,Randomandfunctionsrun_idle,initialize. */ { intend_time;//timetorunsimulation intqueue_limit;//sizeofRunwayqueues intflight_number=0; doublearrival_rate,departure_rate; initialize(end_time,queue_limit,arrival_rate,departure_rate); Randomvariable; Runwaysmall_airport(queue_limit); for(intcurrent_time=0;current_time intnumber_arrivals=variable.poisson(arrival_rate);//currentarrivalrequests for(inti=0;i Planecurrent_plane(flight_number++,current_time,arriving); if(small_airport.can_land(current_plane)! =success) current_plane.refuse(); } intnumber_departures=variable.poisson(departure_rate);//currentdeparturerequests for(intj=0;j Planecurrent_plane(flight_number++,current_time,departing); if(small_airport.can_depart(current_plane)! =success) current_plane.refuse(); } Planemoving_plane; switch(small_airport.activity(current_time,moving_plane)){ //LetatmostonePlaneontotheRunwayatcurrent_time. caseland: moving_plane.land(current_time); break; casetakeoff: moving_plane.fly(current_time); break; caseidle: run_idle(current_time); } } small_airport.shut_down(end_time); } enumRunway_activity{idle,land,takeoff}; classRunway{ public: Runway(intlimit); Error_codecan_land(constPlane¤t); Error_codecan_depart(constPlane¤t); Runway_activityactivity(inttime,Plane&moving); voidshut_down(inttime)const; private: Extended_queuelanding; Extended_queuetakeoff; intqueue_limit; intnum_land_requests;//numberofplanesaskingtoland intnum_takeoff_requests;//numberofplanesaskingtotakeoff intnum_landings;//numberofplanesthathavelanded intnum_takeoffs;//numberofplanesthathavetakenoff intnum_land_accepted;//numberofplanesqueuedtoland intnum_takeoff_accepted;//numberofplanesqueuedtotakeoff intnum_land_refused;//numberoflandingplanesrefused intnum_takeoff_refused;//numberofdepartingplanesrefused intland_wait;//totaltimeofplaneswaitingtoland inttakeoff_wait;//totaltimeofplaneswaitingtotakeoff intidle_time;//totaltimerunwayisidle }; enumPlane_status{null,arriving,departing}; classPlane{ public: Plane(); Plane(intflt,inttime,Plane_statusstatus); voidrefuse()const; voidland(inttime)const; voidfly(inttime)const; intstarted()const; private: intflt_num; intclock_start; Plane_statusstate; }; voidinitialize(int&end_time,int&queue_limit, double&arrival_rate,double&departure_rate) /* Pre: Theuserspecifiesthenumberoftimeunitsinthesimulation, themaximalqueuesizespermitted, andtheexpectedarrivalanddepartureratesfortheairport. Post: Theprogramprintsinstructionsandinitializestheparameters
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 软件工程 数据结构 实验 指导书