table with text and numbers

Discussion in 'C++' started by Johan, Apr 27, 2005.

  1. Johan

    Johan Guest

    Dear experts,

    I am new to c++ (arriving from java) and I am having to implement a
    data table that contains cells with numbers and cells with text. I
    would appreciate any general indications about what would be the best
    approach, bearing in mind that performance will be critical.

    Many thanks

    Johan
     
    Johan, Apr 27, 2005
    #1
    1. Advertising

  2. Johan wrote:
    > I am new to c++ (arriving from java) and I am having to implement a
    > data table that contains cells with numbers and cells with text. I
    > would appreciate any general indications about what would be the best
    > approach, bearing in mind that performance will be critical.


    Using std::vector<std::vector<std::string> > seems the most straight-
    forward. If you know the dimensions of the "table" ahead of its
    creation, you could use a simple two-dimensional array of std::string.

    Since you didn't say what you're going to do with the table or its
    cells, "performance will be critical" has no meaning. Perhaps if you
    state the requirements, as in "performance to resize" or "performance
    to replace data" or "performance to search"...

    V
     
    Victor Bazarov, Apr 27, 2005
    #2
    1. Advertising

  3. Johan

    Uenal Mutlu Guest

    "Johan" wrote
    > Dear experts,
    >
    > I am new to c++ (arriving from java) and I am having to implement a
    > data table that contains cells with numbers and cells with text. I
    > would appreciate any general indications about what would be the best
    > approach, bearing in mind that performance will be critical.


    It depends on your requirements (ie. whether dupes ok or not, auto-sorted or not etc.).
    But basically you define what a cell item is and then make an array of it.
    You can also use std::vector, std::set, std::list, std::map, std::multimap etc. etc.
     
    Uenal Mutlu, Apr 27, 2005
    #3
  4. Johan

    Guest

    Uenal Mutlu wrote:
    > "Johan" wrote
    > > Dear experts,
    > >
    > > I am new to c++ (arriving from java) and I am having to implement a
    > > data table that contains cells with numbers and cells with text. I
    > > would appreciate any general indications about what would be the

    best
    > > approach, bearing in mind that performance will be critical.

    >
    > It depends on your requirements (ie. whether dupes ok or not,

    auto-sorted or not etc.).
    > But basically you define what a cell item is and then make an array

    of it.
    > You can also use std::vector, std::set, std::list, std::map,

    std::multimap etc. etc.
     
    , Apr 27, 2005
    #4
  5. Johan

    Guest

    THanks for your answers.

    A bit of info about what I need to implement. The size of the table
    will be unknown until runtime. The table will be fairly big (a few
    thousands of cells) and will contain both numbers and text strings at
    the same time. Numbers will have to remain as such in order to do
    maths with them.
    Once the table has been acquired, regrouping of cells will be done: 1
    cell from every 2x2, with a content (text of number) calculated through
    certain algorithms on the 4 grouped cells. Then further groupings: 1
    cell with every 4x4, 8x8...). The original table needs to be preserved
    and change of views will be done, forth and back, responding to user
    actions, in real time.

    Many thanks for any further comments on how to implement this

    J
     
    , Apr 27, 2005
    #5
  6. Johan

    Uenal Mutlu Guest

    <> wrote
    > THanks for your answers.
    >
    > A bit of info about what I need to implement. The size of the table
    > will be unknown until runtime.


    But when it is known is it then constant?

    >The table will be fairly big (a few
    > thousands of cells) and will contain both numbers and text strings at
    > the same time. Numbers will have to remain as such in order to do
    > maths with them.
    > Once the table has been acquired, regrouping of cells will be done: 1
    > cell from every 2x2, with a content (text of number) calculated through
    > certain algorithms on the 4 grouped cells. Then further groupings: 1
    > cell with every 4x4, 8x8...). The original table needs to be preserved
    > and change of views will be done, forth and back, responding to user
    > actions, in real time.
    >
    > Many thanks for any further comments on how to implement this


    From C++ point of view this is basic stuff.
    I don't know what types your cell contains (ie. is it an integer or floating point
    number, and can the string be arbitrarily long or is there a max length),
    but you have multiple ways to chose from. The simplest but maybe not
    that mighty would be something like:

    struct Cell
    {
    int iVal;
    char szStr[64];
    };

    Cell* paCell = new Cell[nCells];

    where nCells is the number of cells to allocate dynamically.
    This is a 1-dimensional array of Cells; you can also make it n-dimensional.

    Here you must delete the resource when finished by using
    delete [] paCell;
    On the other hand, depending on the class used, STL does the allocation
    either in the constructor or when a new item gets added, and frees the
    resource(s) in its destructor.

    You just need to specify your application requirements as complete
    as possible, but this is of course obvious for any language used.
    I personally would recommend to use STL classes.
     
    Uenal Mutlu, Apr 27, 2005
    #6
  7. Johan

    Howard Guest

    "Johan" <> wrote in message
    news:...
    > Dear experts,
    >
    > I am new to c++ (arriving from java) and I am having to implement a
    > data table that contains cells with numbers and cells with text. I
    > would appreciate any general indications about what would be the best
    > approach, bearing in mind that performance will be critical.
    >
    > Many thanks
    >
    > Johan


    When you talk about "cells", are you just talking conceptually, or do you
    mean some kind of graphical display, like you see in spreadsheet programs?
    The standard C++ language does not provide graphical support (GUI, mouse,
    etc.), if that's what you're ultimately looking for. For that you need a
    third-party library (like MFC in Visual C++, for example). But if all you
    want is the storage method, then something like std::vector (or one of the
    other containers) might be appropriate. Which one depends on the type of
    operations you need to do (sorting, inserts, deletes, etc.) (Or, perhaps
    you're interested in a real database, such as SQL or Access? In that case,
    you'd again need to go to some third-party software.)

    -Howard
     
    Howard, Apr 27, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Subra
    Replies:
    25
    Views:
    1,256
    user923005
    Mar 8, 2007
  2. Andrew Tatum

    Fibonacci Numbers and Lucas Numbers

    Andrew Tatum, May 26, 2007, in forum: C++
    Replies:
    6
    Views:
    608
    Howard
    May 27, 2007
  3. Lance Hoffmeyer
    Replies:
    2
    Views:
    549
    Lance Hoffmeyer
    Jul 26, 2007
  4. jko170
    Replies:
    9
    Views:
    137
    jko170
    Jan 21, 2009
  5. GIMME
    Replies:
    5
    Views:
    200
    Thomas 'PointedEars' Lahn
    Jul 26, 2004
Loading...

Share This Page