1,177 Posted Topics

Member Avatar for free radical

You are generating the number, and then outputting it 6 times! You need to move the random generation into the loop [code] for (int count = 0; count < 6 ; count++) { number_back = rand() % 53 + 1; cout<<number_back<<endl; } [/code]

Member Avatar for Danny_501
0
95
Member Avatar for 1newguy

Can you please ask a specific question rather than just posting code? And also in the response - what seems to be added was the foreign() definition?

Member Avatar for daviddoria
0
84
Member Avatar for pandey
Member Avatar for opposition

I think what you want is a friend class. I've never used it, but I bet google knows about it :)

Member Avatar for daviddoria
0
172
Member Avatar for lauren316

Please ask a specific question. Where is the code broken? Does it compile? If no, where/what are the errors?

Member Avatar for daviddoria
0
183
Member Avatar for daviddoria

I am trying to write a pretty straight forward algorithm (agglomerative clustering), but the details are getting pretty hairy. (A cluster is simply a group of points. The idea is to take a list of points and decide which are "grouped" or "clustered" close together.) Here is the outline: Input: …

Member Avatar for daviddoria
0
118
Member Avatar for daviddoria

On the line [code] set<T>::iterator iter; [/code] I am getting "expected ';' before 'iter'" [code] #include <vector> #include <set> using namespace std; template <typename T> vector<T> UniqueElements(const vector<T> &V) { set<T> s; s.insert(V.begin(), V.end()); vector<T> Elements; set<T>::iterator iter; return Elements; } [/code] Can anyone see why? It compiles fine if …

Member Avatar for daviddoria
0
102
Member Avatar for lehe

if you have a very simple program that just has to run a zillion times, you can use OpenMP parallel for loops. You just put a #pragma right before the loop and it magically splits it across all available cores. You can do more complicated things with openmp, but this …

Member Avatar for tux4life
0
88
Member Avatar for daviddoria

This simple example fills a vector with numbers 0-9. Then I use find() to find where the 7 is. Then I saw online you can get the index by simply subtracting V.begin() from the iterator that find() returns. Has - been overloaded for iterators to do some magic and return …

Member Avatar for StuXYZ
0
95
Member Avatar for daviddoria

I was using a library recently and I was getting a "undefined reference" linker error when I tried to call a template function with a type that they did not plan on me using. I asked on the mailing list and they said to call [code] VSL_VECTOR_IO_INSTANTIATE(vnl_matrix_fixed<double,3,3>); [/code] I guess …

0
50
Member Avatar for daviddoria

Currently, my index.html is like this [code] <html> <head> <title>EngineeringNotes.net</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div class="header"> <div id="logo"> <h1>EngineeringNotes.net</h1> </div> <div class="menu"> <ul> <li><a href="mailto:daviddoria@gmail.com">Contact Me</a></li> <li><a href="phpBB3">Forums</a></li> <li><a href="Ideology.html">Ideology</a></li> </ul> </div><!-- end menu --> </div><!-- end header --> <div class="page"><!-- start page --> <div class="sidebar"><!-- …

Member Avatar for daviddoria
0
181
Member Avatar for daviddoria

