473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

table with text and numbers

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
Jul 23 '05 #1
6 1938
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
Jul 23 '05 #2
"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.

Jul 23 '05 #3

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.

Jul 23 '05 #4
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

Jul 23 '05 #5
<jo*********@gmail.com> 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.
Jul 23 '05 #6

"Johan" <jo*********@gmail.com> wrote in message
news:63**************************@posting.google.c om...
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


Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael Lauzon | last post by:
This is not for a class, I have a group on SourceForge, this is what one of the Developers is asking; the more advanced you can make it right off all the better!: Can someone please create...
10
by: Andrew Thompson | last post by:
http://www.physci.org/test/chem/element.html, represents information on a chemical element. (http://www.physci.org/test/chem/ for the CSS's) Not yet coded for links to other forms of the...
20
by: WindAndWaves | last post by:
Hi Gurus I was wondering if you can send me in the right direction: I have a table with about 300 rows. I want to make all of them invisible and when a user enters a code in a form then make...
4
by: Kim14 | last post by:
I have a table that works fine in IE, but doesn't work in Netscape or Firefox. It should automatically come up with numbers in some of the fields and depending what is entered, it should calculate...
2
by: Yeah | last post by:
Hi, all! I have a question. I am designing a listing similar to a phone book in HTML. Each listing has periods following it, but they must extend to the end of the table cell, and not wrap. ...
4
by: Bob | last post by:
Hi all, I've got a table that I've imported and it has junk at the top of the table, so after import I run a delete query to remove the junk lines then I'm left with the field names I want for...
17
by: Stubert | last post by:
I have a training module db that stores information about employees and what training they have carried our or need to carry out. One table in this database stores what training needs to be carried...
7
by: Lucas_london via AccessMonster.com | last post by:
Hi I have set up a database/tables in Access based on daily timeseries data. However I would like to create two additional columns in the table as a basis to pull the data on a weekly and...
3
by: pranav13 | last post by:
hi all, im pranav. i have a table with checkbox, sno, book name, book price as coloumns in it. Everything is 5ne while adding and deleting rows. But my requirement is that, now i want to update...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.