2,712 Posted Topics

Member Avatar for MareoRaft
Member Avatar for yobbko

Why do you need to use C++? Use the right tool. I suggest you to use javascript.

Member Avatar for raptr_dflo
0
948
Member Avatar for mahmoz

Create the following: 1) PredatorModel class 2) PreyModel class 3) MapView 4) PredatorController 5) PreyController Your PredatorModel will contain all function necessary for a Predator like move, think, kill and so on. Your PreyModel will contain all function necessary for a Prey like sleep, eat, and so on Your MapView …

Member Avatar for raptr_dflo
0
280
Member Avatar for massivefermion

Are you trying to use STL or not? If not then all you have to do is include headers [code] #include <vector> #include <string> using namespace std; int main(){ vector<string> a; vector<double> b; } [/code]

Member Avatar for raptr_dflo
0
2K
Member Avatar for infiniteloop56

Your pow function is incorrect. Your first task is to create this function [code] //returns base^exp in mathematical sense //example power(2,2) => 4 , power(2,8) => 256 //note works only for exp > 0 int power(const int base,const int exp); [/code] then you can use that power function in your …

Member Avatar for raptr_dflo
0
232
Member Avatar for Ninjah
Member Avatar for The_Prince

[QUOTE=Narue;1579218]Use the simplest method until you can prove that it doesn't perform well enough for your needs. A vector of vectors will probably be the simplest, and should also be sufficiently fast, but there's no way of knowing until you've profiled it with a realistic data set.[/QUOTE] Although I would …

Member Avatar for mrnutty
0
172
Member Avatar for Saith

@OP or a more generic approach: [code] struct InvalidInputException : std::exception{ InvalidInputException(): std::exception("Error: Invalid conversion") {} }; //tries to get a data of type T, throws InvalidInputException if failed template<typename T> T prompt(const std::string msg){ cout << msg ; T res = T(); if( ! (cin >> res) ){ cin.clear(); …

Member Avatar for vijayan121
0
336
Member Avatar for pril

This question is so ambiguous since it doesn't define what an empty array should constitute. One can only guess, smh

Member Avatar for pseudorandom21
0
115
Member Avatar for jens123
Member Avatar for mrnutty
0
175
Member Avatar for ztdep

