CMSC104Problem Solving and Computer ProgrammingSection 0501 |
Each flip is an occurrance and a number of occurrances is a set of occurrances.
We know that the computer always does things in the same exact way, yet we want to study the result of random occurances. To be able to do this, we fool the computer. There is a built-in function that will return a random number. This function takes a starting number (or seed) and calcuates a new random number each time. The bad news is that this function will always return the same set of random numbers. To fix this, the seed must altered before using the random function for the first time.
Prepare a report from the user, giving the number of sets, the number of occurrances in each set, the expected number of occurances for each possibility, the sum of the deviations, the average deviation, the smallest deviation and the largest deviation.
#include <stdio.h> #include <stdlib.h> #include <time.h>
One additional function is will be needed is a function that will return the absolute value of a number, the absolute value of -3 is 3, the absolute value of +3 is 3. When a set of occurrances was expected to return 200 heads, and it returned 193, the deviation from the predicted value is 7. When calculating the deviation for this project, we will only sum up the absoluate value of the deviation.
To seed the random number generator, you must change the seed once in your program. You need to use the following statement once as one of the first things you do:
To simulate getting only heads and tails, we can generate a random and scale it. By using the mod operator, we can get only a 0 or a 1, one of which we will assume is heads and the other is tails. To get a random number in the range of 0 - 1, you will use the code:
To get the absolute value of a number, use the following:
How many sets do you wish? 10 How many attempts per set do you wish? 100 The deviation this time was 3. The deviation this time was 0. The deviation this time was 2. The deviation this time was 1. The deviation this time was 2. The deviation this time was 6. The deviation this time was 2. The deviation this time was 5. The deviation this time was 2. The deviation this time was 7. The number of requested sets was 10. The number of occurrances per set was 100. The expected number of occurances of each odd and even was 50. The sum of the deviations was = 30 The average dieviation was = 3.000000 The smallest deviation was 0. The largest deviation was 7.
How many sets do you wish? 1000 How many attempts per set do you wish? 100000 The number of requested sets was 1000. The number of occurrances per set was 100000. The expected number of occurances of each odd and even was 50000. The sum of the deviations was = 91381 The average dieviation was = 91.381000 The smallest deviation was 1. The largest deviation was 190.
When submitting the assignment, I only want the file jdoe2p3.c. Please make the title and the file name the same when you submit it! If you submit a file named jdoe2p3.c, the way we save the material delete everything but the last file with than name. Therefore, your file will be lost and we will give you a zero!!!! Use your login ID!!!
Documentation | 25 points |
Correct Results | 25 points |
Correct Sytle | 25 points |
Other | 25 points |
You will lose 5 points if you do not name the file correctly.
You will lose 5 points if you email the project instead of submitting
it via Blackboard.
You will lose 5 points if the prompt is not on the next line.
/*****************************************************/ /* Program Header Block */ /* Filename: jdoe2p3.c */ /* Name: Ima Student */ /* Email: jdoe2@umbc.edu */ /* Date: 17 Oct 2005 */ /* Course/section: CMSC-104/0501 */ /* Description: */ /* Analysis: */ /* Input: */ /* Output: */ /* Constraints: */ /* Formulas: */ /* Assumptions: */ /* Design: */ /* (Your psuedocode goes here.) */ /* */ /* Notes: (As needed.) */ /*****************************************************/