2,712 Posted Topics

Member Avatar for Zvjezdan23

Some terms to google, function pointers and arrays. Basically, create a typedef of a function pointer, and create an array of that alias.

Member Avatar for WaltP
0
184
Member Avatar for mluu510
Member Avatar for mrnutty
0
143
Member Avatar for imhiya

Since nodes is of type list of Node you can only add Node into it. For example : [code] list<Node> nodes; Node n; n.name = "test"; nodes.push_back( n ); [/code]

Member Avatar for mrnutty
0
149
Member Avatar for ntrncx

[B]since i study alone and my code starts to be more big and more chaotic i have some questions that maybe will sound silly to more but i have to ask someone. [/B] As with most things, you need to study and work hard yourself. There isn't going to be …

Member Avatar for ntrncx
0
130
Member Avatar for agarg12

Another approach is to create your own namespace : [code] #include <iostream> using namespace std; namespace Util{ template<typename T> T& max(const T& lhs, const T& rhs){ return lhs < rhs ? rhs : lhs ; } }; int main(){ cout << Util::max(1,2) << endl; } [/code]

Member Avatar for agarg12
0
134
Member Avatar for blee93

This problem comes up so often, maybe we should make some sort of section for problem like these

Member Avatar for frogboy77
0
209
Member Avatar for margeaux54

There are couple of option you can choose from : [B]OPTION #1: Use buffer[/B] [code] const int MAX_SIZE = 1000; int bufferLength = 0; int buffer[MAX_SIZE] = {0}; cin >> bufferLength ; if(bufferLength > MAX_SIZE){ cout << "Error: size to large\n"; return 1; } for(int i = 0; i < …

Member Avatar for margeaux54
0
102
Member Avatar for mitrious

The second one doesn't complain because it hasn't been instantiated yet. If you call Str like so [icode] Str(cp, cp + strlen(cp)) [/icode]then you would get that same error.

Member Avatar for mitrious
0
168
Member Avatar for Labdabeta

