Hey there, wonder if you can help me..

I have three classes:
1. Person
2. Accounts
3. Purchases
(Accounts and Purchases both inherit from Person)

You don't need an account to make a purchase but if you do you'll enter your: name, address etc..

The problem I'm having is association. The account will associate with the purchases and I'm thinking something like the object:

int main()
{
     Purchases Receipt;
     Account a;
     cout << "Please enter your name: ";
     cin >> name;
 
     cout << "Please enter your age: ";
     cin >> age;
 
     cout << "Please enter your address: ";
     cin >> address;
     
     cout << "Please enter the Product ID: ";
     cin >> product_id;

     a.setName(name);
     a.setAge(age);
     a.setAddress(address);
     a.setProduct(product);

     Receipt.setValues(name, age, address, product);
     cout << Receipt.getValues() << endl;

All these values are stored in the different classes.

In the functions for purchases there will be a function like:

Purchases::setValues(char theName[], int theAge, char theAddress[], int theProduct)
{
     strcpy(name, theName[]);
     age = theAge;
     strcpy(address, theAddress[]);
     product = theProduct;
}

Is that Association or have I missed the point?

Thanks guys

Hey there, wonder if you can help me..

I have three classes:
1. Person
2. Accounts
3. Purchases
(Accounts and Purchases both inherit from Person)

You don't need an account to make a purchase but if you do you'll enter your: name, address etc..

The problem I'm having is association. The account will associate with the purchases and I'm thinking something like the object:

int main()
{
     Purchases Receipt;
     Account a;
     cout << "Please enter your name: ";
     cin >> name;
 
     cout << "Please enter your age: ";
     cin >> age;
 
     cout << "Please enter your address: ";
     cin >> address;
     
     cout << "Please enter the Product ID: ";
     cin >> product_id;

     a.setName(name);
     a.setAge(age);
     a.setAddress(address);
     a.setProduct(product);

     Receipt.setValues(name, age, address, product);
     cout << Receipt.getValues() << endl;

All these values are stored in the different classes.

In the functions for purchases there will be a function like:

Purchases::setValues(char theName[], int theAge, char theAddress[], int theProduct)
{
     strcpy(name, theName[]);
     age = theAge;
     strcpy(address, theAddress[]);
     product = theProduct;
}

Is that Association or have I missed the point?

Thanks guys

Kind of hard to comment when you haven't posted what is stored where. I imagine that name, age, and address are stored in Person, and product is stored in Purchase. If I were to have Purchase inherit from Person, that's how I'd store it. I'm not sure I'd have Purchase inherit from Person though. I might instead have a Person have a vector of Purchases stored in it rather than have inheritance.

Similarly with "Account". I'm not sure I'd have "Account" inherit from "Person". Certainly they are linked. An Account doesn't make sense without a Person attached to it, and they need to be able to find each other, but I don't know that inheritance is the correct relationship. An Account isn't a type of Person. I'd think that "Boy" and "Girl" or "Child" and "Adult" could inherit from "Person". "Account" and "Purchase" seem like they should be their own classes and they could have a reference to a Person to link them.

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.