473,406 Members | 2,352 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,406 software developers and data experts.

Advice on Data structure for storing mixed type elements

4
I am a newbie in programming and I need some advice on storing of multiple types of data together.

My method takes in a String Array as parameter. This string array basically is an array of Chemical elements.

Expand|Select|Wrap|Line Numbers
  1.  
  2. String[] elements = { Calcium, Potassium, Magnesium, Sodium} 
I iterate through each element of the array and call another method that takes in each chemical element as a parameter and calculates 4 values.

Expand|Select|Wrap|Line Numbers
  1. for (int i = 0; i < elements.Length; i++)
  2. {
    ...some lines of code
  3. GetDerivedPropertyValues(Calcium);}
  4.  
Now before I pass the next element as the function parameter, I need to store the 4 values calculated by the method for that corresponding element.

For this reason, I think I may need an ArrayList ( I could be completely wrong though) which stores the first element as a string type i.e the Element Name, and the remaining 4 double values.

Alternatively, I can also create a double array of size 4 to store the 4 calculated values and call each array by the element name

for example,
Expand|Select|Wrap|Line Numbers
  1. double[] calcium = new double[4]
I dont know how to programmatically name the array according to each element of the initial string array.

Please help me and excuse my lack of knowledge if this is a well documented scenario but I simply didn't knew where to look.

Thanks.
Mar 3 '10 #1
4 2608
tlhintoq
3,525 Expert 2GB
I think I would make a class that contains everything together.


Expand|Select|Wrap|Line Numbers
  1. class ChemElem
  2. {
  3.    public string name;
  4.    public string value1;
  5.    public string value2;
  6.    public string value3;
  7.  
  8.    public Calculate()
  9.    {
  10.        // Do work here
  11.    }
  12. }
  13.  
Now you can can make a new ChemElem.
Set the name
Call the Calculate() method which will populate the values.
Then send the ChemElem around your program as needed, and it will have the name and values together.
Mar 3 '10 #2
kwm123
4
Hi tlhintoq , Thanks for your response. I indeed call the calculate method exposed from another class as you have suggested but the thing is I need to store all the values together in a datastructure such as an array or a list as my further calculations require operations such as comparision and other mathematical interactions of related values of different chemical elements´.

So any more suggestions and advices for storing together strings and doubles of each chemical element?
Mar 4 '10 #3
tlhintoq
3,525 Expert 2GB
What was wrong with the suggestion of using a class?
Mar 4 '10 #4
kwm123
4
I think using class is an elegant solution for object oriented approach of calculating multiple values and code reuse. But how about storing those values together for not one but multiple calculations.

For Example, I have a method exposed by a class that takes in the element name and the temperature and calculates multiple temperature dependent properties. For example, when I call a function exposed by a class,
Expand|Select|Wrap|Line Numbers
  1.  GetDerivedProperties(Titanium, 1800)
I get 4 resulting double values:
  1. Partial pressure
  2. Partial Molar Volume
  3. Partial Density
  4. Partial Viscosity
Now, what do you think is the best way to store these 4 values of different elements together? For instance, if I call 7 times, the GetDerivedProperties(element, temp) function for 7 different elements and store the values of each element?
Mar 8 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dennis Gavrilov | last post by:
Hi, All! I have two questions: strategic and technical. Technical one first: I need to share an array of objects (implemented as hashes, having references to other objects and hashes, sharing...
0
by: Cees Wesseling | last post by:
For a couple of years I am using now my own data binding tool that can create C++ classes from a DTD. At this moment I need to reconsider this tool since I want to use W3C XML Schemas and need to...
0
by: Adam Retter | last post by:
I am storing information about community groups. Each group has an XML file in a collection in eXist. For each community group I need to be able to store its template type and then a set of...
6
by: supercomputer | last post by:
I am using this function to parse data I have stored in an array. This is what the array looks like: , , , , , , , , , , , , , , , , , , , , , , , ] This is the code to parse the array:
2
by: SophistiCat | last post by:
Hi, I am working on a computational program that has to read a number of parameters (~50) from an input file. The program contains a single class hierarchy with about a dozen member-classes or...
5
by: Alfonso Morra | last post by:
Hi, I am writing a messaging library which will allow me to send a generic message structure with custom "payloads". In many cases, a message must store a non-linear data structure (i.e....
5
by: Loui Mercieca | last post by:
Hi, In my design i have a data structure used to store large amount of numbers ( in the range of lots of thousands ). Each element contains 3 items and the no of elements are dynamic.. of the...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
2
by: mirandacascade | last post by:
Situation is this: 1) I have inherited some python code that accepts a string object, the contents of which is an XML document, and produces a data structure that represents some of the content of...
11
by: Cliff Martin | last post by:
Hi, I am reading a fairly large file a line at a time, doing some processing, and filtering out bits of the line. I am storing the interesting information in a struct and then printing it out....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.