c programming flea circus requirements document below you will find what has been de 5151448
C++ programming
Flea Circus Requirements Document Below you will find what has been determined to be the user requirements as well as the program requirements to run the Flea Circus Program. The Flea Circus Program will start with a 30 x 30 grid and one flea in each square. The purpose of the program is to have each flea jump one time per bell ring to an adjacent square. After each “Round”, the program will then calculate and display the total number of unoccupied squares. 1. The user will be prompted to enter any number of bell rings with the only restriction being that it has to be a positive whole number. 2. The range of bell rings: 1-100,000. 3. The program will then begin the first bell ring. 4. Each flea will jump to an adjacent square within the rules defined below. A. A flea must jump to a different square. B. Each flea can jump only once per ring. C. A flea cannot jump diagonally. D. A flea may jump either up, down, left or right on the grid based on a random number generated by the program after each ring. E. A flea may not jump off the “grid”. 5. The program will repeat step 3 until it has completed the number of rings selected by the user. 6. A “Round” is the number of rings of the bell the user has chosen. So if the user chooses 500 bell rings, a “Round” is all 500 bell rings. 7. After a Round, the program will calculate and display the total number of unoccupied grid spaces and which grid has the most fleas in it. You can list several locations if there are some with the same number in it. 8. After a Round has been completed, the program will reset and be ready to start over. 9. The user will then be given the opportunity to end the program or for another Round. 10. The program will then display “Thank You for playing” to the user. 1. User's input/responsibility a. Start program b. Provide program with Number of bell rings C. Review results 2. Program's responsibility a. Setup the GUI (if applicable) b. Make the required number of bell rings C. Move each flea within its bounds i. Chose which space to move to, based on a random number generated d. Count the number of spaces without a flea e. Maybe reset everything for a new game f. Maybe choose how many times the program will run the game (5, 10, etc…) Flea Program – Jump logic jumpFlea: • Modules function: jumps all 900 fleas one time o Calls getlocation Calls getRandomNumber-sends in how many spaces in can jump to o Jumps a flea to its new location o Calls setLocation Argument list: none Returns: nothing OK, so what does the random number generator return and why? At most there are 4 directions the flea can jump. But in some situations it could be 2 or 3 directions. So what should the random number generator do? Well in my opinion, it should return a number that is associated with the all possible directions (4) and then accommodate for the few locations where the flea can jump fewer directions. Look up modulus and expect to get the numbers from 0-3, which is 4 numbers. Now we must think about the how to jump a flea and only jump it in the correct directions. Additionally if we figure out how to do this for 1 flea regardless of its location on the grid we can just add a loop to walk thru all 900 fleas. So let's begin with the first flea, the first jump and so the getLocation would return a O for the XAxis and a 0 for the yAxis. If you draw a grid and look at this flea you will see that it cannot jump up or to the left. If you were to look at the subscripts for the xAxis and the flea was to jump up then the subscript would be -1 because its xAxis was 0 and to move down by 1 location the subscript would increase to 1. so if it was, based on the random number returned (0-3), supposed to jump up but was at the top of the grid and can't then just make it jump down. And you could do this for all directions. If they flea is on the far right, yAxis 29, and it was to jump to the right then the subscript would increase by 1. Now the yAxis subscript is 30 and the flea is off the board, so then just jump it to the left by 1 space from where it began and the ending subscript is now 28. Back to the random number generator for a moment, since it is returning a 0, 1, 2, or a 3,0 could mean jump up and I could mean jump down and etc.. I know it was a bit long but I hope it keeps you all going in the right direction. Flea Program Design Document These are my thoughts on the modules needed, what they do, the argument list, and the return if there is one. 1. Initialize: Argument list: None Returns: Nothing • Modules function: Sets up everything necessary to start the program o sets up form o initializes variables – creates the fleaTable 900,2) o puts each flea into its initial location in the fleaTable 2. startclick: Argument list: None Returns: Nothing • Modules function: Basically runs the program calls getNumberOfRings- a return of -1 will not allow the program to jump fleas, count empties or display the output o executes a loop based on getNumberOfRings return . inside loop: calls jumpFlea calls empties calls displayOutput 3. getNumberOfRings: Argument list: None Returns: An integer that the user entered between 1 and 100,000 or a -1 Modules function: Prompts user and verifies users entry, only gives the user 3 tries to enter a valid number calls validateUserEntry-if the return is a -1 then it passes that on and returns a -1 also o if it is a valid number then validate that it is within the correct range then it returns that number returns a -1 if the user fails to enter a valid number or within the correct range 4. validateUserEntry Argument list: A string • Returns: An integer • Modules function: Converts the passed in argument to an integer o calls error Message – if the passed in argument cannot be converted to an integer returns – 1 if user entry was invalid 5. errorMessage: Argument list: A string Returns: Nothing Modules function: Displays the string that is passed in 6. jumpFlea: Argument list: None Returns: Nothing Modules function: Uses a loop to jump each flea in order from 1 to 900 and inside the loop it does the following o calls getLocation – gets the location of the current flea from the fleaTable o calls getRandomNumber – Returns a number 0-3 o jumps a flea to its new location – O means jump Up • subtract 1 to the x coordinate 1 means jump Down • add 1 from the x coordinate 2 means jump Right • add 1 to the y coordinate 3 means jump Left • subtract 1 from the y coordinate if a flea jumps off the “grid”: • if the x or y variable reaches -1 o add 2 to that variable • if the x or y variable reaches 30 o subtract 2 from that variable o calls setLocation – Updates the fleaTable to the new location of the flea 7. getLocation: • Argument list: All integers, fleaNumber, XAxis (ByRet), yAxis (ByRef) • Returns: The location of the flea by filling and using the ByRet logic • Modules function: Looks at the flea in the fleaTable by using the fleaNumber and returns the x and y values which coordinate to the columns. The flea number coordinates to the row in the fleaTable. The table is a two dimensional array with 900 rows and 2 columns 8. getRandomNumber: Argument list: Nothing Returns: An integer • Modules function: Returns a random number of 0, 1, 2 or 3 o calls system function for a random number o then modifies the returned number so only a 0, 1, 2 or 3 is returned setLocation: Argument list: All integers, fleaNumber, XAXIS, YAXIS Returns: Nothing Modules function: Finds the flea then writes to the fleaTable the new x and y values passed in 10. empties: Argument list: None • Returns: An integer Modules function: Builds a table then figures out where each flea is and then counts the empty locations o creates the boolean fleaGrid(30, 30) o calls buildFleaTable – builds and fills the table o calls countEmpties – walks thru the table and looks for each location where no fleas exist. 11. buildFleaTable: • Argument list: The boolean fleaGrid(30, 30) • Returns: The boolean fleaGrid(30, 30) Modules function: Gets the location of each flea and marks it in the table o initializes the flea Grid with “false” in each location o calls getLocation – for each flea o uses the x and y coordinates to puts a “true” into each location where a flea exists in the table 12. countEmpties: Argument list: The boolean fleaGrid(30, 30) Returns: An integer Modules function: Count the empty locations o uses loops to walk thru the table o adds one to its counter every time a “false” is found in a location of the fleaGrid 13. displayOutput: Argument list: An integer Returns: Nothing • Modules function: assigns the number passed in to the label that is on the mainForm Flea Program – Array Creation Below is what I began with when thinking about the fleas jumping. If we begin with any point on the grid and the flea jumps in the adjacent cell, which is the next one to be evaluated. We would now have two fleas in that cell and so how would we know how many were there and still need to jump and which ones have already jumped and don't. So, if we have a 2 dimensional array used for the jumping 900 rows and 2 columns then we would just walk down the list and jump each flea. The 30 x 30 table is then only used when the number of empties are calculated. Flea Program – System Flowchart Below is what I began with and this is a functional design. By functional design I mean that this not an object oriented design it is functionally how the program will work. And remember that an object oriented design is arranged differently in the code. The next step will be the detailed design and then you will define not only what each module does but how it does it without producing code. You will produce the UML charts that define the classes. Additionally I did include 2 system flow chart pictures because I want you to see that thinking can be done in a progressive manner. The system flow chart you will use. start initalize mainloop displayOutput getNumberOfRings validateUser Entry empties Reti ocation setlocation error Message getRandomNumber buildFleaTable countEmpties