2,712 Posted Topics

Member Avatar for RayvenHawk

1)Find all C++ reserved keywords online. 2)Insert the reserved keywords in order into map. 3)Read in word by word from the text file 3.a) For each word check if it needed word exist in the map 3.a.1) If not then "forget about it" 3.a.2) If so then doStuff with it

Member Avatar for mrnutty
0
164
Member Avatar for tennis
Member Avatar for maleeha munawer

to convert to a string use this function : [code] #include <string> #include <sstream> #include <iostream> using namespace std; template<typename T> string toString(const T& arg){ std::streamstream ss; ss << arg; return ss.str(); } int main(){ cout << toString(123) << endl; cout << toString(12.345) << endl; } [/code]

Member Avatar for maleeha munawer
0
63
Member Avatar for Ayaat Monem
Member Avatar for Buolbear4444

First some design problem. This function is pretty bad : [code] void attackplayer(Player& hero, bool checkup, bool checkdown, bool checkleft, bool checkright){ if (checkup == true || checkdown == true || checkleft == true || checkright == true){ hero.damage(damage); } } [/code] First an obvious way to make this better …

Member Avatar for Buolbear4444
0
186
Member Avatar for 7h3.doctorat3

If its only 1-3 length, then just hard code it like so : [code] int toInt(const string& str){ int result = 0; switch(str.length()){ case 1: result = str[0] - '0'; break; case 2: result = (str[0]-'0')*10 + (str[1] - '0'); break; case 3: result = (str[0]-'0')*100 + (str[1] - '0')*10 …

Member Avatar for mrnutty
0
493
Member Avatar for kalai_c_k

Seems like a homework problem to me. But you need to use the following : 1) Polymorphism 2) Classes 3) std::vector 4) virtual functions 5) Inheritance

Member Avatar for mrnutty
0
121
Member Avatar for erka4444

Why do you have 2 isDead function? From your code, it seems like isDead function needs to be just a function like so : [code] struct Particle{ float posX, posY; }; bool isParticleDead(const Particle& p){ return isOutOfScreen(p);} int main(){ list<Particle> p; p.push_back( Particle() ); p.push_back( Particle() ); p.remove_if(isParticleDead); } [/code]

Member Avatar for mrnutty
0
191
Member Avatar for LevyDee

The derived object is not the main focus, its the base object. By the base object being able to point to the derived object, it calls Derived::print function, if it in fact points to a derived object else it calls its own. Of course this assumes print is a virtual …

Member Avatar for AkashL
0
110
Member Avatar for VorSec

Here is C++ version just because I'm feeling nice today. [code] #include <iostream> #include <vector> #include <string> #include <algorithm> #include <iterator> #include <sstream> using namespace std; template< typename T> struct EqualCheck{ T rhs; EqualCheck(): rhs(){}; EqualCheck(const T& Rhs) : rhs(Rhs){} bool operator()(const T& arg){ return arg == rhs; } }; …

Member Avatar for iamthwee
0
1K
Member Avatar for Andreas5

Its pointless doing this since, you are using string, unless you are doing this as an exercise. [code] string text = "This is the text I want to search in"; string wordToFind = "want"; bool isFound = text.find(wordToFind) != string::npos; [/code]

Member Avatar for Andreas5
1
161
Member Avatar for j-green.10

[QUOTE=j-green.10;1243286]I have a string that includes numbers and letters and I want to be able to seperate the string into parts. An example of the string looks like this FAP834E. I want to seperate it so that the first letter is seperate (F), the second and third are together (AP), …

Member Avatar for Lerner
0
93
Member Avatar for Arlamos

Whats wrong with this : [code] vector< vector<Point> > possible_neurons vector< vector<Point> > possible_neurons_second_copy; possible_neurons_second_copy = possible_neurons; [/code]

Member Avatar for NathanOliver
0
112
Member Avatar for AspiringCoder

Here is an example : [code] #include <iostream> #include <vector> #include <string> using namespace std; int main(){ vector< string > names; const string END = "!"; cout << "Enter many names... <enter '" << END << "' to quit >\n"; while(true){ string temp; cin >> temp; if(temp != END) names.push_back(temp); …

Member Avatar for mrnutty
0
144
Member Avatar for albertkao
Member Avatar for Rajesh R Subram
0
110
Member Avatar for gtschemer

void* is usually used to simulate generics in C. In C++, template were made to remove this bad method. Since you are using C++, definitely, ditch void* and use templates.

Member Avatar for Banfa
0
129
Member Avatar for ryan858

