W
Willson
Ok, first off I am learning C++ for the first time. I know Java very
well, but a new class of mine requires C++. So bare with me please.
I have 2 classes, Birthday.cpp and BirthdayParadox.cpp
Birthday is a class and Birthday paradox is mainly the driver for it. I
am trying to create an object of Birthday in BirthdayParadox and it is
not working.
I get the error: "'Birthday' undeclared (first use this function)"
any idea?
Birthday.cpp
---------------------------------------------------------------------------------------------
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
// #include any header files you need here
class Birthday
{
public:
int bDay;
// standard constructor
// default to January 1st if user provides invalid data
Birthday::Birthday(int doy)
{
// define the implementation code of the constructor
if ( doy < 1 && doy > 365 )
{
bDay = 1;
}
else
bDay = doy;
}
// Default constructor which generates a random birthday
// between January 1st and December 31. We assume only non-leap years
Birthday::Birthday()
{
bDay = setDay();
}
// Set birthday randomly
int Birthday::setDay()
{
srand((unsigned)time(0));
int random_integer = rand();
for(int index=0; index<1; index++)
{
random_integer = (rand()%365)+1;
}
return random_integer;
}
// Test for birthday equality
bool Birthday:perator==( const Birthday &b)const
{
// fill in your code here
return true;
}
/*// print birthday information
std:stream& operator<<(std:stream& out, const Birthday &b)
{
// fill in your code here
cout>> "test";
} */
};
BirthdayParadox----------------------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
// #include any other necessary header files here
// also the required "using" statements
void testBirthdayParadox()
{ // Birthday Paradox test function
Birthday data; // <-------------------------------------------
this is where i get the error.
//srand( time(0) ) ;
// fill in your code here
}
int main()
{
char c;
//testBirthdayParadox();
cin >> c; // to force the DOS screen to stay until you press any
character
return EXIT_SUCCESS; // successful execution
}
well, but a new class of mine requires C++. So bare with me please.
I have 2 classes, Birthday.cpp and BirthdayParadox.cpp
Birthday is a class and Birthday paradox is mainly the driver for it. I
am trying to create an object of Birthday in BirthdayParadox and it is
not working.
I get the error: "'Birthday' undeclared (first use this function)"
any idea?
Birthday.cpp
---------------------------------------------------------------------------------------------
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
// #include any header files you need here
class Birthday
{
public:
int bDay;
// standard constructor
// default to January 1st if user provides invalid data
Birthday::Birthday(int doy)
{
// define the implementation code of the constructor
if ( doy < 1 && doy > 365 )
{
bDay = 1;
}
else
bDay = doy;
}
// Default constructor which generates a random birthday
// between January 1st and December 31. We assume only non-leap years
Birthday::Birthday()
{
bDay = setDay();
}
// Set birthday randomly
int Birthday::setDay()
{
srand((unsigned)time(0));
int random_integer = rand();
for(int index=0; index<1; index++)
{
random_integer = (rand()%365)+1;
}
return random_integer;
}
// Test for birthday equality
bool Birthday:perator==( const Birthday &b)const
{
// fill in your code here
return true;
}
/*// print birthday information
std:stream& operator<<(std:stream& out, const Birthday &b)
{
// fill in your code here
cout>> "test";
} */
};
BirthdayParadox----------------------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
// #include any other necessary header files here
// also the required "using" statements
void testBirthdayParadox()
{ // Birthday Paradox test function
Birthday data; // <-------------------------------------------
this is where i get the error.
//srand( time(0) ) ;
// fill in your code here
}
int main()
{
char c;
//testBirthdayParadox();
cin >> c; // to force the DOS screen to stay until you press any
character
return EXIT_SUCCESS; // successful execution
}