2,712 Posted Topics
Re: You should make the whole iterator class templatized. | |
Re: First you need to be able to represent data in arbitrary length. One way to do that is use a [I]std::vector<int> numbers[/I] or even [I]std::string[/I]. Personally, I would choose the std::strings, because its easier to work with. So lets define such a type : [code] class Number{ private: std::string _numbers; … | |
Re: Just some tips: 1) Make your program first, make it reasonable and clear and readable 2) Then run it and see if it meets your program requirements 3) If not then profile it with a profiler and fix the hotspots | |
Re: >> I want to get some feedback on my code to facilitate improvement. Drop the array_begin and array_end pointer stuff. Use the [] operator instead on the passed in array. As pointed out, forget about register keyword. BubbleSort is slow already so drop the early exit boolean stuff and just … | |
Re: Is there anyway you can change the design of the program so it doesn't rely on compile time ifs? Seems like you want to implement state machine. | |
Re: In C++ you should avoid pointers. In this example, you can just use a static object like so : [code] Shape s = Shape(10,10); [/code] no need for the [i]new[/i] operator or pointers. | |
Re: another thing, is that you might want to create a conversion operator. | |
Re: @OP: Your looking at it the wrong way, instead of letting the client check if a circle is intersects a rectangle, have the rectangle have a function called [i]contains(Circle c)[/i] and call it like so, rectangleObject.contains(circleObject); So that way there is more encapsulation, and a better design. Of course you … | |
Re: This is what you want : [code] string myName = "josh"; string myBrotherName = "tommy"; string input; cout << "Enter a name : "; cin >> input; if(input == myName){ cout << "Welcome admin\n"; } else if(input == myBrotherName){ cout << "Welcome guest\n"; } else cout << "Invalid user\n"; [/code] | |
Re: Just some skeleton to help you visualize whats been said above : [code] for row = 0 to ROW_SIZE for col = 0 to COL_SIZE int rowToSwap = a random valid row int colToSwap = a random valid col swap array[row][col] with array[rowToSwap][colToSwap] [/code] | |
Re: This is interesting. But the correlation isn't that surprising since it test the ability to resist. And the ability to resist if a form of self control. And self control helps people make better decision and so on... | |
Re: Haven't tested it yet, but it could be similar to this : [code] int M = 5; int i = 1; while(i <= M) cout << i++ <<" "; //print from 1 to 5 while(--i > 0) cout << i << " "; //print from 4 to 1 [/code] | |
Re: Try not to use the raw arrays if you can. But what you want it template deduction. [code] #include <iostream> using namespace std; template<typename T, size_t SIZE> int arraySize(const T (&array)[SIZE] ){ return sizeof(array)/sizeof(array[0]); } int main(){ int a[10] = {0}; cout << arraySize(a) << endl; } [/code] | |
Re: This code [icode]test t2 = 50; [/icode] is the same as [icode]test t2 = test(50);[/icode] and this code [icode]test t3;[/icode] is the same as [icode]test t3 = test();[/icode] | |
Re: Create another JPanel, and add the toolbar to that JPanel. And think of that new panel as a toolbar. | |
Re: >>all variations of 1-10 There are 10! different variations go through them like so : 1 1 1 1 1 1 1 2 1 1 1 3 1 1 1 4 1 1 1 5 and so on | |
Re: Yes as you figured out you need a forward deceleration : [code] class Student; //tell compiler that you are going to create a Student class later class Subject{ vector<Student> list_of_student; }; class Student{ vector<Subject> list_of_subject; }; [/code] Your first attempt doesn't work because the Student class doesn't exist when you … | |
Re: Remember a set can only have distinct elements, that might be the reason why it fails sometimes. | |
Re: Change to this [icode]input(carSpeed);[/icode] Also use code tags. | |
Re: sort the vector inside the sortPrint function and then print it? | |
Re: How about a skeleton : [code] string uniqify(const std::string& source,int currentLocation){ if(source.length() <= 1) return source; else{/*code here */} } string string_clean(const std::string& str){ return uniqify(source,0); } [/code] | |
Re: Ok show us how/where you call the allocation for texture. Presumably, you only need to allocate once for the texture. | |
Re: Wait let me get this straight, you have a command, something like this :[icode]"assign 8 strength[/icode]. And this should assign strength to 8. So in general is the format going to be like so :[icode]command number attribute[/icode]? | |
Re: Correction: [code] while(iter !=aList.end()) [COLOR="red"]{[/COLOR] if( *max<*iter) max=iter; iter++; //return max; [COLOR="Red"]}[/COLOR] return max; [/code] | |
Re: I did this for my university like 3 years ago. The exact same problem. I still have it, for a price. | |
Re: I think he means for example : 5 = 1 + 1 + 1 + 1 + 1 5 = 1 + 1 + 1 + 2 5 = 1 + 1 + 3 5 = 1 + 4 5 = 5 5 = 4 + 1 5 = 3 … | |
Re: Yea doesn't look like your destructing it properly. Try something like this : [code] BinarySearchTree::~BinarySearchTree(){ _destroy(this._root); } void BinarySearchTree::_destroy(Node* root){ if( isNull(root) ) return; else{ _destroy(root.getLeft()); _destroy(root.getRight()); delete root; } } [/code] | |
Re: Try using this to hash strings: [code] unsigned long hash(unsigned char *str){ unsigned long hash = 5381; int c; while (c = *str++) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ return hash; } [/code] Then you can incorporate this for the … | |
Re: [QUOTE][B]Your definition of bar() is technically correct syntax, but your usage is illegal because you are returning a reference to a local variable[/B][/QUOTE] Correction. bar() returns a copy of the text "world". | |
Re: Umm not sure what your saying, some guesses : [code] const int N = 100; const float pi = 3.14f; const string = "what?" enum{ CONSTANT_1, CONSTANT_2} struct Foo{ mutable semiConstant; } namespace Math{ const float DEGTORAD = 0.0174532925f; } [/code] | |
Re: Just to explain more : @Op : you first question about the Policy::create(...) The reason why thats there instead of simply just new classT is because of its flexibility. When the user creates a MakeT class it could now specify how the class is created. If it simply uses the … | |
Re: Just for giggle, here is my solution : [code]bool hasWinningMove(const int stonesLeft,int& nextMove){ const float tolerance = 0.00001f; //magic formula muhahahhaaa float intPart = 0; float frac = modf( (stonesLeft+3.0f)/4.0f , &intPart); if(frac <= tolerance|| intPart == 0){ nextMove = 1; return false; } else{ int magicHole = int(ceil(4*intPart - … | |
Re: Yes I can. But instead of giving you the answer. I am going to help and guide you through this long and tough journey to find the number of magical sevens in a given integer. So to start, do you have any ideas? Does not have to be in code, … | |
Re: Yes, first you need to use C++ fstream, instead of C functions, and incorporate getline() command like so : [code] ifstream fileInput("input.txt"); if(!fileInput){ cerr << "File not found\n"; } string line; while(getline(fileInput,line)){ cout << line << endl; //prints line by line } [/code] | |
Re: You cannot as of right now, seperate the template definition from its implementation. They both need to go in the same file. | |
Re: Easy fix, is the have a default do-nothing displayEntity for ark::Entity. Alternative is to rethink your design. It looks like your design went bad somewhere, if your left to do the above hack. | |
Re: I will delegate the explanation to [URL="http://www.cplusplus.com/reference/clibrary/cstdio/printf/"]this[/URL] site, | |
Re: [CODE] Fraction Fraction :: operator* (const Fraction& fr2) { int numen = (numerator * fr2.[COLOR="Red"]numerator[/COLOR]); int denom = (denominator * fr2.denominator); return Fraction (numen, denom); // Trouble here } [/CODE] | |
Re: There is no need to redefine true/false. | |
Re: For you exception handling, it would make sense if you propagate the exception to the client instead of throwing it yourself and catching it. If thats the case then you need not to throw any exception, you can simply use a boolean statement. And to further extend your exception handling, … | |
Re: Do you know what this data means ? [code] 0 1 1 0 1 1 0 1 1 1 1 1 0 0 0 0 1 0 0 1 1 1 0 1 0 [/code] Read it like this way : [code] 1 2 3 4 5 ---------- 1 |0 … | |
Re: [QUOTE=dlube;1403301]how would you write a for loop that calculates the total investment over 40 years if a one pays $500 each month but every 2 years the payment increases 10%?[/QUOTE] I wouldn't. Instead, I would post in a forum by disguising the question by asking the members in the forum, … | |
Re: What information you got : a) 3 husband and 3 wives. b) A Boat to transport a couple/wife/2 wives Objective: Transport 3 husband and the wives by the rules governed by (b). So With that think and list all possible class names you need? Do you really a Person class? … | |
Re: One way is to do the following: [code] void display(float average){ cout.precision(2); cout << average << endl; } [/code] Or you can truncate the number to 2 decimal place like so : [code] void display(float average){ cout << truncate(average,2) << endl; } //use integer division float truncate(float num,int decimalPlaces){ int … | |
Re: Also consider using string/list<int> instead of ints[]. That way its easier to change the whole array if you need to. | |
Re: the [i]search[/i] function takes in 4 arguments not five. What you want is something like this: [code] //returns true if source contains target with case ignored bool no_case_compare(const string& source, const string& target){ string srcCpy(source.size(),0); string targetCpy(target.size(),0); std::transform(source.begin(),source.end(),srcCpy.begin(),tolower); std::transform(target.begin(),target.end(),targetCpy.begin(),tolower); return srcCpy.find(targetCpy) != string::npos; } [/code] |
The End.