Thread: Vectors and Classes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2020
    Posts
    1

    Lightbulb The Way of the Structures of Arrays

    Not Relevant: Psst, hey, don't follow the OOP hole; it's scary
    Super Relevant: ..psst, try this

    (0) let's suppose we have a Data Structure named BUFFER

    (1) the first container in BUFFER is a
    Code:
     vector<uint32_t> _id_
    (1.1) _id_ contains all the passengers ids; Attention: All ids are unique, like all people on this earth.. and all ids are natural numbers (e.i 1,2,3,4,..).
    (1.2) _id_ is the most trivial and important container in BUFFER
    (1.3)
    every new passenger gets a new id; if for some
    Code:
    n >= 0, if (_id_[n] <= 0) is true 
    then the nth passenger does not exist.
    (2.) Every passenger has a known/fixed number of features like the ones you mentioned (they could have more). These features are: age; phone number; ACTUAL id number; flight "something"; "has the passenger arrived yet"; "how many cpu cycles did he skip due to his inability to recognize the presence of a well established dogma" (passive aggressive OOP vs DOD pun); The number of bags he brings; etc. NOTICE that all of these features are addressable via native types (unsigned int, int, bool(C doesn't like these), and more);
    (2.1) The next part is to create a container for each feature of type passenger feature type that we want to address.
    very Pseudo-code
    Code:
    BUFFER{
        Vec<uint32> _id_;
        /*containers with the passenger features */
        Vec<uint32> _planeID_;
        Vec<uint8> _numBags_;
        .
        .
    }
    In a short schema:
    Code:
    for some n >= 0
    _id_[n] : id of nth passenger
    _numBags_[n] : number of bags the nth passenger brings
    _planeID_[n] : the id of the aircraft the nth passenger was assigned to
    , provided that (_id_[n] > 0) is true
    You could also have an AIRCRAFT_BUFFER with the same formatting.

    I mean, this is one way of Designing your structures of data before you start filling anything with eternal loops of iterators; I like this way a lot. This was the first thing that came out of the top of my head.. hope i could've helped with the designing part. stay safe; stay oop minimal.
    Last edited by coddiwomple; 05-07-2020 at 09:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Classes/Vectors help!
    By bigboybz in forum C++ Programming
    Replies: 8
    Last Post: 03-03-2011, 03:42 AM
  2. Vectors of classes
    By Dondrei in forum C++ Programming
    Replies: 26
    Last Post: 03-20-2009, 05:11 AM
  3. classes and vectors
    By izuael in forum C++ Programming
    Replies: 10
    Last Post: 11-27-2006, 04:19 PM
  4. Classes or Vectors?
    By Ideswa in forum C++ Programming
    Replies: 4
    Last Post: 04-08-2006, 10:07 AM
  5. vectors and classes
    By kooma in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2002, 12:44 PM

Tags for this Thread