According to this: [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.13[/url] One way to keep only the function declaration in the .h file is to do this [code] ////////// file: Tools.h #include <iostream> #include <vector> using namespace std; template <typename T> T Sum(vector<T> &V); [/code] [code] ///////// file: Tools.cpp #include "Tools.h" #include <iostream> #include <vector> using namespace …

Member Avatar for tux4life
0
294
Member Avatar for daviddoria

To remove duplicates from a vector, my first thought was to insert them all into a set, it would take care of the uniqueness of the elements, and then read them back out into my vector. However, I have a vector<Point>, where Point is a point in 3d space (ie. …

Member Avatar for daviddoria
0
213
Member Avatar for ahvicm

There is no reason to post all of that code to ask that question. I suppose you need to handle/trap a keypress event and manually output a *, but I'm not sure how to do that.

Member Avatar for tux4life
0
88
Member Avatar for orwell84

cout<<input * (input-1)<<"\n"; //multiplies it all together that line is not dependent on the function call before it. also, you should call your function "factorial" instead of "recurse". The recursiveness should be implied by the behavior, it shouldn't need to be stated explicitly. Dave

Member Avatar for orwell84
0
161
Member Avatar for Dragonsfire

You say [code] if (Puzzle[ptx]... [/code] but you haven't defined Puzzle anywhere!

Member Avatar for Dragonsfire
0
96
Member Avatar for daviddoria

I was reading about the new "tuple" type coming in c++0x, and I decided to try it. I saw that if you give a compiler flag -std=c++0x it will work. So I did it, and then #include <tuple> works and everything was good. Then I decided to try the default …

Member Avatar for daviddoria
0
85
Member Avatar for daviddoria

Is there a built in type to store UNordered pairs? ie. I want these [code] pair<double, double> a(4.0, 5.0); pair<double, double> a(5.0, 4.0); [/code] to be equal. Do I have to make a wrapper and override == ? Thanks, Dave

Member Avatar for DemonGal711
0
144
Member Avatar for daviddoria

I often have this situation [code] class OrientedPoint { private: Point P; Vector N; Color C; bool valid; public: //////////// Constructors ////////// OrientedPoint() {} OrientedPoint(const Point &Coord); OrientedPoint(const Point &Coord, const Vector &Normal); OrientedPoint(const Point &Coord, const Color &C); OrientedPoint(const Point &Coord, const Vector &Normal, const Color &C); [/code] where …

Member Avatar for daviddoria
0
122
Member Avatar for daviddoria

Is pthreads still the way to go to detach a process from the main thread in linux? It seems seems kind of convoluted/old/c-style from looking at some examples - is there a more "c++" way? Thanks, Dave

0
48
Member Avatar for evbaseball6

That seems like a good outline, but you have to attempt to write the key functions and then we can help you debug it.

Member Avatar for tux4life
0
73
Member Avatar for Moe
Member Avatar for emiller7

Which lines is it complaining about? Also, in general, you cannot/should not do this: [code] char stuNames[stu][21]; double stuGrades[stu][num]; [/code] The numbers in [ ] need be determined at compile time, or you need to dynamically allocate the array using "new".

Member Avatar for VernonDozier
0
6K
Member Avatar for daviddoria

I'm just trying to figure out how this stuff works. I wrote this function: [code] #include <algorithm> #include <vector> double VectorMax(const vector<double> &a) { vector<double>::iterator pos; pos = max_element (a.begin(), a.end()); return *pos; } [/code] and call it with: [code] vector<double> Numbers; Numbers.push_back(3.4); Numbers.push_back(4.5); Numbers.push_back(1.2); cout << VectorMax(Numbers) << endl; …

Member Avatar for nucleon
0
193
Member Avatar for daviddoria

I am trying to use the for_each from stl algorithm. [url]http://www.cplusplus.com/reference/algorithm/for_each.html[/url] [code] #include <algorithm> #include <vector> #include <iostream> template <typename T> void OutputObject(const T &obj) { cout << obj << endl; } template <typename T> void OutputVector(const vector<T> &V) { for_each (V.begin(), V.end(), OutputObject); cout << endl; } [/code] I …

Member Avatar for daviddoria
0
576
Member Avatar for daviddoria

I found this while googling for something [url]http://msdn.microsoft.com/en-us/library/ms177203(VS.80).aspx[/url] I tried it (with g++) and it seems to be a syntax error - is this like something specific to Visual Studio or something? Dave

Member Avatar for Narue
0
92
Member Avatar for cruisx

With text files I don't think there is much option but to read in the whole file, and write out the whole file again, but this time with the new value in the place of the old value. I think you'd have to use an actual database to be able …

Member Avatar for computercobra
0
832
Member Avatar for daviddoria

Is there a reason to use [code] cout << static_cast<int>(thing); [/code] instead of [code] cout << (int)thing; [/code] ? Thanks, Dave

Member Avatar for Narue
0
102
Member Avatar for daviddoria

If I make an array like this [code] GLubyte bufImage[100][100][3]; [/code] I can pass bufImage to a function and then get the values using: [code] r = bufImage[im_x][im_y][0]; g = bufImage[im_x][im_y][1]; b = bufImage[im_x][im_y][2]; [/code] However, if I don't know Width and Height at runtime, this does not work. I …

Member Avatar for Narue
0
311
Member Avatar for erialclaire_238

You seem to have not tried at all. Give it a shot and then if it doesn't work we'll help you.

Member Avatar for erialclaire_238
0
319
Member Avatar for daviddoria

I've seen a few questions about this floating around here (mostly from me :) ) but I finally got this is into a nice working form - maybe it will be useful for someone. It is called like this: [code] void TestParallelSort() { vector<double> Numbers; Numbers.push_back(3.4); Numbers.push_back(4.5); Numbers.push_back(1.2); vector<string> Names; …

0
230
Member Avatar for cwarn23

I don't know how it works with windows, but in linux you have to use some kind of "UI Framework" like QT or GTK.

Member Avatar for mitrmkar
0
143
Member Avatar for newcpp

Even though you are using c++, this is not a c++ question. Ask here: [url]http://www.opengl.org/discussion_boards/[/url] And I bet you'll get your answer.

Member Avatar for daviddoria
0
133
Member Avatar for venkitce

They are like arrays, but you can dynamically add items to them using push_back. They also have a function size() to get the length of the vector. I find them amazingly useful!

Member Avatar for NavidV
0
116
Member Avatar for mohsin334

Throw some code tags around there so it's a bit more readable, but thanks for the tutorial. Is this the right place to post these? I have a handful of things like this that may be useful to others - where should we put them?

Member Avatar for daviddoria
0
97
Member Avatar for daviddoria

It seems like SO often I need to attach a "valid" flag to a standard type. For example - I have a function called "CalculateLunchTime" that I pass a vector of times. If the vector has 0 elements, they did not take a lunch, so the duration is 0 minutes. …

Member Avatar for Rashakil Fol
0
598
Member Avatar for dirbax

Any time there is an "if" I'd say it would either turn into a piecewise function or you'd need some wacky step functions. Also, please use code tags.

Member Avatar for Rashakil Fol
0
122
Member Avatar for Icebone1000

This should do what you're looking to do. For some reason there is a small issue with re-using the string stream for the 4th line (so I made a new one, I left the code that doesn't work commented), but I've started a thread about why that is. [code] void …

Member Avatar for Icebone1000
0
99
Member Avatar for CPPRULZ

You cannot do this, it's simply incorrect syntax: [code] Furlong(class Kilometer& kilo) [/code] You just need to do [code] Furlong(Kilometer& kilo) [/code] And also, you really shouldn't/can't have both classes contain the other class. In this case I would make two non-member functions [code] Furlong KilometerToFurlong(Kilometer &kilo); Kilometer FurlongToKilometer(Furlong &furl); …

Member Avatar for CPPRULZ
0
155
Member Avatar for daviddoria

If I use the uncommented 3 lines for getting an int out of a stringstream, the value in MPV is wrong. However, if I make a new stringstream, then it works fine. I thought setting .str("") was essentially resetting the stringstream? [code] line = ""; getline(fin, line); //get fourth line …

Member Avatar for daviddoria
0
469
Member Avatar for daviddoria

I have two functions: GetDayTime and GetLunchTime. From some places in the program, all I have is the associate name and a date and I want to determine these quantities. So I just query the database inside the function: [code] Public Function CalculateLunchTime(ByVal DateToCalculate As DateTime) As Double Dim daEvent …

0
79
Member Avatar for disc

I do it just to remind myself (and the compiler) that no class variables can be changed in this function. Basically just to keep me from accidentally doing something stupid! ie. [code] double YourClass::GetX() { x_ = 2.0; } [/code] You should not be modifying any of the member variables …

Member Avatar for disc
0
183
Member Avatar for Samran

I really never use arrays, I go for the vector of vectors [code] vector<vector<char> > array(columns); for(unsigned int i = 0; i < columns; i++) { vector<char> RowVector(rows); // ... fill the row vector ... array.push_back(RowVector); } [/code] If you want to use an actually array you have to use …

Member Avatar for Samran
0
3K
Member Avatar for thingstealer

I had this same question: [url]http://www.daniweb.com/forums/thread114375.html[/url] The answer was basically "you've designed it wrong"!

Member Avatar for thingstealer
0
131
Member Avatar for daviddoria

I have a delete button which does this: [code] TTDataSet.PunchEventTable.Rows(dgvData.SelectedRows(0).Index).Delete() [/code] The problem is that if I delete row 0 (the 0th index in the DataGridView and in the underlying table, all is well. But now row 1 in the table corresponds to row 0 in the DataGridView, so if …

Member Avatar for rapture
0
895
Member Avatar for daviddoria

I have tried to make a SumVector function for all types, but if it is called with a vector of unsigned char's, it will do something special. Here is what I tried, but I get a multiple definitions of the function compiler error. [code] template <typename T> void SumVector(vector<T> &V) …

Member Avatar for nucleon
0
3K
Member Avatar for sam_sumit184
Member Avatar for h3llpunk

Which line do you get the pointer comparison error? In this code: [code] int random_integer = (rand()%6)+1; random_integer = pcdice1; [/code] You are storing the random number in random_integer, and then immediately replacing it with pcdice1. That is why you aren't seeing a different number each time. Dave

Member Avatar for vmanes
0
88
Member Avatar for deerowbear

Yea, but it looks like you're using it on line 77 and defining it on line 241 - you need to define it before you use it!

Member Avatar for Ancient Dragon
0
103
Member Avatar for raineloire11

I've found boost particularly hard to work with, especially if you don't know what you're doing! It sounds like you just want a switch statement? [url]http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Companion/cxx_crib/switch.html[/url] If you have a more exact goal then let us know.

Member Avatar for siddhant3s
-1
95

The End.