I'm having trouble with this code its part of a birthday profile for class everything else works but this date.cpp file....looked all throughout forms but can't find this particular one..Please help

#include "stdafx.h"
#include "date.h"
#include <string>
using std::string;


class TestBirthday
{
public: static void main()
	{
		int num;
		System.out.println("Enter number of people to test");
		num = Console.readInt();
		
		Birthday2 Experiment = new Birthday2(num);
		System.out.println("The number of duplicates when testing " +num+ " people is "+ Experiment.countDuplicates());
	}
}

class Birthday2()
{

	private
		int num;
	private 
		int[]birthday;
	
	public
		Birthday2(int number)
{
	num = number;
	birthday = new int[num];

}

	public int countDuplicates()
	{
		boolean duplicate = false;
		int index = 0;
		int dup = 0;
		int day;
		
		
		while (index < num)
		{
			day = 1 + (int)(Math.random()*365);
			{
				duplicate = searchBirthdays(day,index);
				if (duplicate)
					dup ++;
			}
			
			birthday[index] = day;
			index ++;
		}
		return dup;
	}
	
	
	private boolean searchBirthdays(int bday, int end)
	{
		boolean found = false;
		int index = 0;
		
		while ((index < end) && (!found))
		{
			
			if(bday == birthday[index])
				found = true;
			
			index ++;
		}//end while
		
		return found;
	}

}

Edited 6 Years Ago by __avd: Added [code] tags.

these are my errors

error c2236: unexpected 'class' 'Birthday2'.Did you forget a ';' ---I tried to put one amongst 20, 19, 21 and nothing worked
fatal error C1903: unable to recover from previous error(s);stopping compilation -- I think if the first error gets fixed it work work??

