2,712 Posted Topics
Re: 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 … | |
Re: 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 … | |
Re: >>[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 … | |
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 … ![]() | |
Re: [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. | |
Re: 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 | |
Re: [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 … | |
I'm presenting to day at my internship in front of the whole company and the president, wish me luck!!!! I'm so nervous. | |
Re: [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! … | |
Re: Use matlab. Its made for these kinds of things. Choose the correct language. | |
Re: 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 … | |
Re: >>[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] | |
Re: [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 ;) | |
Re: I though it was obvious that Obama was going to get reelected? The main reason being, that during his presidency, Osama was killed. | |
Re: Can you post "Simulation.h" ? Make sure you spelled if correctly | |
Re: >>[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 = … | |
Re: 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] | |
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 … | |
Re: Take the BMP image, copy it into paint. Then save it as JPEG | |
Re: 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 … | |
Re: [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 … | |
Re: 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. | |
Re: [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. | |
![]() | Re: @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 != … |
Re: [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 >> … | |
Re: 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 … | |
Re: No pick a better language. Javascript would be a good choice. | |
Re: >>[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. | |
Re: Can you define what you mean by a critical path? Maybe give examples. | |
Re: 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 … | |
Re: 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 << " "; … | |
Re: 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. | |
Re: [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 < … | |
Re: 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] | |
Re: [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 … | |
Re: 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 … | |
Re: >>[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. | |
Re: >>[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 … | |
Re: >>[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 … | |
Re: 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] … | |
Re: Your using the wrong structure, check out [URL="http://www.cplusplus.com/reference/std/valarray/"]std::valarray[/URL] | |
Re: 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 && … | |
Re: 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 | |
Re: 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 | |
Re: 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 & = … | |
Re: 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 … | |
Re: [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 : … ![]() | |
Re: 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++; … | |
Re: 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 … |
The End.