2,712 Posted Topics

Member Avatar for AshfaqueIW

If you have a uniform function or can make one, then you could map it. [code] std::map< int , void(*)()> myMap; const int ON_UPDATE = 0; const int ON_QUIT = -1; myMap[ON_UPDATE] = updateHandler; myMap[ON_QUIT] = quitHandler; while( ! someCondition ){ int state = getState(); myMap[ state ] (); //call …

Member Avatar for mrnutty
0
1K
Member Avatar for mridontknow

You want to use random_shuffle function, [code] #include <algorithm> #include <vector> #include <string> #include <iostream> int main(){ using namespace std; const int COLOR_SIZE = 4; string colors[COLOR_SIZE ] = { "yellow", "green", "blue" , "red" } std::vector<string> colorVec( colors, colors + COLOR_SIZE ); //shuffle colors std::random_shuffle( colorVec.begin(), colorVec.end() ); //do …

Member Avatar for mrnutty
0
2K
Member Avatar for bigdan182

>>[B]I have 8 teams and I need to find the top 4,[/B] You don't really need to sort because all you care for is the top 4 team. In fact if you were using the correct data structure, you wouldn't need to worry about picking the top 4 teams, for …

Member Avatar for rubberman
0
140
Member Avatar for floatingDivs
Member Avatar for mrnutty

Just for exercise, if people want to give it a go; see how creative one can be. [b]Problem Statement:[/b] Given a list of data from a file( or user input which ever) as such: [code] char 1 char 2 char 26 char 27 char 52 char 53 [/code] output the …

Member Avatar for iamthwee
1
151
Member Avatar for aomas98

[QUOTE=ztdep;1617159]The problem can be solved with many ways. I solved it in a more straight way. Every one should help other people more actively, I do not want a grad.[/QUOTE] HAHHAHAH [URL="http://static.tvtropes.org/pmwiki/pub/images/picard-facepalm.jpg"]FacePalm[/URL]. He totally didn't get it.

Member Avatar for Rashakil Fol
-2
177
Member Avatar for afi@alvi

Yes, but it will be a little work 1) Use Java's JNI to talk to C++ program/functions 2) Use phonegap, javascript to talk to JAVA program. 3) Now your application works with android/iphone and Blackberry 6 or higher

Member Avatar for mrnutty
0
194
Member Avatar for Peyton

[CODE] // overloads the equivalence operator which allows two Words to be compared using == bool Word::operator==(const Word& rhs) const { if (_word == rhs._word) return true; else return false; } [/CODE] That compares another Word with the current Word. The current Word has its own '_word' variables, so it …

Member Avatar for Peyton
0
149
Member Avatar for mrnutty

I'm presenting to day at my internship in front of the whole company and the president, wish me luck!!!! I'm so nervous.

Member Avatar for iAssistant
0
180
Member Avatar for fsefsef23

[QUOTE] I got it now! Thanks so much firstPerson, I don't know why I didn't think of how easier it would be in reverse order haha! We actually had a choice between queues and stacks, and I realize now how much more I'd probably prefer the FIFO structure of queues! …

Member Avatar for WaltP
0
424
Member Avatar for har58
Member Avatar for shokichi
0
2K
Member Avatar for fsefsef23

Okay let me help you with the algorithm, it will be a simple one. This is you stack content: [N,n,<,-,<,-,<,-,<,-,N,o, ,<,-,w, ,i,z,<,-,s,t,h,e,<,-,<,-,<,-, ,t,h,e, ,t,i,m,e,.] where as you said the top of the stack is '.' and bottom of the stack is 'N'; Now to make the algorithm easier first you …

Member Avatar for WaltP
0
690
Member Avatar for MareoRaft

>>[B] l<2^(K-1);[/B] thats not correct, if you are looking for the power function, then you need to include cmath: [code] #include <cmath> #include <iostream> int main(){ using namespace std; float res = std::pow(2.0f,4.0f); //2^4 = 16 cout << res << endl; } [/code]

Member Avatar for MareoRaft
0
187
Member Avatar for amaanbhae

[QUOTE=NathanOliver;1613622][code=c++] class String { }; [/code] Here is a string class for you. All you need to do is fill in the blank[/QUOTE] Actually according to his post, thats all he needed. How dare you give him all that hard working code ;)

Member Avatar for Ketsuekiame
-5
181
Member Avatar for pseudorandom21

I though it was obvious that Obama was going to get reelected? The main reason being, that during his presidency, Osama was killed.

Member Avatar for pseudorandom21
0
660
Member Avatar for ztdep
Member Avatar for IMJS

>>[B]char*** b_array_ptr[/B] You can think this as a pointer to a 2D array of chars. Example will suffice: [code] #include <iostream> using namespace std; int main(){ char ***ptr = 0; //dynamically initialize it const int WIDTH = 3; const int HEIGHT = 3; const int DEPTH = 3; ptr = …

Member Avatar for fruitymo
0
117
Member Avatar for tubby123

You can do this on O(n) using the fact that characters has a number associated with them. Here is [URL="http://codepad.org/MevXtEXU"]live code[/URL]