class Birthday2()
{

private
int num;
private
int[]birthday;

public
Birthday2(int number)
{
num = number;
birthday = new int[num];

}

Edited 6 Years Ago by __avd: Added [code] tags.

'm having trouble with this code its part of a birthday profile for class everything else works but this date.cpp file....looked all throughout forms but can't find this particular one..Please help

@joewinsock. Why did you post java code here? Can you maybe provide some more information about what it is you are trying to do?

Edited 6 Years Ago by __avd: n/a

To be honest, it's looks like you have no clue what you're doing. You've pasted some mangled Java-code in a cpp file and hope it works.

Do you know the difference between Java and C++ ?
Did you copy-paste this code from somewhere on the web?

No i didn't copy n paste this code. And your telling me that my instructor is leading me in the wrong direction. ...How bout this

#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

#include "Date.h"
#include "Birthdate.h"
#include "InvalidDate.h"
#include "Person.h"

enum months {JANUARY=1, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER};
enum birthstones {GARNET = 1,AMETHYST,AQUAMARINE,DIAMOND,EMERALD,PEARL,RUBY,PERIDOT,SAPPHIRE,OPAL,TOPAZ,TURQUOISE};
string getBirthstone(months month)//helps return string
{
	string gem;
	switch(month)
	{
	case JANUARY:
		gem = "Garnet";
		break;
	case FEBRUARY:
		gem = "Amethyst";
		break;
	case MARCH:
		gem = "Aquamarine";
		break;
	case APRIL:
		gem = "Diamond";
		break;
	case MAY:
		gem = "Emerald";
		break;
	case JUNE:
		gem = "Pearl";
		break;
	case JULY:
		gem = "Ruby";
		break;
	case AUGUST:
		gem = "Peridot";
		break;
	case SEPTEMBER:
		gem = "Sapphire";
		break;
	case OCTOBER:
		gem = "Opal";
		break;
	case NOVEMBER:
		gem = "Topaz";
		break;
	case DECEMBER:
		gem = "Turquoise";
		break;
	}
	return gem;
}

Person user;

void setPersonName()
{
	char buffer[30];
	cout << "Enter your first name: ";
	cin>> buffer;
	user.setFirstName(buffer);
	cout << "Enter your last name: ";
	cin>> buffer;
	user.setLastName(buffer);

	return;

}
void setBirthdate()
{
	int day, mth, yr;

	cout<< " Enter your birth month: ";
	cin>>mth;

	cout<< " Enter your birth day: ";
	cin>>day;

	cout<< " Enter your birth year: ";
	cin>>yr;

	user.setBirthday(mth, day, yr);
	return;

}
void outputInfo()
{
	int mth, day, yr;
	Birthdate date;
	date = user.getBirthday();
	mth = date.getMonth ();
	day = date.getDay ();
	yr = date.getYear ();

	
	cout<< "Hello " << user.getFullName() <<endl;
	cout<< "You were born on: "<< setw (2)<<right<<setfill('0')<<mth<<'/'<<day<<'/'<<yr<<"."<<endl;
	cout<< "Your birthstone is: " << date.birthstone() <<endl;
	cout<< "Your zodiac sign is: " <<date.astroSign() <<endl;
	cout<< " You were born in: " << date.season() <<endl;
	return;
}
int main()
{
	int selection = 0;
	int i;
	int input;

	void (*f[3]) () = {setPersonName, setBirthdate, outputInfo};
	string name;
	
	Birthdate date;

	do
	{
	
		for (i = 0; i<5; i++)
			cout<<"   *";
		cout<<endl<<"  ";
		for (i = 0; i<5; i++)
			cout<<"*** ";
		cout<<endl;

		cout<<"0 - Enter name"<<endl;
		cout<<"1 - Enter birthdate" <<endl;
		cout<<"2 - Display information" <<endl;
		


		for (i = 0; i<5; i++)
			cout<<"   *";
		cout<<endl<<"  ";
		for (i = 0; i<5; i++)
			cout<<"*** ";
		cout<<endl;
		for (i = 0; i<5; i++)
			cout<<"   *";
		cout<<endl;

		cout<<"Select a menue item (-1 to exit)";
		cin>>selection;
		if (selection != -1)
			(*f[selection])();

	}while (selection != -1);
	  
	return 0;
}

i dare you to tell me thats java
do you know the difference
and why don't you copy and paste that code into your c++ and tell me what errors you get....I asked for help Not someone to accuse me of copy n pasting...

Edited 6 Years Ago by Nick Evan: added closing code-tag

>> i dare you to tell me thats java

I won't because it's C++. Your first post is a completely different code and not C++.

these are my errrors same date.cpp file
error C2653: 'TestBirthday' is not a class or namespace name ...line 9
error C2447: '{' missing function header(old-style formal list?) ....line 11
error C2447: '{' missing function header(old-style formal list?) ......line 23

#include "stdafx.h"
#include "date.h"
#include <string>
using std::string;
using namespace std;



class TestBirthday::Date(int num, int dup);
//public: static void main()
    {
        int num;
       
        cout<<"Enter number of people to test"<<endl;
        cin<<endl;
        num = Console.readInt();
       
        Birthday2 = new Birthday2(num);
        cout<<"The number of duplicates when testing " +num+ " people is "+ Birthday2.countDuplicates<< endl;
    }
//};
//class Birthday2;
{
    TestBirthday::Birthday2();
    int num;
    int[]birthday;
         Birthday2(int number)
    {
        num = number;
        int[]birthday = new int[num];
    }
        int countDuplicates()
    {
        boolean duplicate = false;
        int index = 0;
        int dup = 0;
        int day;
       
        while (index < num)
        {
            day = 1 + (int)(Math.random()*365);
            {
                duplicate = searchBirthdays(day,index);
                if (duplicate)
                    dup ++;
            }
            birthday[index] = day;
            index ++;
        }//end while
        return dup;
    }//end countDuplicates
   
private: boolean searchBirthdays(int bday, int end)
    {
        boolean found = false;
        int index = 0;
       
        while ((index < end) && (!found))
        {
            if(bday == birthday[index])
                found = true;
            index ++;
        }//end while
       
        return found;
    }
};

Edited 6 Years Ago by Nick Evan: Fixed closing tag

This article has been dead for over six months. Start a new discussion instead.