-2

The goal of my program is to allow the user to enter up to 100 names for people and 100 names for cars. Then the user can "register" a car to as many people as s/he wishes using pointers. I know I need a person class and a car class and I need to use two arrays of size 100 for each. But I am completely lost on how to set anything else up. I have done a lot of researching to try and figure something out. I would be extremely appreciative if anyone could give me some basic example code for how something like this could be done.

I don't have much code:

class Person{
public:
    person();
    Car* in_car;
};

class Car{
public:
    Car();
};

int main()
{
    Car cars[101];
    Person people[101];
}
3
  • 1
    Paste the code maybe help more. Commented Apr 26, 2017 at 6:31
  • start cr eating the objects and use data structures for associations Commented Apr 26, 2017 at 6:33
  • Could you be more specific as to how to use data structures for association? Commented Apr 26, 2017 at 6:37

1 Answer 1

0

You could add a vector of car pointers to the People class.

class People{
...

private:

vector<Car*> _pointer;
};
Sign up to request clarification or add additional context in comments.

3 Comments

The code I'm creating now will be used in part of a larger project where it will be necessary to have used an array
It is probably better to use a std::set for tracking the association, this would avoid duplicate registration.
No problem you can substitute vector for array. stackoverflow.com/questions/8399001/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.