Member Avatar for mrnutty
0
106
Member Avatar for mrnutty

Meant mostly for windows, uses system("cls") although you can simply set USE_NON_STANDARD_CLS to false and it will use newlines to clear screen. Test it out. [code] /** * Note: Use at own risk, this is just for fun */ #include <algorithm> #include <iostream> #include <vector> #include <string> #include <windows.h> #include …

Member Avatar for mrnutty
0
156
Member Avatar for shizu
Member Avatar for Tomi1988

Ok here is an analogy I head and I will try it out: Imagine you picked a hotel, and then you bought a room, so they gave you the key to that room. You take out your bible, read it and then put it inside your drawer. Next morning you …

Member Avatar for mrnutty
0
207
Member Avatar for Stefano Mtangoo

[QUOTE=evstevemd;1608986]I'm not sure where this post fits, but after staggering here and there I Thought I would throw it here! I find difficult to make coordinates by hand (Not very good at x-y-z though I know the XY coordinate). Is there a tool that will allow you to draw let …

Member Avatar for Stefano Mtangoo
0
236
Member Avatar for toneranger

You can use a date as reference time, and calculate the number of seconds since that that time. You can do this for each data, and do comparison and analysis between dates that way.

Member Avatar for Ancient Dragon
0
242
Member Avatar for DJSAN10

[QUOTE=DJSAN10;1610754]what happens if we delete a pointer twice..??[/QUOTE] The FBI, CIA, and the military comes to your house via dragon and breaths fire onto your soul sending you to hell for eternity to burn, simply because you deleted a pointer twice. So next time be aware.

Member Avatar for DJSAN10
0
670
Member Avatar for Raim

