#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <ctype.h>
#include <time.h>
using namespace std;
const int SAMPLE_SIZE = 23;
const int NUMBER_OF_SETS = 1000;
void GetandDisplayMenu();
void ExplainBDayParadox();
void VerifyBDayParadox();
void DisplayBDaySet();
void GenerateBDaySet(int B[]);
void SortBDaySet (int B[]);
void ConvertDayOfYear (int DayofYear, int &MonthNumber, int &DayNumber);
int DaysInMonth (int MonthNumber);
void Exit();
void main()
{
int MenuChoice;
GetandDisplayMenu();
cin >> MenuChoice;
srand(int (time(NULL)));
switch (MenuChoice)
{
case 1: ExplainBDayParadox();
break;
case 2: VerifyBDayParadox();
break;
//case 3: DisplayBDaySet();
break;
//case 4: Exit();
break;
default:;
}
}
/*************************** Menu Display Function *************************************/
void GetandDisplayMenu()
{
cout << " Please select one of the option below!" << endl;
cout << " ====================================" << endl;
cout << " 1. Explain birthday paradox" << endl;
cout << " 2. Check birthday paradox by generating 1000 sets of birthdays" << endl;
cout << " 3. Display one set of 23 birthdays" << endl;
cout << " E. Exit" << endl;
cout << " ----------------------------------" << endl;
cout << " Please enter your selection: ";
}
/********************** Birthday Paradox Explanation Function **************************/
void ExplainBDayParadox()
{
cout << "\nThe birthday paradox can be described as follows: " << endl;
cout << " If 23 persons are chosen at random, then the chances are more " << endl;
cout << " than 50% that at least two will have the same birthday!" << endl;
}
/************************ Verify Birthday Paradox Function ***************************/
void VerifyBDayParadox()
{
int k, j;
const int SIZE = 23;
int B[SIZE+1];
float Result, matches=0;
for (k=1; k<=NUMBER_OF_SETS; k++)
{
GenerateBDaySet(B)/>;
SortBDaySet(B)/>;
for (j=0; j<SIZE; j++)
{
if (B[j]==B[j+1])
{
matches++;
break; //BREAK THE LOOP
}
}
}
Result = (matches/1000) * 100;
cout << "\nGenerating 1000 sets of 23 birthdays and checking for matches... " << endl;
cout << "Results : " << matches << " out of " << NUMBER_OF_SETS << " (" << Result << "%)"
<< " of the sets contained matching birthdays." << endl;
cout << " ================================================================== " << endl;
}
/************************ Generate Birthday Set Function *******************************/
void GenerateBDaySet(int B[])
{
int i=0;
for(i; i<23; i++)\
{
B[i]=(1+rand()%365);
}
}
/************************ Sorting Birthday Function ************************************/
void SortBDaySet(int B[])
{
int temp, min, i=0, j=0;
for(i; i < 23; i++)
{
min = i;
for (j=i+1; j < 23; j++)
{
if (B[j] < B[min])
min = j;
}
temp = B[i];
B[i] = B[min];
B[min] = temp;
}
}
/************************* Display Birthday Set Function *******************************/void DisplayBDayset()
{
const int SIZE=23;
char *MonthOfYear[13]={"ERROR","January","February","March","April","May","June",
"July","August","September","October","November","December"};
int B[SIZE+1];
int MonthNumber = 0, DayNumber = 0;
GenerateBDaySet(B)/>;
SortBDaySet(B)/>;
ConvertDayOfYear(B)/>;
}
/************************* Days in Month Function **************************************/
int DaysInMonth (int MonthNumber)
{
switch (MonthNumber)
{
case 2: return 28;
break;
case 4: return 30;
break;
case 6: return 30;
break;
case 9: return 30;
break;
case 11: return 30;
break;
default: return 31;
}
}
/*********************** Convert Day of Year Function **********************************/
void ConvertDayOfYear (int DayofYear, int &MonthNumber, int &DayNumber)
{
MonthNumber = 1;
while (DayofYear > DaysInMonth(MonthNumber))
{
DayofYear = (DayofYear - DaysInMonth(MonthNumber));
++MonthNumber;
}
DayNumber=DayofYear;
}
I keep getting a error (144): error C2660: 'ConvertDayOfYear' : function does not take 0 arguments and I cant seem to figure it out.

New Topic/Question
Reply




MultiQuote




|