• +1-617-874-1011 (US)
  • +44-117-230-1145 (UK)
Live Chat
Follow Us:

Pascal Assignment Question

Individual Programming Assignment, HW 3

Your program should use the Free Pascal compiler described. When you hand in your assignment to the digital dropbox, it should be a .PAS file, not zipped.

Your assignment is to use a random number generator to explore the game of roulette. A Eurpean roulette wheel has the following numbers:

Single zero wheel: 0-32-15-19-4-21-2-25-17-34-6-27-13-36-11-30-8-23-10-5-24-16-33-1-20-14-31-9-22-18-29-7-28-12-35-3-26

Despite the true mathematics of the matter, “0” is considered neither “odd” nor “even” when someone bets on the ball landing in an odd or even slot. (This is another way in which the house always wins in gambling.)

Many movies and stories have people making outlandish amounts of money by placing a bet on a single number, winning, and then leaving the winnings on that same number and, miraculously, winning again. Let’s assume that each of the 37 numbers is equally likely to come up on any spin of the wheel. How unlikely is that any number comes up twice in a row? And how unlikely is it for the fabled, lucky bettor to win twice in a row by betting the same number? (Be careful… these are two different answers!)

It is relatively straightforward to answer both of these questions using logic and statistics. However, you are to do it using simulations. (Such simulations are called “Monte Carlo simulations.” Really!) Use your random number generator as if it were a roulette wheel. Throw a random integer between 0 and 36 inclusive. Each random number generated will represent one spin of the wheel, with the small ball landing in the slot with that number. Answer the following questions empirically using the results of your simulation:

  1. On average, how often does a number come up two times in a row? On average, how often does a number come up three times in a row?
  1. If you pick a PARTICULAR number, how long does it take for that number to come up twice in a row? Let’s make the number 13, just for fun.
  1. What is the longest run of evens in a row in your simulation? What is the longest run of odds in a row? (Remember that 0 is classified as neither odd nor even.)

You must do at least the following simulations. You may do more, but not less:

  1. Do 10,000 spins of the wheel and answer the questions above.
  2. Do 1,000,000 spins, and answer the questions above.
  3. Do 100,000,000 spins, and answer the questions above.
  4. Do 10,000,000,000 spins and answer the questions above. (It may take a long time to run this.)

Be careful to use qword instead of int variables for the appropriate declarations since some of these numbers will be way over 32,767 (the limit of a Pascal int).

Also, while you are debugging your program, it is wise to print out to the screen frequently so you can see what’s going on (and perhaps what’s going wrong!). But once you start running programs that do LOTS of calculations, then do input and output sparingly; input and output require FAR more time than other calculations, and you want simulations doing millions of trials to go quickly, not slowly.

HW3. EMPIRICAL DATA: Generating data with a Free Pascal program

HW3 is about generating empirical data using Free Pascal (either using the Free Pascal IDE or the Lazurus system) and the function given by the language for generating pseudo-random numbers. Choose one of the problems in the HW3 folder to work on.

There are many ways to generate empirical data. You can take a survey. You can do research that includes counting things that exist, for example, the number of websites that UIS maintains on its servers. (I'm told that number is now over a million.) You can also write a program that generates data; that's what you will be doing in this assignment.

Exactly what you need to do to generate your empirical data is specific to your individual assignment. However, some rules apply to all of you:

  1. The generation and reporting of this data is supposed to be your work and your work alone. You are not allowed to work in teams, and you can't beg or hire help from anyone else to get it done. If you get someone else to do your work for you and you do not give them credit, then you are a plagiarist. If you copy someone else’s program, then you are a plagiarist. By now it should be clear that plagiarism is a major no-no.
  2. If you incorporate other people's code or ideas into your code, then (just like in a written document) you must give credit to whoever provided that code in your code's comments. If you copy someone else's code and you do NOT give credit, then you have committed plagiarism.
  3. Once you have generated your data, you will have may to report about that data in another homework assignment.
  4. You must use a Free Pascal program to generate your data for HW3. It is not acceptable to use some other programming language, and not some other implementation of Pascal. If you use something different and I can’t compile your Pascal program on my first try, it will cost you points. You may decide to use a different language to develop your program, and then convert it to Pascal. I doubt that this will save you much time and effort, but you may do this if you’d like. However, it is your Free Pascal program that you will hand in and that I will grade.
  5. When you hand in HW3, you should hand in the Free Pascal program you used to generate your data. Call the file lastnameHW3.pas, where "lastname" is replaced by your last name. For me, the file would be called vespaHW3.pas. Notice that I do NOT want your data that you generate. I will run your program, and I want your program to generate your data, but for me on my machine.
  6. You must use Pascal as the programming language for any software written in this class. The code must be compatible with the Free Pascal compiler. Be sure to include at least one function and one procedure in your HW3 program.
  7. Many of your simulations will use BIG numbers, so be careful. Use qword Free Pascal variables instead of integer variables so that your data does not overrun the variables. (longint includes negatives, 0 and positive numbers; qword is 0 and positives only.)

In COURSE DOCUMENTS there are several Pascal examples. You should look at those before doing this assignment. There are plenty of useful ideas in those programs.

Once you have generated your data, try to analyze it. Is the data enough to answer the question(s) from your assignment? Sometimes, you might need to generate more data to prove a hypothesis or demonstrate your point of view. It could be also the case that the data you collected might not meet your expectations.

For most of you, the description of your assignment will include some suggestions about how many times you should repeat your experiments.

You have a while to complete this assignment, but don't delay. Generating, interpreting, and reporting your data will take some time. Tempus fugit! (That's Latin for "time flies!")

If you do input and output from files (and I think it is a very good idea to do so), then be careful about where that file appears. Generally, unless you do something different, files that are generated end up in the same directory where your executable files are created by the Free Pascal compiler or by Lazarus. In your opening comments in your program, be sure to tell the person running your program (me) where any external files necessary for your program should go.

The name and purpose of any files that your program uses is one of the things I will look for in the opening comments of your program. Other information there should include your name, the date, the name of our course, and a coherent explanation of what your program does. The program should include a significant opening comment, and useful internal comments. Constants, user-defined types, procedures and functions should be used as appropriate to make the Free Pascal program easy to read and maintain.