2,712 Posted Topics

Member Avatar for gazzatav
Member Avatar for svatstika

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; …

Member Avatar for svatstika
0
187
Member Avatar for seanbp

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

Member Avatar for vijayan121
0
107
Member Avatar for seanbp

>> 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 …

Member Avatar for seanbp
0
377
Member Avatar for VernonDozier

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.

Member Avatar for VernonDozier
0
174
Member Avatar for mattloto

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.

Member Avatar for mrnutty
0
126
Member Avatar for svatstika
Member Avatar for Kuroshi

@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 …

Member Avatar for mrnutty
0
94
Member Avatar for ziggazam

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]

Member Avatar for ziggazam
0
108
Member Avatar for dynamyt3

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]

Member Avatar for dynamyt3
0
1K
Member Avatar for GrimJack

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...

Member Avatar for GrimJack
1
158
Member Avatar for needhelpe

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]

Member Avatar for Nick Evan
0
4K
Member Avatar for chamika.deshan

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]

Member Avatar for chamika.deshan
0
108
Member Avatar for rj2910

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]

Member Avatar for mrnutty
0
102
Member Avatar for LianaN

Create another JPanel, and add the toolbar to that JPanel. And think of that new panel as a toolbar.

Member Avatar for LianaN
0
137
Member Avatar for MarounMaroun

>>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

Member Avatar for frogboy77
0
96
Member Avatar for jcax

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 …

Member Avatar for jcax
0
132
Member Avatar for blah32

Remember a set can only have distinct elements, that might be the reason why it fails sometimes.

Member Avatar for arkoenig
0
113
Member Avatar for hworkr
Member Avatar for Transcendent
Member Avatar for Transcendent
0
105
Member Avatar for qvyhnl

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]

Member Avatar for Clinton Portis
0
186
Member Avatar for eskimo456

Ok show us how/where you call the allocation for texture. Presumably, you only need to allocate once for the texture.

Member Avatar for eskimo456
0
168
Member Avatar for cclausen7

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]?

Member Avatar for Fbody
0
136
Member Avatar for Transcendent

Correction: [code] while(iter !=aList.end()) [COLOR="red"]{[/COLOR] if( *max<*iter) max=iter; iter++; //return max; [COLOR="Red"]}[/COLOR] return max; [/code]

Member Avatar for abdelhakeem
0
226
Member Avatar for ProgrammerAl

I did this for my university like 3 years ago. The exact same problem. I still have it, for a price.

Member Avatar for ProgrammerAl
0
1K
Member Avatar for tomtetlaw
Member Avatar for kuchick32

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 …

Member Avatar for frogboy77
0
132
Member Avatar for aaronmk2

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]

Member Avatar for iopp
0
1K
Member Avatar for tylerjgarland

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 …

Member Avatar for mrnutty
-1
274
Member Avatar for kevintse

[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".

Member Avatar for kevintse
0
129
Member Avatar for salty11
Member Avatar for Spiffy P Mcgee

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]

Member Avatar for mike_2000_17
0
115
Member Avatar for chamika.deshan

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 …

Member Avatar for mrnutty
0
147
Member Avatar for i_luv_c++

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 - …

Member Avatar for mrnutty
0
130
Member Avatar for qvyhnl

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, …

Member Avatar for mrnutty
0
103
Member Avatar for muffle

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]

Member Avatar for muffle
0
184
Member Avatar for Toxic_Rice

You cannot as of right now, seperate the template definition from its implementation. They both need to go in the same file.

Member Avatar for Toxic_Rice
0
237
Member Avatar for PieterA

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.

Member Avatar for PieterA
0
197
Member Avatar for thunderwolf07

I will delegate the explanation to [URL="http://www.cplusplus.com/reference/clibrary/cstdio/printf/"]this[/URL] site,

Member Avatar for thunderwolf07
0
79
Member Avatar for Syrne

[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]

Member Avatar for Syrne
0
185
Member Avatar for hystaspes
Member Avatar for Tankadin

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, …

Member Avatar for quuba
0
430
Member Avatar for tKc

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 …

Member Avatar for mrnutty
0
481
Member Avatar for bejums
Member Avatar for Rickay
Member Avatar for dlube

[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, …

Member Avatar for smrati.katiyar
0
102
Member Avatar for mbouster

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? …

Member Avatar for mbouster
0
2K
Member Avatar for nickx522

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 …

Member Avatar for Akill10
0
96
Member Avatar for jmcorpse

Also consider using string/list<int> instead of ints[]. That way its easier to change the whole array if you need to.

Member Avatar for Clinton Portis
0
2K
Member Avatar for djhog

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]

Member Avatar for djhog
0
181

The End.