Actually there is little to no reason to make operators virtual, with mild exception to operator=; As for the syntax you can do this : [code] struct F{ virtual F& operator+(const F& f)const = 0; //.. and so on }; [/code]

Member Avatar for Labdabeta
0
262
Member Avatar for WildBamaBoy

You avoid using it much as possible, instead substitute reference for it. But you might eventually need to use it when you need polymorphism, although you can still use reference, in most cases, pointers might be more practical.

Member Avatar for WildBamaBoy
0
172
Member Avatar for daniel1977
Member Avatar for JamieLynnSEO
0
77
Member Avatar for fka
Member Avatar for mrnutty
0
205
Member Avatar for efficacious

Use std::string [code] std::string binaryNumber; cin >> binaryNumber; for(int i = 0; i < binaryNumber.size(); ++i) cout << binaryNumber[i] << endl; [/code]

Member Avatar for pseudorandom21
0
168
Member Avatar for lochnessmonster
Member Avatar for cwarn23

[QUOTE=Rashakil Fol;1486859]Basically anything would be faster.[/QUOTE] Well.... [code] float squareRoot(float num){ const float epsilon = 10e-6; float start = epsilon; while( start * start < num) start += epsilon; return start; } [/code]

Member Avatar for mrnutty
0
843
Member Avatar for maikens

You should be just setting the root height to 0 then set its left and right height to n+1. No need for get height function.

Member Avatar for mrnutty
0
143
Member Avatar for daviddoria

It doesn't work because for an element n to be less than m, both x and y fields of n has to be lower than of m's( by your construct). You should test x first then y. Like so : [code] if(p1.x < p2.x) return true; else return p1.y < …

Member Avatar for daviddoria
0
229
Member Avatar for kutuup
Member Avatar for sambho
Member Avatar for Transcendent

I don't know if there is a solution manual for it( google it), but you can post the problem and we'll be happy to solve it for you, provided that you attempted and solved the problem already, if not then we can guide you to the solutions.

Member Avatar for arkoenig
0
1K
Member Avatar for SourabhT
Member Avatar for spoonlicker

What part of it confuses you? Instead of trying to avoid it, why not try to understand it, even if its just a little more. And remember we're here to help.

Member Avatar for katokato
-1
695
Member Avatar for Lelly

>>[B]Implement the Random partitioning version of Quicksort[/B] Means simply choose a random partition index from the array. >>[B]Take care that your data array is not copied (by value) into your subroutines[/B] Means use reference, for example : [code] void quickSort(float array[] , const int size){ //pick random pivot partition(array, pivot); …

Member Avatar for mrnutty
0
532
Member Avatar for ROTC89
Member Avatar for lochnessmonster

[QUOTE=Narue;1466559]No, it's not bad. Only C++ purists will rag on you about it, but they're in a world of their own anyway.[/QUOTE] Its not bad but its harmful isn't it? If one had an option, why would he think about mixing C style with C++? Usually, its more safe to …

Member Avatar for pritpal.singh88
0
233
Member Avatar for dennis.d.elston

Surprised none mentioned the use of const. [code] float computeAverage(const float data[], const int DATA_SIZE){ return std::accumulate(data, data + DATA_SIZE, 0)/ float(DATA_SIZE); } [/code]

Member Avatar for dennis.d.elston
0
190
Member Avatar for ana_1234

To test if it contains a loop, i.e is a circular linked list, what you need to do is transverse through the list, and see if head comes up twice. Here is some psuedo-code. [code] bool isLoopedLinkedList(const listnode* head){ - bool result = false - create a listnode headCopy - …

Member Avatar for mrnutty
0
148
Member Avatar for dolly_olaide

[QUOTE=mike_2000_17;1477672]Line 49 is wrong for sure, it probably should be: [CODE] total += data[i*width + j]; //or maybe "data[j*height + i]" [/CODE] At line 62, the ImageData array was never initialized, so it won't contain the actual pixel values, you should probably use data as above. For the rest, I …

Member Avatar for dolly_olaide
0
5K
Member Avatar for Saiiiira

>>[B] I want to know more about these PDAs and the class of functions they compute.[/B] The compute the same languages as Context Free Grammers.

Member Avatar for Saiiiira
0
284
Member Avatar for shakssage

Do you think a Finite Automaton can represent a PDA? If it can the you would have proved that PDA = FA

Member Avatar for Saiiiira
0
238
Member Avatar for chamnab

Sure : [code] std::string greeting = "hello"; string::size_type pos = greeting.find('e'); std::string fuzz = greeting.erase( pos , 1) [/code]

Member Avatar for mrnutty
0
47
Member Avatar for caut_baia

[CODE] if(y) //verify that y is not NULL before deleting it. delete y; //this should be safe. [/CODE] just note, deleting NULL is defined and does nothing.

Member Avatar for caut_baia
0
561
Member Avatar for fsefsef23

- First you should be using std::vectors if possible. - Second returning the array is kind of bad OOP, since your encapsulation decreases. Instead consider providing mechanism to accesses the coefficients. For example. [code] class Polynomial{ private: float coefficients[10]; float exponents[10]; public: //... const float coefficientAt(int i )const; const float …

Member Avatar for mrnutty
0
182
Member Avatar for fsefsef23

This is just a logic problem. What part of this is troubling you? A simple way to do this could be something like so : [code] for i = 0 to coefficients.size print coefficients[i] + "x" + "^" + i + " " [/code] So in the simple example, say …

Member Avatar for jonsca
0
163
Member Avatar for jake1496
Member Avatar for frank731tr

Quick way as suggested: [code] string userInput; getline(cin, userInput); validate(userInput); double d = atof(userInput.c_str()); doStuffWith(d); [/code]

Member Avatar for mrnutty
0
2K
Member Avatar for Gh0st93

Are you interested in the physics or its visual appreance? For the physics part, you can simply model the bulets by a vector that travels straight in its direction. But i'm not completely sure what exactly you need.

Member Avatar for eskimo456
0
178
Member Avatar for lochnessmonster

If you are fine with prepending it with a dash then you can for example : [code] int _1 = 0; int var = _1 + 3; [/code]

Member Avatar for Red Goose
0
110
Member Avatar for Mr.UNOwen
Member Avatar for mrnutty

The simplest sort, although inefficient. Below is a demonstration of bubble sort and insertion sort. The bubble sort just consists of 2 for loops and std::swap. The insertion sort uses 2 loops as well but not as much swap as bubble sort. Any questions ?

Member Avatar for 88omar
1
434
Member Avatar for lochnessmonster
Member Avatar for lovely girl

Take your pick : Complexity is : - The quality of being intricate and compounded - Characterization of something with many parts in intricate arrangement - The state of being complex - The degree to which a program is difficult to understand by human developers in order to, for example, …

Member Avatar for mrnutty
-3
105
Member Avatar for medopunsher
Member Avatar for andimiami

It shouldn't be hard. Read the input as a string. And move everything thats not a number to the right, and everything that is a number to the left. and output.

Member Avatar for mrnutty
0
209
Member Avatar for mrnutty
Member Avatar for strungoutfan78

[QUOTE=caut_baia;1470666]You have to assign a static const variable in order to be accepted as an array size.Try using a template function and pass it a constant integral when calling it. [code] template <int size> int* func () { //example int array[size]; return array; } [/code][/QUOTE] Don't do that. That code …

Member Avatar for strungoutfan78
0
399
Member Avatar for Lord_Migit

Since they are raw pointers you would have to deallocate each pointer manually. If you want to use something like [i]m_vPopulation2 = m_vParentPop2[/i] then you should instead use smart pointers instead of raw pointers. If both of the vectors are the same size then you can do this : [code] …

Member Avatar for Lord_Migit
0
145
Member Avatar for jkoske

from what I can see your code is prefect. Bugs free, fast, and takes no memory space.and its portable. Congrats.

Member Avatar for Red Goose
0
85
Member Avatar for ChaseRLewis

Its probably because of the casting and such. Unless your working in a 'tight' environment, generally, forget about lookup tables.

Member Avatar for mike_2000_17
0
2K
Member Avatar for alex55

[CODE] averaged[i]; if(i>highest)[/CODE] You probably want [CODE] if( averaged[i] > averaged[highest] ){ highest = i; } [/CODE]

Member Avatar for alex55
0
131

The End.