Another way using std::vector( not tested nor compiled ) [code] template<typename T> class Array2D{ public: typedef std::vector<T> ColumnVector; typedef std::vector<ColumnVector> Array2DType; private: Array2DType _array; public: Array2D(const int rowSize, const int colSize, const int initVal = 0) : _array( rowSize, ColumnVector(colSize, initVal ) ); const T& operator()(const int row, const int …

Member Avatar for vijayan121
0
189
Member Avatar for vTr
Member Avatar for WolfShield

Man, I just passed by teen years. I'm 20 currently. Times flies by so fast. I started like 2-3 years ago. It became an obsession initially, then started to die down a little, because I have way too much work to do,in and out of school. As an advice, I …

Member Avatar for thing789
0
315
Member Avatar for ifiok.idiang
Member Avatar for Rashakil Fol
1
133
Member Avatar for Drau

You can simply append 0 since it does nothing: [code] string toString(const double d, int nZero = 0){ stringstream stream; stream << d; return stream.str() + string(nZero,'0'); } [/code] If you use the double value to print out the value then you can set its precision like so : [code] …

Member Avatar for Drau
0
154
Member Avatar for axeves

You would have to include that header before you can use it. For example, [code] //in foo.h struct Foo{ //... }; [/code] [code] //main.cpp #include <iostream> #include "foo.h" int main(){ Foo f; } [/code]

Member Avatar for pseudorandom21
0
128
Member Avatar for lochnessmonster

[QUOTE=Narue;1575270]Yes, I know. And it's easily the most complex part of the standard C++ library. How many hundreds of pages do you expect for a complete description of everything that's going on?[/QUOTE] just curious, why would you take the trouble to learn that? For fun?

Member Avatar for vijayan121
0
120
Member Avatar for mrnutty

Anyone here working on some project? I'm just curious on what people here work on? Maybe its a job or maybe a virus to steal bank accounts, either way, don't hesitate not to say and announce it here. This could potentially give others ideas on what their next project should …

Member Avatar for sergent
0
205
Member Avatar for theguitarist

It first reads 2, and stores it in x. It then reads 4 and stores it in x. Reading is done so now it executes the body. The 6 you entered also, does not get read into x or y just yet, because the stream already read 2 and 4, …

Member Avatar for WaltP
0
493
Member Avatar for Muhammad Anas

[QUOTE=Muhammad Anas;1573712]I just downloaded a document containing some pointers exercises. The statement of One of its questions is as follows: [COLOR="Green"]Write a function that returns a pointer to the maximum value of an array of double's. If the array is empty, return NULL. double* maximum(const double* a, int size); [/COLOR] …

Member Avatar for Muhammad Anas
0
1K
Member Avatar for Suzie999

I'm not completely sure but you might be able to do this [code] std::wstring basePath(L"file:"); std::wstring subPath(L"src/main.cpp"); std::wstring fullPath( basePath + L"\n" + subPath ); MessageBox(0,(_T)fullPath.c_str(),0,0); [/code]

Member Avatar for Suzie999
0
432
Member Avatar for moshe12007

start coding, just because you know theory doesn't mean your good at applying them. So start coding, gitty-up

Member Avatar for mrnutty
0
192
Member Avatar for Muhammad Anas

[QUOTE=Labdabeta;1573525]I don't see anything wrong. I would suggest for good practice also setting your pointers to null when you deallocate them. I sometimes like to define delarr in a preprocessor macro: [CODE]#define delarr(X) (delete[](X));((X)=0)[/CODE] Hope this helps. (Also I may be wrong so more people should check as well)[/QUOTE] If …

Member Avatar for Muhammad Anas
0
159
Member Avatar for Pinchanzee

idk too much about jQuery but it seems you can abstract: [code] <script> function foo(name,id) { var $j = jQuery.noConflict(); $j(function() { $j(name).click(function(evt) { $j(id).load("content.php?order=most&f=recent") evt.preventDefault(); }) }) } foo("mostrec","#1"); foo(".leastrec","#1"); //...so on </script> [/code]

Member Avatar for Airshow
0
242
Member Avatar for thecoolman5

Sucks at it happens. Thats why once a while you should hit cntrl-s( save shortcut ). This happened to me many times, and I learnt my lesson.

Member Avatar for thecoolman5
0
181
Member Avatar for Mr. K

Try increasing the speed to like 2000, is the ball position printing in different coordinates? If the if statements getting executed?

Member Avatar for raptr_dflo
0
107
Member Avatar for ichigo_cool

[URL="http://www.cplusplus.com/reference/stl/vector/assign/"]Read,Read,Read[/URL]

Member Avatar for ichigo_cool
0
197
Member Avatar for raj03

In your getCalc function, make cout and else and if statements lowercase

Member Avatar for tkud
0
192
Member Avatar for jonhylever
Member Avatar for tubby123

Hint: Use your pivot algorithm to work from the bottom up instead of top down

Member Avatar for mrnutty
0
229
Member Avatar for lochnessmonster

[QUOTE=lochnessmonster;1571191]it just seems wierd that if u truly want to read 4-bytes from memory address x00000007 you the processor must read starting from x00000004-x0000007 then make another read from x00000008-x0000000B then shift the unneeded bytes off! I was wondering why u cant say hey man lets read 4 bytes starting …

Member Avatar for mike_2000_17
0
128
Member Avatar for iamuser_2007

[QUOTE=iamuser_2007;1570561]Tell me about these and give me some negative and positive code examples. >>Stack Unwinding >>Constructors, Destructors and Exception Handling >>Exceptions and Inheritance thnx for information[/QUOTE] Stack Unwinding - its when a stack unwinds Constructors/Destructors/Exception Handling - its when you use constructors/destructors/exception handling Exception and Inheritance - Its when you …

Member Avatar for ichigo_cool
0
122
Member Avatar for jimJohnson

Simplify this: [code] bool isPalindrome(const std::string& s) { std::string sReverse = s; std::reverse(sReverse.begin(), sReverse.end()); return s == sReverse; // return true if the reverse is the same as non-reverse } [/code] to this : [code] bool isPalindrome(const std::string& s){ return s == string(s.rbegin(),s.rend()); } [/code]

Member Avatar for raptr_dflo
0
217
Member Avatar for iamuser_2007

Since you are reading the book, I assume you have some knowledge, so here is a basic start [code] class Quadratic_int{ private: int *coefficients; public: Quadratic_int(); //default constructor Quadratic_int(const Quadratic_int&) ; //copy constructor[ one of big 3 ] ~Quadratic_int(); //destructor[ two of big 3 ] Quadratic_int& operator=(const Quadratic_int&); // assignment …

Member Avatar for sergent
-2
193
Member Avatar for Geek-Master

Alternatively : [code] const int ROW_SIZE = 10; const int COL_SIZE = 10; int array2d[ROW_SIZE][COL_SIZE] = {0}; [/code]

Member Avatar for Hialek
0
5K
Member Avatar for Stefano Mtangoo

Read [URL="https://sites.google.com/site/tnuttysite/Home"]this[/URL]. It has very good explanation.

Member Avatar for Stefano Mtangoo
0
206
Member Avatar for jamesl22

Your camera has some position associated with it, check that position for potential collision and if collision moving up should mean a slight sliding to the right or left depending on the view vector

Member Avatar for jamesl22
0
981
Member Avatar for Saad234

Sounds like your using the wrong language all together. Consider using java, where it has all that for you, or just use pure C++ with a GUI library support. The easiest route would be to use java, but that depends on if you know java and how well you know …

Member Avatar for mrnutty
0
233
Member Avatar for programing

Your code is not easy to look at and your description is rather vague. To solve your problem all you have to do is use one stack for original input and use the other stack for reversal input like so : [code] #include <iostream> #include <stack> #include <algorithm> using namespace …

Member Avatar for raptr_dflo
0
230
Member Avatar for FoxInBoots

Formula is: s_n = n/2 * (a0 + an) for example, sum from 10 to 15 is: s_6 = 6/2 * (10 + 15 )= 75 where we note that 10 is the first term and 15 is the sixth term More details [URL="http://en.wikipedia.org/wiki/Arithmetic_progression"]here[/URL]

Member Avatar for FoxInBoots
0
2K
Member Avatar for vanalex

Yes in that for-loop example there would be a memory leakage if you don't deallocate the tab before reallocating memory for it again. [i]&tab[/i] means take the address of tab, in which if tab is an array, then when you pass it into a function, it decays into a pointer, …

Member Avatar for vanalex
0
112
Member Avatar for Haranadh

Create a recursive solution where it creates N/M by N/M subchunks where N > M and N % M == 0, and creates a separate thread to calculate the product of the two matrix using LU decomposition, and and uses that result for the parent subchunk. Other than that, use …

Member Avatar for mike_2000_17
0
312
Member Avatar for IMJS

Both example are similar, no you do not have a memory leak although there might be subtle problems with your first example. In general, use reference when possible instead of pointers. I'm sure mike below me will give you a more elaborate answer soon.

Member Avatar for mrnutty
0
187
Member Avatar for jory

On the contrary to whats being said, I advice you to not google it, not use std::reverse and not use std::string.rbegin() in conjunction with std::string.rend(). Your purpose should be to get better at programming, so one day you can solve problems by rational thinking, instead of googling everything. Then you …

Member Avatar for predator78
-1
105
Member Avatar for ravenous

From the presented solution, IMO OP solution is better. Reasons being( in no order ), 1) Less to Type 2) Less chance to get wrong 3) Follows Idiom better( reuse ) 4) Possibly faster 5) Cleaner 6) Safer 7) Is more C++ than C

