2,712 Posted Topics
Re: Some terms to google, function pointers and arrays. Basically, create a typedef of a function pointer, and create an array of that alias. | |
Re: You can click on the error and it will take you to that line | |
Re: 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] | |
Re: [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 … | |
Re: 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] | |
Re: This problem comes up so often, maybe we should make some sort of section for problem like these | |
Re: 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 < … | |
Re: 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. | |
Re: 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] | |
Re: 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. | |
Re: There is no such things as [B]stackType[/B] use std::stack | |
Re: [I]srand [/I]is in [I]cstdlib[/I]. So try to include cstdlib. | |
Re: Use std::string [code] std::string binaryNumber; cin >> binaryNumber; for(int i = 0; i < binaryNumber.size(); ++i) cout << binaryNumber[i] << endl; [/code] | |
Re: [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] | |
Re: 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. | |
Re: 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 < … | |
Re: You need to deference you pointers | |
Re: what exactly do you mean by distinct prime factor? | |
Re: 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. | |
Re: [code] class Temp{ virtual void dr() = 0; }; [/code] | |
Re: 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. | |
Re: >>[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); … | |
| |
Re: [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 … | |
Re: 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] | |
Re: 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 - … | |
Re: [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 … | |
Re: >>[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. | |
Re: Do you think a Finite Automaton can represent a PDA? If it can the you would have proved that PDA = FA | |
Re: Sure : [code] std::string greeting = "hello"; string::size_type pos = greeting.find('e'); std::string fuzz = greeting.erase( pos , 1) [/code] | |
Re: [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. | |
Re: - 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 … | |
Re: 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 … | |
Re: Quick way as suggested: [code] string userInput; getline(cin, userInput); validate(userInput); double d = atof(userInput.c_str()); doStuffWith(d); [/code] | |
Re: 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. | |
Re: If you are fine with prepending it with a dash then you can for example : [code] int _1 = 0; int var = _1 + 3; [/code] | |
Re: Never used it, but possibly [URL="http://www.wxwidgets.org/"]wxwidgits[/URL] | |
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 ? | |
Re: 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, … | |
Re: 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. | |
Re: [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 … | |
Re: 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] … | |
Re: from what I can see your code is prefect. Bugs free, fast, and takes no memory space.and its portable. Congrats. | |
Re: Its probably because of the casting and such. Unless your working in a 'tight' environment, generally, forget about lookup tables. | |
Re: [CODE] averaged[i]; if(i>highest)[/CODE] You probably want [CODE] if( averaged[i] > averaged[highest] ){ highest = i; } [/CODE] |
The End.