Trouble with data structures
Apr 4, 2012 at 12:43am UTC
This is my first time using structs and I'm having trouble with understanding how to use one. I need to use a struct to organize the information for each sample.
This is the file that I must read the data from:
Total Number of Samples:\n
8\n
Tests Per Sample:\n
5\n
Lot:\t Sample:\t Emf (volts):\t Measured Current (mA): \n
2A304\t 1\t 100 120 140 160 180\t 26.67 32.97 38.57 42.78 49.32\n
2A304\t 3\t 100 120 140 160 180\t 26.39 31.41 36.94 38.00 48.52\n
4B501\t 1\t 100 120 140 160 180\t 29.24 0 37.53 42.67 48.52\n
3C201\t 1\t 100 120 140 160 180\t 26.67 32.96 38.51 42.84 0\n
4B501\t 2\t 100 120 140 160 180\t 26.67 0 0 43.36 48.78\n
2A304\t 4\t 100 120 140 160 180\t 26.67 32.97 38.57 42.78\n
3C201\t 3\t 100 120 140 160 180\t 26.25 33.01 38.54 42.84 49.12\n
3C201\t 4\t 100 120 140 160 180\t 26.67 32.96 38.51 42.84 0\n
I need to allow for 10 tests per sample and 10 samples per lot. Do I need to use a struct within a struct or something?
Apr 4, 2012 at 3:57am UTC
Create a struct like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
struct Sample {
int lot;
int sampleID;
// this might also be a vector
size_t nTests;
Test[] tests;
};
struct Test {
int emf;
double ma;
}
Apr 4, 2012 at 2:54pm UTC
Thanks for the help! What is size_ t nTests though?
Apr 4, 2012 at 10:40pm UTC
The number of tests. size_t is a typedef that measures the size of an array, like int.
You could also do vector<Test>, then you don't need to keep track of nTests.
Apr 5, 2012 at 4:30pm UTC
Ok thanks. This was really helpful
Topic archived. No new replies allowed.