Homework help!!!

Hi, I'm currently working on my homework and got stuck with classes so it would be very helpful if anyone can help me work out my problem.

-the program is basically reads 2 input files and make an appointments book for each person using 3 classes.
1. appointment class is to hold appointment( ids of 2 people and time of appointment)
2. date class is to hold time(month, day, year, and hour)
3. person class is to hold (id, first name last name, and an array of appointments)

Here are my classes

Appointment class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
	Appointment::Appointment()
	{
	}
	Appointment::Appointment(int personID, const Date& date) throw(logic_error)
		:personToMeetID(personID), date(date)
	{
		//throw some logic error
	}

	Date Appointment::getMeetingDate() const
	{
		return date;
	}
	int Appointment::getPersonToMeetID() const
	{
		return personToMeetID;
	}

	void Appointment::setMeetingDate(const Date& d)
	{
		date = d;
	}
	
	void Appointment::setPersonToMeetID(int id)
	{
		personToMeetID = id;
	}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
	Person::Person()
	{}
	//DONE
	Person::Person(string fName, string lName, int id)
		:firstName(fName), lastName(lName), ID(id)
	{}

	string Person::getLastName() const
	{
		return lastName;
	}
	string Person::getFirstName() const
	{
		return firstName;
	}
	int Person::getID() const
	{
		return ID;
	}

	bool Person::isFree(const Date& time) const //is person available at this time?
	{
		Person person;
		if(person.isFree(time))
			return true;
		else
			return false;
	}

	void Person::setName(string first, string last)
	{
		firstName = first;
		lastName = last;
	}
	void Person::setID(int id)
	{
		ID = id;
	}

	void Person::makeAppointment(Date time, int id)  // id is person to meet
	{
              //NEED HELP WITH THIS FUNCITON
	}

	void Person::printAppointments(ostream& out,Person person[],int totalPeople) const
	{
             //NEED HELP WITH THIS FUNCITON
	}
	   ostream& operator << (ostream& out, const Person& p)
   {
	   return out<<p.ID<<" "<<p.firstName<<" "<<p.lastName<<" "<<p.appointmentBook;
   }
   istream& operator >> (istream& in, Person& p)
   {
	   return in>>p.ID>>p.firstName>>p.lastName;
   }


Person.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

using namespace std;
class Person{
public:
	Person();
	Person(string fName, string lName, int id);
	string getLastName() const;
	string getFirstName() const;
	int getID() const;
	bool isFree(const Date& time) const; //is person available at this time?
	void setName(string first, string last);
	void setID(int id); 
	void makeAppointment(Date time, int id);  // id is person to meet
	void printAppointments(ostream& out,Person person[],int totalPeople) const;

  friend ostream& operator << (ostream& out, const Person& p);
  friend istream& operator >> (istream& in, Person& p);

private:
	int ID;
	string firstName;
	string lastName;
	static const int maxAppointments = 200;
	Appointment appointmentBook[maxAppointments];
	int numAppointments;
};

#endif 


appointment.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

class Appointment{
public:
	Appointment();
	Appointment(int personID, const Date& date) throw(logic_error);

	Date getMeetingDate() const;
	int getPersonToMeetID() const;
	void setMeetingDate(const Date& d);
	void setPersonToMeetID(int id);
private:
	int personToMeetID;  // id of person to meet
	Date date;

};

#endif 


I dont know if my isFree function is correct and i'm stuck with make appointment function. Can anyone explain this for me. Thanks a lot

here is test input file: (firstID, secondID, year, month, day, hour)
888888 333333 1776 12 26 8
999999 444444 1776 7 18 7
666666 222222 1776 2 14 12
555555 333333 1776 7 1 14
666666 111111 1776 7 23 15
777777 333333 1776 4 18 19
999999 222222 1776 12 26 18


Here is people.txt file (ID, FirstName, LastName)
111111 George Washington
222222 Martha Washington
333333 Thomas Jefferson
444444 James Madison
555555 Alexander Hamilton
666666 James Madison
777777 Dolley Madison
888888 John Adams
999999 Abigail Adams

Here is sample output file
George Washington 111111:
James Madison 666666 7/23/1776 3 p.m.
Dolley Madison 777777 8/13/1776 2 p.m.
Thomas Jefferson 333333 2/26/1776 1 p.m.
Dolley Madison 777777 1/30/1776 8 a.m.
Thomas Jefferson 333333 5/10/1776 7 p.m.
Thomas Jefferson 333333 2/5/1776 3 p.m.
Alexander Hamilton 555555 8/29/1776 11 a.m.
James Madison 666666 4/17/1776 3 p.m.
James Madison 444444 5/30/1776 5 p.m.

I think it compares the ID with firstID and SecondID, if the IDs are the same, it will add to the appointment book for each person
For:
1
2
3
4
5
6
7
8
	bool Person::isFree(const Date& time) const //is person available at this time?
	{
		Person person;
		if(person.isFree(time))
			return true;
		else
			return false;
	}


You are essentially calling your isFree method recursively. when you say person.isFree(time). You need to actually define what that method does in there. You are going to want to look at the calling Person Appointments and see if they are free. Then return true or false there.

Also, I believe you are testing if a newly created Person person is free and not the calling Person in your code. You should use this->isFree(time) to test the calling Person. (But again that cannot be within the isFree function.
Topic archived. No new replies allowed.