Click here to Skip to main content
15,917,862 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: No Resize Pin
sschilachi29-Mar-04 8:31
sschilachi29-Mar-04 8:31 
GeneralRe: No Resize Pin
Prakash Nadar29-Mar-04 15:27
Prakash Nadar29-Mar-04 15:27 
GeneralRe: No Resize Pin
David Crow29-Mar-04 8:46
David Crow29-Mar-04 8:46 
GeneralRe: No Resize Pin
Rick York29-Mar-04 14:41
mveRick York29-Mar-04 14:41 
GeneralChange Propertysheet Color Pin
kimiko29-Mar-04 7:20
kimiko29-Mar-04 7:20 
GeneralRe: Change Propertysheet Color Pin
David Crow29-Mar-04 7:57
David Crow29-Mar-04 7:57 
GeneralRe: Change Propertysheet Color Pin
Prakash Nadar29-Mar-04 8:28
Prakash Nadar29-Mar-04 8:28 
Generalusing iterator to count though vector Pin
wadstar29-Mar-04 6:29
wadstar29-Mar-04 6:29 
ive been working on some simulation code, what i have written basically what it does it creates a Vector and fills it with random DOUBLE numbers from two different sources untill maz_size reached.. what im stuck is i want to go thorugh each element in the vector..prob using an iterator such as input_iterator i think?

so the vector is such..
[number_from_first_source, number_from_secondSource, number from_first source...etc etc]
so every odd element is form source1 and every even element is from source 2..

now i want to go thorugh each element with specific iterator value..example lets say 20ms i.e. 0.002..quite small value. the random numbers are all seeded values. so how owul di go through the vector with this small iterator value.

i will paste the written code.

]#include <iostream><br />
#include <vector><br />
#include <stdlib><br />
#include <time><br />
#include <numeric><br />
#include <algorithm><br />
#include "exponentialgenerator.h"<br />
<br />
using namespace std;<br />
<br />
ExponentialGenerator one = 1.41;<br />
ExponentialGenerator two = 1.71;<br />
<br />
double nextNumber = reinterpret_cast<double>one.generate());<br />
double nextNumber2 = reinterpret_cast<double>two.generate());<br />
int counter = 0;<br />
<br />
void fillVectorToSum(vector<double>& v, double sum)<br />
{<br />
<br />
int total = 0;<br />
do {<br />
if (counter++ % 2){<br />
v.push_back(nextNumber);<br />
total += nextNumber;<br />
nextNumber = one.generate();<br />
}<br />
else {<br />
v.push_back(nextNumber2);<br />
total += nextNumber2;<br />
nextNumber2 = two.generate();<br />
}<br />
<br />
} while(total+nextNumber+nextNumber2 <= sum);<br />
if(total < sum)<br />
v.push_back(sum-total);<br />
}<br />
<br />
int main()<br />
{<br />
<br />
srand((unsigned) time(NULL));<br />
vector<double> v;<br />
fillVectorToSum(v, 30);<br />
<br />
cout << "Number of elements: " << v.size() << "\nTotal: "<br />
<< accumulate(v.begin(), v.end(), 0) << endl;<br />
copy(v.begin(), v.end(), ostream_iterator<double> (cout," "));<br />
<br />
}


the exponentialGenerator.h file i use jus to generate numbers if your wondering....

anyway any input to this problem would be appreciated.
GeneralRe: using iterator to count though vector Pin
valikac29-Mar-04 6:44
valikac29-Mar-04 6:44 
GeneralRe: using iterator to count though vector Pin
Anonymous29-Mar-04 6:59
Anonymous29-Mar-04 6:59 
GeneralRe: using iterator to count though vector Pin
Antony M Kancidrowski29-Mar-04 7:37
Antony M Kancidrowski29-Mar-04 7:37 
GeneralScroll Bars in Dialog Pin
Rassul Yunussov29-Mar-04 6:24
Rassul Yunussov29-Mar-04 6:24 
GeneralRe: Scroll Bars in Dialog Pin
ohadp29-Mar-04 19:55
ohadp29-Mar-04 19:55 
GeneralRemoving ding Pin
doctorpi29-Mar-04 6:04
doctorpi29-Mar-04 6:04 
GeneralRe: Removing ding Pin
David Crow29-Mar-04 8:03
David Crow29-Mar-04 8:03 
GeneralRe: Removing ding Pin
Prakash Nadar29-Mar-04 8:31
Prakash Nadar29-Mar-04 8:31 
GeneralRe: Removing ding Pin
doctorpi30-Mar-04 2:29
doctorpi30-Mar-04 2:29 
GeneralLimiting dekstop(maximized windows') size Pin
clayman8729-Mar-04 5:20
clayman8729-Mar-04 5:20 
GeneralRe: Limiting dekstop(maximized windows') size Pin
valikac29-Mar-04 6:46
valikac29-Mar-04 6:46 
GeneralRe: Limiting dekstop(maximized windows') size Pin
Michael Dunn29-Mar-04 8:30
sitebuilderMichael Dunn29-Mar-04 8:30 
Generalnamespace std Pin
BlackDice29-Mar-04 5:03
BlackDice29-Mar-04 5:03 
GeneralRe: namespace std Pin
Chris Losinger29-Mar-04 5:35
professionalChris Losinger29-Mar-04 5:35 
GeneralRe: namespace std Pin
BlackDice29-Mar-04 5:40
BlackDice29-Mar-04 5:40 
Generalerror C1010 Pin
dadacncn29-Mar-04 4:40
dadacncn29-Mar-04 4:40 
GeneralRe: error C1010 Pin
ohadp29-Mar-04 4:48
ohadp29-Mar-04 4:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.