Member Avatar for Narue
1
2K
Member Avatar for Smartflight

[QUOTE=Smartflight;1567497]Can this not be done without a constructor? Because we haven't learnt that yet... it's our next chapter, though.[/QUOTE] Yes, it can. A viable solution to this problem is to create a base counter class that is templatized. But I assume you haven't learn that before. So for now you …

Member Avatar for mike_2000_17
0
118
Member Avatar for ocramferreira

Forget about reading it in an array. Use the correct data structure. Lookup hashtable, which is just created for situation like these, lookup. Using hashTable, you can lookup in the dictionary on average on constant time, as well as insert in constant time. Basically, thats all the optimization you need. …

Member Avatar for iamthwee
0
572
Member Avatar for vegaseat

Anyone of these will do for me : Metis, Adrastea, Amalthea, Thebe ... There are 59 more that I can name. But thats good enough.

Member Avatar for jwenting
1
161
Member Avatar for annitaz

For 1, you choose A, which is correct. For 2, your almost there but its not correct, because there are 2 nested loop you have to take into account both of them. For 3, redo 2 then see what you get. But your almost there.

Member Avatar for mrnutty
-1
164
Member Avatar for johans22

[QUOTE=guest3;1565620]How to round a number like 1678.5445 to 1678.6?.[/QUOTE] Do you really need to round it like that? What benefit would that give you? Its questionable if it should even be rounded that way.

Member Avatar for Derek Elensar
0
112

The End.