DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Discrete solution help! (http://www.daniweb.com/forums/thread158566.html)

burhanms Nov 20th, 2008 10:28 am
Discrete solution help!
 
Hello,

I work on a problem and I want my solution to be picked from discrete numbers.( I want a value for diameter and I want it to be selected from the available diameter values)

Does anyone know it can be done with C++ and how?

Thanks

niek_e Nov 20th, 2008 11:20 am
Re: Discrete solution help!
 
I'm not sure if I understand the question correctly, but if you want a bunch of numbers which you can choose from, you could use vectors.
Example:
    vector<int> diameters;
    /* load a few bogus values */
    diameters.push_back(1);
    diameters.push_back(5);
    diameters.push_back(7);
    /*display available numbers */
    cout << "numbers available: ";
    for (unsigned int i = 0; i < diameters.size(); i++)
        cout << diameters[i] << " ";

output:
numbers available: 1 5 7

Alex Edwards Nov 20th, 2008 12:24 pm
Re: Discrete solution help!
 
If you have a finite number of values and they aren't going to change, you can get away with using a standard array instead of a vector.

This is only if you have a static amount of values and performance is an issue. If performance doesn't matter, use a vector as suggested from niek_e since you get the perks of a dynamic array as well as information about its size and the ability to use STL algorithms with it to manipulate, copy or iterate through its contents... etc.

-Alex

MosaicFuneral Nov 20th, 2008 1:58 pm
Re: Discrete solution help!
 
You mean if you have a radius, circumference, etc. then solve it?

http://www.mathopenref.com/diameter.html


All times are GMT -4. The time now is 6:01 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC