Thread: Problems defining classes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    37
    So,if I understood you correctly,since a owner can have multiple vehicles we should have a pointer in both classes?Something like this?:

    Code:
    class owner
    {
    private:
    
      string name;
      string address;
      long id;
      long phone;
    
    public:
    
      owner(string o_name,string o_address, long o_id,long o_phone);//constructor
      void getname (void) const;
      string setname(string o_name);
      //etc,other gets and sets 
    }
    
    class vehicle
     {
    private:
    
      string model;
      string brand;
      string license;
      long nr_oldowners;
    
    public:
    
      vehicle(string v_model,string v_brand,string v_license,long v_nr_oldowner)
      void getlicense (void) const;
      string setlicensestring o_name);
      //etc,other gets and sets 
    }
    
    class autoreg
    {
    
    private:
    
      vehicle *v;
      owner  *o;
    
    public:
    
         insert_v(string v_model,string v_brand,string v_license,long v_nr_oldowner);//is this okay??
    
         insert_o(string v_model,string v_brand,string v_license,long_nr_oldowner,string o_name,string o_address, long o_id,long o_phone););//is this okay??
    
         erase_o(string o_name,string o_address, long o_id,long o_phone););//is this okay??
    
         erase_v(string v_model,string v_brand,string v_license,long v_nr_oldowner););//is this okay??
    
         update(string v_model,string v_brand,string v_license,long_nr_oldowner,string o_name,string o_address, long o_id,long o_phone););//is this okay??
       
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, that would make more sense.

    Technically, vehicle could be constant part of the registry - there's no registration without a vehicle, only the owner may be shared between multiple vehicles.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    37
    You mean the
    Code:
    insert_v(string v_model,string v_brand,string v_license,long v_nr_oldowner)
    method,making it constant?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by esmeco View Post
    You mean the
    Code:
    insert_v(string v_model,string v_brand,string v_license,long v_nr_oldowner)
    method,making it constant?
    Not quite: just replace vehicle *v with vehicle v; this means that the vehicls is part of the registry, raher than something pointed to by the registry.

    Each registration concerns exactly and always one unique vehicle. The owner may or may not be unique, so you need a way to refer to an owner from more than one registration. This means that it has to be a pointer or some other type of reference [you could keep all owners in an array and keep the index of the owner in the registry, for example - but I think a pointer is better].

    [Edit]Also, I would probably just make functions to get and set things, rather than functions that take a lot of parameters and do lots of things.

    If you maintain the existing model with a pointer to a vehicle, you could even us a method "setVehicle(vehicle *av);" and "setOwner(owner *ao);". [/edit]

    --
    Mats
    Last edited by matsp; 10-11-2007 at 08:25 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. College Classes
    By nubby in forum C Programming
    Replies: 2
    Last Post: 10-07-2007, 12:32 AM
  2. Inheritance, overriding, problems
    By CodeMonkey in forum C++ Programming
    Replies: 8
    Last Post: 01-04-2007, 01:26 AM
  3. classes, inheritance and include problems
    By baniakjr in forum C++ Programming
    Replies: 6
    Last Post: 12-12-2006, 01:45 PM
  4. C++ Classes: Use, Misuse...Confusion.
    By Snorpy_Py in forum C++ Programming
    Replies: 4
    Last Post: 10-23-2006, 01:46 AM
  5. Sharing a variable between classes of different .CPP files
    By divingcrab in forum C++ Programming
    Replies: 5
    Last Post: 07-07-2002, 02:57 PM