Also subtle but still there, this part : [code] char* argv[1] [/code] creates a array of char pointer, with size 1, thus only index 0 is valid. That means that this code :[code] string arg = argv[1]; [/code] is a index out of bounds.

Member Avatar for Aranarth
0
86
Member Avatar for marcoakis

No that you have hardcoded the work, I would use stl to lessen the work I have to do. That means, more efficient code, safer, readability, and shorter code. For example, your listPropertiesSorted could be something like this : [code] bool propertiesCompare(const Property& lhs, const Property& rhs){ /* compare properties …

Member Avatar for mrnutty
0
79
Member Avatar for gtateco

I hope there is no naming conflict here , since there is a std::list. But this code: [code]listArray = new list[hashTableSize];[/code] will THROW and exception, instead of setting listArray to null. So there is no reason to check if listArray is null, because you won't get a chance to check …

Member Avatar for mrnutty
0
3K
Member Avatar for ayan2587

For this, read up on [URL="http://en.wikipedia.org/wiki/Modular_exponentiation"]Modular exponentiation[/URL]. Using that technique, will help you solve this problem.

Member Avatar for ayan2587
0
204
Member Avatar for bsse007

Not compiled. [code] #include <iostream> #include <fstream> #include <algorithm> #include <string> using namespace std; int main(){ std::ifstream fileReader("text.txt"); std::string content; std::string temp; while( getline(fileReader,temp) ){ content += temp; } char letterToFind = 'A'; int count = std::count(content.begin(),content.end(),letterToFind); cout << count << " occurrence of '" << letterToFind << "'\n"; } …

Member Avatar for Radical Edward
0
127
Member Avatar for jackman05

Note there are explicit formulas for 2x2 and 3x3 matrix, see [URL="http://en.wikipedia.org/wiki/Invertible_matrix"] here [/URL]

Member Avatar for mrnutty
0
317
Member Avatar for c++_fem

why [URL="http://www.cplusplus.com/reference/algorithm/next_permutation/"]yes[/URL] there is.

Member Avatar for c++_fem
0
2K
Member Avatar for frag

>>is this correct or wrong? why? what if you wanted to add more cities, say 100 more. How much code do you think you would have to write ? Thus a good code, not only cares about its present status, it also cares about its future status as well.

Member Avatar for JohnSmith12
0
133
Member Avatar for Fernidad13

>> What kind of math do they use and how?? Every kind. From simple addition, to stokes equations, to rays to everything.

Member Avatar for digital29
0
584
Member Avatar for lul

[QUOTE=iamthwee;1239322]Which one? Transpose, adjoint, inverse, addition, identity, multiplication ...[/QUOTE] subtraction, LU factorization, elementary row operations, power, determinants ...

Member Avatar for mrnutty
-2
27
Member Avatar for bobsta

>>typedef std::vector vector <class B> bVecArray is that supposed to be : [code] typedef std::vector< vector <class B> >bVecArray //or typedef std::vector<class B> bVecArray [/code]

Member Avatar for mrnutty
0
145
Member Avatar for bladethebric

opengl does not have anything for printing a text. If you are using glut. Then you can use glutBitmapCharacter function. If not, then there are plenty of libs that prints fancy texts for you. Go ahead and google it.

Member Avatar for bladethebric
0
112
Member Avatar for aryansmit3754

Why would anyone do this? Ouch my eyes. Use either std::for_each, BOOST_FOR_EACH, or even manually.

Member Avatar for mrnutty
0
202
Member Avatar for abhi74k

No you are confusing yourself. This is what happens as pointed out : [code] A ob4 = (ob1.operaotr+(ob2)).operator+(ob3); [/code] But I think your problem is that this code : [code] A operator + (const A & ob){ return (num+ ob.num); } [/code] This code does NOT return a const object. …

Member Avatar for Aranarth
0
150
Member Avatar for new2programming
Member Avatar for iamcreasy

1) Write code. 2) Write more code. 3) Read up on design patterns, whether it be wiki or whatever 4) goto 1 until comfortable 5) Now every time you write code, you can either : 5a) Finish the code, and the project ( depending on its size) then take a …

Member Avatar for avarionist
0
171
Member Avatar for leesho

When you change the array size, change the bounds on the for loop as well. Thats why you should use integer constants : [code] const int MAX_SIZE = 10; int inputArray[MAX_SIZE] = {0}; //initialize all elements to 0 for(int i = 0; i < MAX_SIZE; ++i){ cin >> inputArray[i]; } …

Member Avatar for mrnutty
0
272
Member Avatar for rowley4

Generally : [code] declare var v1 declare stringstream converter declare var2 v2 converter << v1 //put variable 1 into stream, whether it be int,long,string... converter >> v2 //convert var1, into int,long,float,string or whatever type var2 is. [/code]

Member Avatar for daviddoria
0
136
Member Avatar for dimios

>> why Turbo C++ is still the dominant compiler in universities that still teach C++ [citation?] And, if you are using C++, then definitely use C++ containers. else if you are using C, then don't use C++ containers , lol.

Member Avatar for NathanOliver
0
218
Member Avatar for iamthwee

Use the property of sets. It only inserts elements that are unique. That means no same element will exist in the container. Do something like this. Note not compiled : [code] struct MyData{ //bunch of datas }; bool operator(const MyData& lhs, const MyData& rhs){ return true; } std::istream& operator >>(std::istream& …

Member Avatar for iamthwee
0
281
Member Avatar for Dows

The problem is you separate the definition of printVector. Your compiler can't handle defining a template function somewhere else than its declared file. So do this instead. [code] //myTools.h template<class Iterator> static void print(Iterator begin, Iterator end){ while(begin != end){ cout << *begin++ << " "; }; } [/code] Better …

Member Avatar for mrnutty
0
152
Member Avatar for m khan

The sphere could probably be drawing over your polygons. But, i'll have to see your code first.

Member Avatar for mrnutty
-2
47
Member Avatar for red999

>> don't I need to derefence Yes you do >>so the -> operator should be necessary on the first case Nope. The operator[] deferences the pointer.

Member Avatar for Ariste
0
100
Member Avatar for mrnutty

Not exactly sure where I would have posted this, maybe in the help wanted section, if there is one,( sorry I didn't bother looking). But I feel like I should place this post here, because there are some smart people that lurks in these woods. So I have my first …

Member Avatar for mrnutty
0
146
Member Avatar for epicasian

Better yet, you should decouple the system. A player class should not have an array that stores the animation sequence. Try something like this for example. [code] class Player{ //blah blah blah void move(int x, int y){ /*logic goes here */ } //more blah blah blah }; template<typename CoordType> struct …

