| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Birthday pairings
hey I have this program I'm tryin to get to work I was wondering if anyone could help
Here's the code that I have so far the problem is with the two functions that have comments in em: #include <iostream> #include <iomanip> #include ".\Random.h" #include <vector> #define DAYS_PER_YEAR 366 using namespace std; // 31 28/9 31 30 31 30 31 31 30 31 30 31 enum MONTH { JAN=1,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC }; struct DATE { int YYYY; MONTH MM; int DD; }; typedef vector<DATE> DATES; int main() { int R(); void DisplayFrequencies(long int frequencies[],long int T); long int frequencies[DAYS_PER_YEAR+1],i,T; for (int r = 1; r <= DAYS_PER_YEAR; r++) frequencies[r] = 0; cout << "T? "; cin >> T; SetRandomSeed(); for (i = 1; i <= T; i++) frequencies[R()]++; DisplayFrequencies(frequencies,T); return( 0 ); } int R() { bool IsContainedInBDays(DATES BDays,DATE BDay); DATE RandomDATE(); DATE BDay; DATES BDays; int r=0; while(!IsContainedInBDays(BDays,BDay)) { BDays.push_back(BDay); BDay = RandomDate(); r++; } return (r); } DATE RandomDATE() { bool IsLeapYear(int YYYY); /* Chose a date with a randomly chosen year, month and day of month. */ } bool IsLeapYear(int YYYY) { return( (( (YYYY % 4 == 0) && (YYYY % 100 != 0) ) || (YYYY % 400 == 0) ) ? true : false ); } bool IsContainedInBDays(DATES BDays,DATE BDay) { DATES::const_iterator i; bool r= false; for(DATES:iterater i = BDays,begin(); i!=BDays,end();i++) r=r||(i->MM=BDay,MM)&&(i->DD==BDay,DD); return (r); } void DisplayFrequencies(long int frequencies[],long int T) { /* Display frequencies using the format implied by the Sample Program Dialog. */ } any help would be really great |
|
#2
|
|||
|
|||
|
Hey Man! Look..it's important to use the <code> tags to keep the code readable...this is madness!!
Code:
#include <iostream>
#include <iomanip>
#include ".\Random.h"
#include <vector>
#define DAYS_PER_YEAR 366
using namespace std;
// 31 28/9 31 30 31 30 31 31 30 31 30 31
enum MONTH { JAN=1,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC };
struct DATE{
int YYYY;
MONTH MM;
int DD;
};
typedef vector<DATE> DATES;
int main()
{
int R();
DisplayFrequencies(long int frequencies[],long int T);
long int frequencies[DAYS_PER_YEAR+1],i,T;
for (int r = 1; r <= DAYS_PER_YEAR; r++)
frequencies[r] = 0;
cout << "T? "; cin >> T;
SetRandomSeed();
for (i = 1; i <= T; i++)
frequencies[R()]++;
DisplayFrequencies(frequencies,T);
return( 0 );
}
int R()
{
bool IsContainedInBDays(DATES BDays,DATE BDay);
DATE RandomDATE();
DATE BDay;
DATES BDays;
int r=0;
while(!IsContainedInBDays(BDays,BDay))
{
BDays.push_back(BDay);
BDay = RandomDate();
r++;
}
return (r);
}
DATE RandomDATE()
{
bool IsLeapYear(int YYYY);
/* Chose a date with a randomly chosen year, month and day of month. */
}
bool IsLeapYear(int YYYY)
{
return( (( (YYYY % 4 == 0) && (YYYY % 100 != 0) ) || (YYYY % 400 == 0) ) ? true : false );
}
bool IsContainedInBDays(DATES BDays,DATE BDay)
{
DATES::const_iterator i;
bool r= false;
for(DATES:iterater i = BDays,begin(); i!=BDays,end();i++)
r=r||(i->MM=BDay,MM)&&(i->DD==BDay,DD);
return (r);
}
void DisplayFrequencies(long int frequencies[],long int T)
{
/*Display frequencies using the format implied by the Sample Program Dialog.*/
}
That's a little more tidy...isn't it? |
|
#3
|
|||
|
|||
|
hehe sorry bout that
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Birthday pairings |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|