80 likes | 93 Views
Develop a program to analyze dice game outcomes, calculating mean and median throws per game, along with win probabilities. Implement sorting and statistical calculations using arrays and pointers in C programming.
E N D
Heads up:– Project is due on Tuesday before Thanksgiving break! Programming Project #4Arrays and Pointers Due, November 24, 11:59 PM (Assignment adapted from C: How to Program, 5th and 6th editions, by Deitel and Deitel) Programming Assignment #4
Objectives • Create and allocate arrays of data • Pass arrays as arguments to functions • Allow functions to modify the contents of arrays • Use pointer arithmetic for arrays See handout (.doc, .html) Programming Assignment #4
Assignment • Copy playGame, rollDice from Project #3. • Modify playGame as follows:– • Do not print anything • Return an integer indicating number of throws of this game • Positive if player wins, negative if player loses • Add additional functions in separate .c file • Play a number of games and store results in an array • Print mean and median number of throws per game • Analyze the results and print table showing results • Multiple modules (.c files) with makefile Programming Assignment #4
Program Operating • Prompt for number of games to play • Allocate an array with that number of elements • Play the games, gather results in array • Calculate and print mean and median number of throws per game • Calculate and print the following:– • Probability of the player winning at craps • Percent won on 1st throw, 2nd throw, etc. (up to 20) • Percent lost on 1st throw, 2nd throw, etc. (up to 20) • Do chances of winning improve with number of throws Programming Assignment #4
Calculating Median • Median – the middle value of all the results • Store data in array • Sort by value • Select the middle value • See handout for formula • Sorting the data • Use BubbleSort — see handout Programming Assignment #4
Makefile • Your program must comprise at least two .c files and one .h file. • Recommend three and two • One each for bubblesort.c and bubblesort.h • Must include a makefile • To build entire project • To build an individual .o file • To clean the directory • See Lab #4 Programming Assignment #4
Grading • Total 25 points • Program organization & makefile – 5 points • Correct compilation without warnings – 2 points • Correctly allocating and freeing array, playing n games, and storing results • Sorting array, calculating mean and median • Building table or data structure and answering four questions – 5 points • Write-up – 3 points • Extra credit – 5 points • Use optional command line arguments for number of games and random number seed — see handout Programming Assignment #4
Questions? Programming Assignment #4