Member Avatar for mrnutty
0
137
Member Avatar for mrnutty

Its this side thing I was working one, when I got the chance. Its not very good right now, as its still in its developing stage. But its still ok, where I can show it of, lol. Attached is an exe, that given a set of data points, it tries …

Member Avatar for NathanOliver
2
168
Member Avatar for Shaida

Also add std namespace : [code] #include<iostream.h> void hi(void); void name(void); using namespace std; int main() { ... } [/code] Otherwise you get errors like "cin" not found, and so on.

Member Avatar for Shaida
0
2K
Member Avatar for Alex_

[URL="http://en.wikipedia.org/wiki/Interpreter_pattern"]Wiki[/URL] is pretty clear. What part is confusing? Look at the [URL="http://upload.wikimedia.org/wikipedia/en/0/03/Interpreter_UML_class_diagram.jpg"]UML[/URL]diagram, and see if that helps.

Member Avatar for mrnutty
0
103
Member Avatar for spartanace

[QUOTE=spartanace;1232890]I found the solution just in case anyone is staring at this thread wondering the same thing about there template. The template is supposed to be a .h(header) rather than a .cpp.[/QUOTE] Yes thats, a known fact. The up coming C++0x is going to fix this.

Member Avatar for mrnutty
0
159
Member Avatar for new2programming

Create a hierarchy : [code] class Item{ //... virtual int points()const; //returns how much points this item is worth }; class Book{ //... int points()const{ return 2; } }; class Food{ //... int points()const{ return 5; } } ; //... [/code]

Member Avatar for new2programming
0
60
Member Avatar for Empireryan

If i read your question correctly then you can just do this : [code] int twoD[90][10]; //initialize twoD here int * randPtr = 0; int row = random(0,90); //some random function that returns a random number from [0,90) int col = random(0,10); randPtr = &twoD[row][col]; [/code]

Member Avatar for NathanOliver
0
104
Member Avatar for ssmg

Which version of MS Wrod do you have. In version 2007, it saves the formatting and the colors. Perhaps, try copy/pasting it on a text file. And then export it on M.S word.

Member Avatar for nbaztec
0
366
Member Avatar for dimios

Hey Narue, let me ask you something. If you got an offer to write a software, and your choices were only C and C++. Which would you choose ? "Different", yes. "Better", no" Can you show why this is ? Thats a big claim. I understand that OOP programming can …

Member Avatar for bandtank
0
221
Member Avatar for Tuyet Anh Pham
Member Avatar for Tuyet Anh Pham
0
311

The End.