//--------------------------------------------------------- // Hmwk10 // // Simulate an experiment in which coins are flipped and // the empirical probabilities are calculated and displayed. // // D. Searls // REPLACE THIS LINE WITH YOUR NAME!! // Asbury University //--------------------------------------------------------- #include "worldType.h" #include #include #include using namespace std; //--------------------------------------------------------- // drawColChart // // Draw a column chart on the graphics device based on // the specified properties. // // In Parameters: // n - number of data categories // dataName - category names // dataValue - catagory values // chartTitle - the title of the chart // xAxisTitle - the horizontal axis title // yAxisTitle - the vertical axis title // background - the background color // foreground - the foreground color // fillcolor - the fill color // yinc - vertical axis label increment // yplaces - decimal places for vertical axis labels //--------------------------------------------------------- void drawColChart(int n, string dataName[], double dataValue[], string chartTitle, string xAxisTitle, string yAxisTitle, int background, int foreground, int fillcolor, double yinc, int yplaces) { // Implement this function } //--------------------------------------------------------- // illustrate // // Illustrate the probability distribution of heads by // drawing a column chart. This function sets up the // horizontal axis labels and the titles for the chart // and then invokes the drawColChart function to do the // actual drawing. // // In Parameters: n, prob //--------------------------------------------------------- void illustrate(int n, double prob[]) { string* name; char text[20]; string title; try { name = new string[n+1]; for (int i = 0; i <= n; i++) { sprintf(text, "%i", i); name[i] = text; } sprintf(text, "Flipping %i Coins", n); title = text; drawColChart(n + 1, name, prob, title, "Heads", "Probability", WHITE, BLACK, COLOR(255, 0, 0), 0.05, 2); delete [] name; } catch (bad_alloc bae) { cout << "Memory allocation failed. Program terminated\n"; exit(0); } } //********************************************************* // M A I N D R I V E R //********************************************************* int main() { // You will need to add one statement to your main // driver (from Lab 10). That statement will invoke the // illustrate function (passing the number of coins and // the corresponding array of probabilities as // parameters). }