I have a questions about classes in C++. I'm working on a homework assignment where I have a class called Person and a derived class called Doctor. I also have two other classes that are called Date and Bill. I'm suppose to create a class drived from Person and call it Patient.The only thing thats tripping me up is that the Patient class should hold information from the Bill class and the Date class. I was thinking that I should create nonmember functions in Bill and Date that would allow a Patient object to access the members in both class, but I'm not sure if that's legal.

You can declare objects of type Bill and Date and use the public members in your class. For instance:

class Date
{
public:
    int year;
    string month;
    int day;
    int hour;
    int minute;
    Date()
        :year(1900),
        month("Jan."),
        day(1),
        hour(0),
        minute(0)
    {
    }
};
class Bill
{
public:
    Date lastPayment;
    Date nextPayment;
    double amountOwing;
    Bill()
        :amountOwing(0.00)
    {
    }

};
class Person
{
public:
    string firstName;
    string lastName;
    Address address;
    Person()
        :firstName(""),
        lastName("")
    {
    }
};
class Doctor : Person
{
};
class Patient : Person
{
    Bill bill;
    Date lastAppointment;
    Date nextAppointment;
};

When you declare an object of type Bill,Bill bill;, you can access the public members of the Date class through the objects lastPayment and nextPayment(bill.lastPayment.year).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.