@OP: [code] int userInput = 0; const int QUIT = 8; do{ cin >> userInput; switch(userInput){ case ADD: doAdd(); break; case SUB: doSub(); break; case MULT: doMult(); break; case DIV: doMult(); break; case FACT: doFact(); break; case QUIT: break; default: doErrorInput(); break; } if(userInput != QUIT){ showMenu(); } }while(userInput != …

Member Avatar for mrnutty
0
119
Member Avatar for ordinary jam

[QUOTE=sfuo;1610138]In C++ I'd use classes and their operators to add the fractions together. You can play around with overloading the >> and << operators to make calling input/output neater. [CODE]#include <iostream> #include <conio.h> using namespace std; class FRACTION { int numerator; int denominator; public: FRACTION() { cin >> numerator >> …

Member Avatar for mrnutty
1
1K
Member Avatar for Xoltha

Can you use std::string? If not you can do something like this: [code] void substituteRule(const char *expr, const char *rule, char *result){ if(!expr) return; else if(expr[0] == 'F') _expand(result,rule); // rule = rule + result; Substitute rule else _expand(rule,expr[0]); //else no substitute just add substituteRule(expr + 1, rule, result); //else …

Member Avatar for teo236
0
176
Member Avatar for awah mohamad
Member Avatar for Awah Mohamed
0
148
Member Avatar for LevyDee

>>[B]for(int i = 0; i < (sizeof(animations) / sizeof(Animation)); i++)[/B] I hope you know that, thats only going to run once. And for your error, are you sure its in that line? If what you say is true then it should compile. Lets see the definition of condition and AnimationCondition.

Member Avatar for mrnutty
0
167
Member Avatar for logan_231_2009
Member Avatar for user786
0
3K
Member Avatar for Zvjezdan23

There are some serious problems with your code. Here is a fix. I'll let someone explain it, because I don't have enough patience right now. [code] #include <iostream> #include <string> #include <algorithm> #include <cmath> using namespace std; void DistanceofTwoCars(float *car1, float *car2){ cout << "The Distance between Car 1 and …

Member Avatar for mrnutty
0
163
Member Avatar for Ahmed2

You do not want remove, but list::erase. Here is your code with tags and a little more cleaned up: [code] cout << "Contents: "; list<FileInfo*>::iterator p = futurelist.begin(); while(p != futurelist.end()) { cout << (*p)->submissiontime << " "; cout << (*p)->length << " "; cout << (*p)->finishtime << " "; …

Member Avatar for Ahmed2
0
172
Member Avatar for dilequeno

Make your class as such: [code] class dm_energy_vec { public: dm_energy_vec(){} dm_energy_vec(const vector<float>& vec): m_energy_dep(vec){} vector<float> m_energy_dep; }; [/code] and in line 40, change to: [code] energy_dep_sum.push_back( dm_energy_vec(energy_dep)); [/code] but honestly see no point for that class.

Member Avatar for dilequeno
0
102
Member Avatar for Sonia11

[QUOTE=L7Sqr;1608044]Any reason you can't use standard facilities? For example:[code]#include <iostream> #include <vector> #include <algorithm> struct Equals { Equals(int x) : v_(x) {} bool operator() (int x) { return v_ == x; } int v_; }; int main () { std::vector< int > items; for (int i = 0; i < …

Member Avatar for L7Sqr
0
4K
Member Avatar for kalingaRHASTA

Easy enough, assuming some things. [code] int maxVal = INT_MIN; int minVal = INT_MAX; int input = -1; const int END = -1; while( cin >> input ){ if( input == END) break; else{ minVal = std::min(minVal,input); maxVal = std::max(maxVal,input); } } [/code]

Member Avatar for Salem
0
261
Member Avatar for L3gacy

[CODE] while(begin != end ) words[*begin++]++; [/CODE] is the same as: [code] while(begin != end ) //<-- I believe the stream iterator is getting input here { int count = words[*begin]; //get the value for the given word words[*begin] = count + 1; //increase the count by 1 ++begin; //move …

Member Avatar for mrnutty
0
323
Member Avatar for MareoRaft

It really up to the compiler to decide what to do on overflow. I don't think there is a standard mechanism to handle overflow. But a lot of compilers, wraps around the values. And it seems like you need a variable that can hold the proper range, promote the variable …

Member Avatar for mrnutty
0
136
Member Avatar for MareoRaft

>>[B]And of course, is it WORTH passing ints by reference?[/B] No not really, unless you do need to modify the int. Reference and ints usually take up same size, so no noticeable advantage.

Member Avatar for mike_2000_17
0
300
Member Avatar for MareoRaft

>>[B]Why is it a bad idea to use the std namespace for my new functions? If all of my functions have names which are different than the names of std functions, it is no harm, right? [/B] No do not do that. To avoid conflicts( perhaps in the future), you …

Member Avatar for mrnutty
0
150
Member Avatar for MareoRaft

>>[B]There is an error concerning lines 10-14. I had been using this code previously without errors. I'm not sure what I may have changed. [/B] IT previously worked because you probably never used that function, so the program didn't instantiate it. But since now you are using it, the compiler …

Member Avatar for mrnutty
0
2K
Member Avatar for mark_6

Steps: [CODE]- Get ColumnSize - Create a 2D array ColumnSize x ColumnSize with each element initialized to ' '(space) - Populate the First and last column of the 2D array '#' - for i = ColumnSize - 1 to 0 - make Array2D[ColumnSize][ColumnSize] = '#' - Print the whole array[/CODE] …

Member Avatar for sumant mahadik
-1
1K
Member Avatar for MareoRaft

Your using the wrong structure, check out [URL="http://www.cplusplus.com/reference/std/valarray/"]std::valarray[/URL]

Member Avatar for mike_2000_17
0
153
Member Avatar for radiata

You can't compare in C++ like you do in math. This [icode]if(a > b > c)[/icode] is wrong, it gets evaluated to [icode] (a>b) > c [/icode]. So if a>b, it returns true, and it compare if true is > c. What you want is [icode] if(a > b && …

Member Avatar for Nick Evan
0
206
Member Avatar for ztdep

Are you comparing char* to char*? It depends on the datatype of keyword. If so then consider using strcmp function of change from char* to std::string

Member Avatar for mrnutty
0
241
Member Avatar for MooGeek

Presumably I'll have a family by then, So I'll hang around with them, Im a fun guy!!! Other than that, I have no idea, only time will tell

Member Avatar for almostbob
0
279
Member Avatar for munitjsr2

PLease help me with these questions, I was interviewed for thses just today Q1)Can we delare constant data members inside a class? Q2)does friend function violates encapsulation/data hiding? Q3)what are the types of polymorhphism you know? Q4)why do you need virtual functions? Q5)Can we do something like\ int & = …

Member Avatar for kanuxy
-2
185
Member Avatar for Nexgr

To transverse the tree and test for certain condition you can a structure like this: [code] //assume private template<typename Predicate> bool MyTree::transverse(const TreeNode& root,const Predicate& tester){ if(!root) return false; else if(tester(root.getCod()) == true) return true; else return transverse(root.getLeftChild()) || transverse(root.getRightChild()); } //assume public bool MyTree::find(const std::string& target){ struct MyCompare{ bool …

Member Avatar for Nexgr
0
152
Member Avatar for NvIs

[B]>>adding rows and columns of a multi array[/B] For a second I was happy because I though you were using boost::multi_array, but oh well. As for a solution to your problem, I suggest you create an array that holds the sum of each column. Here is some code hints : …

Member Avatar for PCSO
0
4K
Member Avatar for gujinni

Its behavior is equivalent to : [code] //src via cplusplus.com template <class InputIterator1, class InputIterator2, class OutputIterator> OutputIterator set_difference ( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result ) { while (first1!=last1 && first2!=last2) { if (*first1<*first2) *result++ = *first1++; else if (*first2<*first1) first2++; else { first1++; first2++; …

Member Avatar for gujinni
0
270
Member Avatar for TheLittleEngine

Do something like this: Assume the user inputs something like this, [I]"234,324,324.66"[/I]. Then you can do the following, 1) Replace all instance of ',' with ' '. That is replace a comma with space. 2) Load the string into a stringstream object 3) Read the money one by one. Here …

Member Avatar for sfuo
0
164

The End.