2,712 Posted Topics
Re: You want [icode] ifstream in(foom.c_str());[/icode] | |
Re: Why do you need to use C++? Use the right tool. I suggest you to use javascript. | |
Re: 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 … | |
Re: 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] | |
Re: 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 … | |
Re: what error? What exactly is the problem you are having? | |
Re: [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 … | |
Re: @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(); … | |
Re: This question is so ambiguous since it doesn't define what an empty array should constitute. One can only guess, smh | |
Re: Yea I believe thats what the author meant, although its not good code. | |
Re: 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 … | |
Re: What exactly are you having a problem with? | |
Re: 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 … | |
Re: A hint, read the definition of a binary tree, then see how it applies to the trees's children. | |
Re: 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] … | |
Re: 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] | |
Re: [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? | |
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 … | |
Re: 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, … | |
Re: [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] … | |
Re: 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] | |
Re: start coding, just because you know theory doesn't mean your good at applying them. So start coding, gitty-up | |
Re: [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 … | |
Re: 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] | |
Re: 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. | |
Re: Try increasing the speed to like 2000, is the ball position printing in different coordinates? If the if statements getting executed? | |
Re: [URL="http://www.cplusplus.com/reference/stl/vector/assign/"]Read,Read,Read[/URL] | |
Re: In your getCalc function, make cout and else and if statements lowercase | |
Re: Hint: Use your pivot algorithm to work from the bottom up instead of top down | |
Re: [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 … | |
Re: [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 … | |
Re: 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] | |
Re: 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 … | |
![]() | Re: Alternatively : [code] const int ROW_SIZE = 10; const int COL_SIZE = 10; int array2d[ROW_SIZE][COL_SIZE] = {0}; [/code] |
Re: Read [URL="https://sites.google.com/site/tnuttysite/Home"]this[/URL]. It has very good explanation. | |
Re: 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 | |
Re: 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 … | |
Re: 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 … | |
Re: 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] | |
Re: 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, … | |
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
Re: 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 | |
![]() | Re: [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 … |
Re: 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. … ![]() | |
Re: Anyone of these will do for me : Metis, Adrastea, Amalthea, Thebe ... There are 59 more that I can name. But thats good enough. | |
Re: 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. | |
Re: [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. |
The End.