table array problem

i have a problem in making an array representing a table as following: i have to prompt the user to enter x,y values to get another value needed for
calculation so making a 2d array like a[x][y] to get another value in the equation but the problem is that all the values of x, y are not integer numbers
and no linear relation to convert them to integers
ex. values of y are 1.38, 1.3958 , 1.3982
values of x are .3 , .358 , .387
to get the desired values










closed account (Lv0f92yv)
You can use floats to store those numbers as well...
float table[x][y];

the problem is not the number i want to save but the number representing those values:
for example:

double a[x][y]={1,2,3
4,5,6}
i want to prompt the user to enter x,y to represent the number inside the array but x,y are not integers.
as following:
he must enter diameter 1.334 inch with beta ratio .345 to represent a value of a factor=2 to be used in my equation
Last edited on
closed account (Lv0f92yv)
Do you have any code written for this? If you do, can you please post it?

I'm not sure I understand what the problem is.
Let me try to understand. You want some way to represent diameter with beta_ration gives value.

E.g
diameter1 with beta_ratio1 = 2
diameter2 with beta_ratio2 = 3
diameter3 with beta_ratio3 = 4
...
above is stored in an "array"

That is, your key is a "composite pair of diameter with beta_ratio" and the value is what we want to retrieve later on in your program correct ?

E.g
I pass in diameter1 and beta_ratio1 and I expect to retrieve from the "array" the value of 2 correct ?

"array" can be a vector, map, list, multi-map etc etc.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//ASSUMPTION! You are going to limit the decimal places to be stored for diameter and 
//beta_ratio else comparison will fail later on!!!

class MyClass {
  public:
  MyClass(float diameter, float beta_ratio, int value) : m_diameter(diameter), 
m_beta_ratio(beta_ratio), m_value(value) {}

  float m_diameter;
  float m_beta_ratio;
  int m_value;
}

class CanFind {
  public:
  CanFind(float diameter, float beta_ratio) : m_diameter(diameter), m_beta_ratio(beta_ratio) {}
  bool operator()(MyClass& obj) {
    if (obj.m_diameter == m_diameter && obj.m_beta_ratio == m_beta_ratio) return true;
    else return false;
  }

  float m_diameter;
  float m_beta_ratio;
}

vector<MyClass> vec;
vec.push_back(MyClass(1.334, .345, 2));
...

vec<MyClass>::iterator itr = find_if(vec.begin(),vec.end(),CanFind(1.334,.345));
if (itr!=vec.end()) cout << itr->m_value;
Last edited on
excellent,
that is exactly what i meant
thanks very much
it was a problem i faced with a lot of talbles of data that non integer values needed to represent a certain value of an array.
Topic archived. No new replies allowed.