讲解:CMSC 202、C++、C++、data structureSPSS|Web

CMSC 202 Fall 2019Project 3 – DecayAssignment: Project 3 – DecayValue: 80 points1.OverviewIn this project you will:Implement a linked-list data structure,Use dynamic memory allocation to create new objects,Practice using C++ class syntax, Practice vectors, Practice object-oriented thinking. 2.BackgroundFor this project, we are going to be building a simple linked list where each node holds a boolean value. The basic linked list looks like this:There are two main ways to populate each node in the linked list. The first is by loading a file where each linked list is on a single line. Each linked list will be a multiple of three but has no defined limit in size (minimum 3 nodes, maximum unknown – but will be a multiple of 3). The input file will look like this:In this example, there are three individual linked lists – the first has three nodes, the second has 6 nodes, and the third has 30 nodes. Each linked list will be seperated by a semi-colon. A test file can have any number of linked lists with any number of nodes in each list.In the example below, there are six nodes. The more challenging part of this project is creating the decay simulation. The simulation would traverse the list and remove all groups of three 1s in a row starting from the left.If there were additional sets of exactly three 1s in a row, it would remove them as well. After all sets of three 1s have been removed, the user can choose a node to switch from zero to one or one to zero and it checks for groups of three again. This repeats until the entire list is emptied.3.Assignment DescriptionYour assignment is to build an application that can either read a file of decay lists or randomly generate a decay list.1.The file may contain one or more lists.2.Each list will be separated by a semi-colon (;).3.Each list will have at least three nodes but no upper limit (but the upper limit must be a multiple of three). 4.Each node only holds one Boolean value (if it is a 0 or 1).5.If a random list is generated, the user will enter a size of the new DecayList and then multiply the entered value by three to define the number of nodes. Each node will randomly be assigned a 0 or 1.6.The simulation will iterate through the list and if there are three nodes in a row with a “true” or 1 value, it will remove those three nodes. If there are four or more nodes in a row with a “true” or 1 then it will remove the first three trues then continue to see if there are more sequences of three “trues” or 1s in a row. 7.Between each round of checking for trues or 1s, the user can choose one node to invert its value – switching a 0 to a 1 or a 1 to a 0.8.All user inputs will be assumed to be the correct data type. For example, if you ask the user for an integer, they will provide an integer.9.Regardless of the sample output below, all user input must be validated. If you ask for a number between 1 and 5 with the user entering an 8, the user should be re-prompted.10.Have a main menu that asks the user if they want to:a.What would you like to do?:i.Load Fileii.Simulate Loaded File (if no file is loaded, it prompts you to do option 1 first)iii.Simulate Random Fileiv.Exit1.Upon exit, nothing is saved4.Requirements:Initially, you will have to use the following files Node.h, DecayList.h, Decay.h, makefile, driver.cpp, and a simple test file. You can copy the files from Prof. Dixon’s folder at:/afs/umbc.edu/users/j/d/jdixon/pub/cs202/proj3To copy it into your project folder, just navigate to your project 3 folder in your home folder and use the command:cp /afs/umbc.edu/users/j/d/jdixon/pub/cs202/proj3/* .Notice the trailing period is required (it says copy it into this folder).The project must be completed in C++. You may not use any libraries or data structures that we have not learned in class. Libraries we have learned include , , , , , , and . You should only use namespace std.You must use the function prototypes as outlined in the Node.h, DecayList.h, and Decay.h header file. Do not edit the header files.There is one provided test file. The file is named test1.txt.You can easily create an additional test file to check other scenarios.You need to write the functions for the three classes for this project. You need to code Node.cpp, DecayList.cpp, and Decay.cpp. Do not use the STL list for this project.The DecayList is the linked list class for this project. Here are some general descriptions of each of the functions:oDecayList() – The constructor creates a new empty linked list. m_head is nullptr and m_size is zero.o~DecayList() – The destructor de-allocates any dynamically allocated memory.oGetSize() – Returns the number of nodes in the list.oInvertValue(int index) – for a specific node in the list, inverts the value in the node. A 1 turns into 0 or 0 turns into a 1. oPrintDecayList() – Displays the value in each node in the decay list. oCheckEmpty() – Returns if the linked list is empty.oInsertEnd() – This inserts a node into the end of the DecayList. There is no m_tail so you must iterate over the list to the end!oTraverseList() – The iterates through the list to identify groups of three nodes to remove. Calls RemoveNodes(index,3) to remove those nodes. May call RemoveNodes multiple times in one traversal (due to a new list being loaded).oRemoveNodes(index, numNodes) – At a specific index, removes some number of nodes in a row. This is a tricky function so wait until the end to code! Don’t forget about the special cases when the nodes are in the beginning, middle or end of the list.The Decay class manages the application and populates the various DecayLists. Decay.cpp file that are prototyped in Decay.h.oDecay() – The constructor just sets m_file = o~Decay() – The destructor de-allocates any dynamically allocated memory (each list). oEmptyLists() – This function de-allocates any dynamically allocated list.oLoadFile()– The LoadFile function loads one to many DecayLists each with a different number of nodes. Each list is terminated in the data file with a semi-colon (;).oChooseList() – Allows the user to choose one of the lists loaded into m_lists.oCreateRandomList() – Creates a list of a specific number of nodes (user entered * 3). Each node is randomly assigned either a 0 or 1. oRunSimulation(int index) – After a specific list is chosen or a random list is generated, RunSimulation is called. It is passed the index of the list from the vector m_lists.oStart() – Calls the various functions in the DecayList.Choices 1 – Calls LoadFileChoice 2 – Calls ChooseListChoice 3 - Calls CreateRandomListChoice 4 - Exits.5.Sample Input and Output5.1.Sample RunA normal run of the compiled code would look like this with user input highlighted in blue:Welcome to Decay, where you code a frustrating system instead of doing your physics homework.1. Load File2. Simulate Loaded File3. Simulate Random List4. Quit1What is the name CMSC 202代做、C++程序语言调试、代写C++、代做dof the file?test1.txtWelcome to Decay, where you code a frustrating system instead of doing your physics homework.1. Load File2. Simulate Loaded File3. Simulate Random List4. Quit Here are the runs looking at 2. Simulate Loaded File then choosing list 1 with 3 nodes.2Which Decay scenario do you want to experience?1. List 1(3 nodes)2. List 2(6 nodes)3. List 3(30 nodes)4. Quit1The sequence has been initialized.|1|->|0|->|1|->ENDWhich node to change? 1 2 323 nodes removed!All nodes from that list have been removed!All lists have been cleared.Welcome to Decay, where you code a frustrating system instead of doing your physics homework.1. Load File2. Simulate Loaded File3. Simulate Random List4. QuitAs you can see in the example above, there were three nodes and only the center node had a value of 0. By switching that node to a 1, there were three 1s in a row and those nodes were removed.Here is an full example where a random list is simulated with a starting size of 3 (so 9 nodes).Welcome to Decay, where you code a frustrating system instead of doing your physics homework.1. Load File2. Simulate Loaded File3. Simulate Random List4. Quit3How large a list would you like?3|0|->|1|->|0|->|0|->|0|->|0|->|1|->|0|->|0|->ENDWhich node to change? 1 2 3 4 5 6 7 8 93|0|->|1|->|1|->|0|->|0|->|0|->|1|->|0|->|0|->ENDWhich node to change? 1 2 3 4 5 6 7 8 943 nodes removed!|0|->|0|->|0|->|1|->|0|->|0|->ENDWhich node to change? 1 2 3 4 5 65|0|->|0|->|0|->|1|->|1|->|0|->ENDWhich node to change? 1 2 3 4 5 663 nodes removed!|0|->|0|->|0|->ENDWhich node to change? 1 2 31|1|->|0|->|0|->ENDWhich node to change? 1 2 32|1|->|1|->|0|->ENDWhich node to change? 1 2 333 nodes removed!All nodes from that list have been removed!All lists have been cleared.Welcome to Decay, where you code a frustrating system instead of doing your physics homework.1. Load File2. Simulate Loaded File3. Simulate Random List4. QuitHere is an example with some validation../proj3Welcome to Decay, where you code a frustrating system instead of doing your physics homework.1. Load File2. Simulate Loaded File3. Simulate Random List4. Quit2Load a file first!Welcome to Decay, where you code a frustrating system instead of doing your physics homework.1. Load File2. Simulate Loaded File3. Simulate Random List4. Quit3How large a list would you like?-1How large a list would you like?1|0|->|1|->|1|->ENDWhich node to change? 1 2 36.Compiling and RunningBecause we are using a significant amount of dynamic memory for this project, you are required to manage any memory leaks that might be created. For a linked list, this is most commonly related to the dynamically allocated nodes. Remember, in general, for each item that is dynamically created, it should be deleted using a destructor.One way to test to make sure that you have successfully removed any of the memory leaks is to use the valgrind command.Since this project makes extensive use of dynamic memory, it is important that you test your program for memory leaks using valgrind:valgrind ./proj3Note: If you accidently use valgrind make run, you may end up with some memory that is still reachable. Do not test this – test using the command above where you include the input file. The makefile should include make val1 (which is ok).If you have no memory leaks, you should see output like the following:==5606====5606== HEAP SUMMARY:==5606== in use at exit: 0 bytes in 0 blocks==5606== total heap usage: 87 allocs, 87 frees, 10,684 bytes allocated==5606====5606== All heap blocks were freed -- no leaks are possible==5606====5606== For counts of detected and suppressed errors, rerun with: -v==5606== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)The important part is “in use at exit: 0 bytes 0 blocks,” which tells me all the dynamic memory was deleted before the program exited. If you see anything other than 0 bytes 0 blocks there is probably an error in one of your destructors. We will evaluate this as part of the grading for this project.Additional information on valgrind can be found here: http://valgrind.org/docs/manual/quick-start.htmlOnce you have compiled using your makefile, enter the command ./proj3 to run your program. You can use make val1 to test each of the input files using valgrind (do NOT use valgrind make run!). They have differing sizes. If your executable is not proj3, you will lose points. It should look like the sample output provided above. 7.Completing your ProjectWhen you have completed your project, you can copy it into the submission folder. You can copy your files into the submission folder as many times as you like (before the due date). We will only grade what is in your submission folder.For this project, you should submit these files to the proj3 subdirectory:driver.cpp — should be unchanged.Node.h — should be unchanged.Node.cpp – should include your implementations of the class functions.DecayList.h — should be unchanged.DecayList.cpp – should include your implementations of the class functions.Decay.h — should be unchanged.Decay.cpp – should include your implementations of the class functions.As you should have already set up your symbolic link for this class, you can just copy your files listed above to the submission folderb.cd to your project 3 folder. An example might be cd ~/202/projects/proj3c.cp driver.cpp Node.h Node.cpp DecayList.h DecayList.h Decay.h Decay.cpp ~/cs202proj/proj3You can check to make sure that your files were successfully copied over to the submission directory by entering the commandls ~/cs202proj/proj3You can check that your program compiles and runs in the proj3 directory, but please clean up any .o and executable files. Again, do not develop your code in this directory and you should not have the only copy of your program here. Uploading of any .gch files will result in a severe penalty.For additional information about project submissions, there is a more complete document available in Blackboard under “Course Materials” and “Project Submission.”IMPORTANT: If you want to submit the project late (after the due date), you will need to copy your files to the appropriate late folder. If you can no longer copy the files into the proj3 folder, it is because the due date has passed. You should be able to see your proj3 files, but you can no longer edit or copy the files in to your proj3 folder. (They will be read only)If it is 0-24 hours late, copy your files to ~/cs202proj/proj3-late1If it is 24-48 hours late, copy your files to ~/cs202proj/proj3-late2If it is after 48 hours late, it is too late to be submitted.转自:http://www.3daixie.com/contents/11/3444.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,753评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,668评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 166,090评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,010评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,054评论 6 395
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,806评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,484评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,380评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,873评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,021评论 3 338
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,158评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,838评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,499评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,044评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,159评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,449评论 3 374
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,136评论 2 356

推荐阅读更多精彩内容