2,712 Posted Topics
Re: Then go for, Lucas series. The only difference is the starting value. For fibonacci f(0) = 1, and f(1) = 1. Then its defined recursively as f(n) = f(n-1) + f(n-2), where n >=2. For Lucus series, f(0) = 2, and f(1) = 1, then its defined recursively as f(n) … | |
Re: Because as of right now you have to include the definition of the template class in the same file as the template header. If your compiler supports the keyword export, then you can separate them. | |
Re: Or just get it as a string and see what it contains. For example : [code] string number; cin >> number; //say user entered "123" int a = number[0] - '0'; //a = 1 int b = number[1] = '0'; //a = 2 int c = number[2] = '0'; //a … | |
Re: Make your first for loop like so : [code] for ( i=2;i<=40;i++)[/code] Then make your second for loop like so [code] for(i2=2; i2<i; i2++)[/code] The main problem is that you are printing inside the loop. Print outside. You overall loop could look like this : [code] int i = 0, … | |
Re: [QUOTE=vijaysoft1;1134776]I am stuck with one problem , please anyone help me to do this . The question is Write a function to modify a list ( [I]one dimensional array[/I] ) of numbers such that every number is replaced by the average of its immediate neighbours ( [I]the value just above … | |
Re: This is wrong right of the back, "while (found=false && first<=last)". This is also wrong : [code] else if(searchValue>array[midpoint]) last=midpoint-1; else first=midpoint+1; [/code] Any clue why? | |
Re: Its good. The source is just not so flexible. You should separate it into files. Make use of structures, if you know how. You use mostly brute force, even with variables. Also do not use magic numbers, use constants, so its more readable and clear. Your source has a lot … | |
Re: >>[B] can anyone help me initialize this array with nested for loops?[/B] Do you know how to do it for a single for loop, i.e initialize say an Array[4] using a for loop? | |
![]() | Re: The inner loop is O(n^2), the most outer loop is log(n) [ I think ], so I would guess its log(n)*O(n^2). |
Re: We're not physics. Post your code! Its probably something wrong with your program. Maybe the "1" in "104" is your boolean variable and the 04 is something else. | |
Re: Try to make your own using the ctime header. Here is some starter code [code] class Timer{ private: long startTime; long endTime; public: Timer() { startTime = endTime = clock(); } void startTimer(){ } void stopTimer(){ } long getElapsedMilliSeconds(){ } long getElapsedSeconds(){ return getElapsedMilliSeconds() * CLOCKS_PER_SEC; } float getElapsedMinutes(){ return … | |
We are all tired of from our daily lives. So I suggest to sit back and play this game. I present here a hangman game( text version ) for your enjoyment. There might be some bugs as I haven't throughly tested it, so sorry if you find it( I'm sure … | |
| |
Re: This [CODE]void setDrawRectangleBorder() { char border; cout << "Enter the character you would like to see as the border of the rectangle:"; cin >> border; }[/CODE] Does not do anything useful. | |
Re: You need to realize the conversion between 2d array and 1d array. Namely, that 1D_Row = 2dRow * MAX_ROW + 2D_Column; In code it would look like this : [code] for(int row = 0; row < MAX_ROW; ++row){ for(int col = 0; col < MAX_COL; ++col){ Array1D[col + row*MAX_ROW] = … | |
Re: In recursion there are 2 main things : 1) basis : 2) Induction. In you recursive, you have provided the Induction, namely f() = f(), but you have not provided a basis case. Here is an example of a recursion function. Again, a recursion function has a basis and the … | |
Re: I really do wan't to help you, but I can't. Your code is hard to read. I would recommend you to indent your code. Then give it a try and see what happens. Then maybe shorten it as much as possible to show us what problem you are having. | |
Re: >>[B]Anyways you should be able to fix the problem you have by declaring pBeam in a global scope (by declaring it outside of functions at the top of your file).[/B] You should but that is not a good solution. Don't start of learning bad practices. It will only come back … | |
Re: The warnings tells a thousand words : [code] 30 [Warning] ` class Kontrolka' only defines private constructors and has no friends 33 [Warning] ` class KontrolkaAtomowa' only defines private constructors and has no friends 36 `Kontrolka' with only non-default constructor in class without a constructor [/code] Realize that in a … | |
Re: Use cout and cin instead of the C function printf and scanf, after all this is C++. Using rand, you have the correct idea, but you also have to seed it. Insert this code : srand( time(0) ) at the very beginning of your main. That code seeds the rand … | |
Re: The problem is that D3DXVECTOR3 is not being found for whatever reason. Have you linked ALL of the lib and headers? Maybe something got corrupted. >>[B]I've actually been building this from a tutorial (its beginners DirectX for C++ Veterans) where the source code compiles and runs perfectly, yet, even pasting … | |
Re: >>[B]if (answer!=df1/df2)[/B] what happens if df2 > df1. For example say df1 = 20 and df2 40 answer = df1 / sf2 = 20 / 40 = 1/2 = 0.5 Thats a fraction. And your variables are of type Int. That means the real answer gets truncated. Which means if … | |
Re: Use std::copy. If not then create your own like so. [CODE]#include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; template<typename Container> void print(const Container c){ Container::const_iterator itr = c.begin(); cout << "{ "; while(itr != c.end()){ cout << *itr++ << " "; } cout << "}"<<endl; } template<typename … | |
Re: Using only C++ won't do this for you. You will have to use external libraries and such. For example using win32, you probably can get control of the mouse, maybe. Using audio libraries, you can play an manipulate sounds. Using an image library, you can manipulate images. Using a graphics … | |
Re: >>[B]But, I've been told that srand() will produce a better random number[/B] Whomever told that to you should not talk about programming anymore. All srand does is seed the random number generator. [B]>>a good one is the mesner twister >>It's called the Mersenne Twister.[/B] Yes that is better than rand, … | |
Re: This : [code] class Test{ int i; public : Test() : i(0){} }; [/code] is very similar to this : [code] class Test{ int i; public: Test(){ i = 0; } }; [/code] The only difference is that the first one is more efficient, and as pointed out, its called … | |
Re: >>[B]const char *str1 = "pointer to constant"[/B] That means that the pointer points to a const data. Which means that the pointer can't change the const data that its pointing since a const data cant be changed. But it can point to somewhere else. >>[B]char *const str2 = "constant pointer";[/B] … | |
Re: In C++ easy as 1,2,3 : [code] double toDouble(string str) //1 -- define function { //2 -- use simple logic and some stream object stringstreamm convert; convert << str; double val = 0.0; convert >> val; return val; //3 -- return value, assuming it was a success. } [/code] | |
Re: The use of destructor is to delete or release any memory that has been allocated. In Java, they handle the garbage collection for you. C++ is not as friendly. You have to use the destructor to delete or handle anything that needs to be handled when the object gets destroyed. … | |
Re: Cross platform, I would say openGL is your best bet. | |
Re: No since the return type is of char reference, that means you can change the value while accessing it as well. | |
[URL="http://www.codinghorror.com/blog/archives/000781.html"] This [/URL] is a little hard for me to believe. Thankfully, I am not one of those applicants, nor ever will be. | |
Re: >>[B] 1)if i wanted to write a line of code needed to declare a 1-dimensional array named names that can hold 8 string values would this be correct?: char names[8];[/B] Nope what you declared is an array of chars. chars are just 1 character. For example 'a' is a char, … | |
Re: >> the flamethrower works differently then the gun Does it? The flamethrower shoots and so does the gun. The flamethrower has some mass and so does the gun The flamethrower can run empty and so does the gun. The point here is that, they do differ internally, but not so … | |
Re: Make use of the string functions like find_first_of and so one. For example you can do something like this : [code] string vowels = "aeiou"; string sentence = "hello baby!"; if(sentence.find_first_of(vowels) != string::npos){ cout << "There is a vowel in " << sentence << endl; } [/code] | |
Re: That sucks so bad. If it makes you feel better, my classes this semester is a tough load. Its busting my chops and we just started. | |
Re: Just make a wrapper function : [code] void print(std::string msg, int posX, int posY, int color){ textout_ex(screen, font, msg.c_str(),posX, posY, color); } [/code] And use it like so : [code] void doo(){ string msg = "hello 2d world!"; print(msg,0,0,makecol(255,0,0)); } [/code] an even better wrapper : [code] void print(std::string msg, … | |
Re: What you should do is create a 2D array class. Then use a vector to hold it. Here is what I mean : [code] std::vector< Array2D > vecOfArray2D; int size = 0; cin >> size; vecOfArray2D.resize(size); [/code] The Array2D is a class that you should implement. | |
Re: What you are looking for is template. I think this is what you are trying to accomplish. [code] template<typename Type> class Object{ protected: Type var; public: Object(){} Object(const Type& initValue) : var(initValue){ } virtual string toString()const ; //leaves the derived to implement this } [/code] Then you can do something … | |
Re: Looks like your vertices are not correct. Have you tried to load a simple mesh first? | |
![]() | Re: The Art of sorting? The Art of searching? The Art of finding shortest path? ![]() |
Re: sigh. Its practically the same concept as before, when I gave you toHex() function. This time try to learn whats going on, please. [code] #include <iostream> #include <sstream> #include <string> using namespace std; template<typename Type> string toHex(const Type& value, bool showBase = true){ stringstream strm; if(showBase) strm << showbase; strm … | |
Re: Again use CODE TAGS...arghhh >>[B]What is the output?[/B] The output is either compile time errors, or a stack overflow in your "recurse" function. | |
Re: Show us how you are detecting your collision. And a picture of the situation would be nice as well. Depending on the situation, you might be able to get away with 1d collision. | |
Re: Use CODE TAGS please? >>[B] What is the output? [/B] The output is a bunch of compiler errors, that says WTF are you doing? | |
Re: First create a function that makes a rectangle like so : [code] ####### # # # # # # ####### [/code] After you get that , then its a simple change. | |
Re: You know most of the time the error says it all : [code]::list' : use of class template requires template argument list [/code] You have this [code] class MergingLists : public list[/code] The error tells you that list uses templates so that means that your MergingLists has to also be … | |
Re: It won't be hard. First if you do the way you suggested to do it, i.e [code] if(RIGHT_KEY_PRESSED) moveScreen(World.RIGHT); [/code] Then there will be a problem. The problem being that the screen will stutter. In fact try it out and see if its good enough, though. What I would suggest … | |
Re: If you want to see if a/b == c/d , then all you have to check if a == c && b == d; More specifically, if a == kc && b == kd where k is an element from the natural numbers. | |
Re: 1) Your insert function is incorrect 2) Your remove function is mis informative, called it removeTop() or pop_front(). 3) You concat function shouldn't be very hard(unless I am missing something). All you have to do is either append the whole list you get into your list front part or the … |
The End.