2,712 Posted Topics
Re: Welcome, we'll be glad to help. Just make sure you read the rules, and use code tags and such. | |
Re: When you do this : [code] #include "sim.cpp" using namespace std; [/code] you are not including namespace std, inside sim.cpp, because of the ordering. Just do this : [CODE] #include <iostream> #include <fstream> #include <queue> #include <list> #include "ItemType.h" [COLOR="Red"]using namespace std;[/COLOR] [/CODE] yo | |
| |
Re: Your function prototype is constant corrected, so that means you cannot change the member variables, which you should not have to. First you need to check if both the matrix are of equal size( equal row AND equal column ). Then next, you should create a new matrix object, that … | |
Re: Why create it when stl already has one for you? Maybe you should give more information on what you are trying to do. | |
The objective is to make it last long as possible. The rules is that I say ONE word, and another person has to say ONE word which will be a part of a sentence when more word comes. A sample run : [ICODE]Post# The word posted --------------------------------- 1 Hello 2 … | |
Re: You should not worry about how fast a fundamental loop is. If you care about speed, then your bottleneck is probably elsewhere. | |
Re: >>[b]for i = 0 to n-1 do[/b] how long does this loop run for? >>[b]for j = 0 to (i^2) - 1 do[/b] Realize that this loop runs for (i^2)-1, for EACH i in the loop before this >>[b]for k = 0 to j - 1[/b] Realize that this loop … | |
Re: Usually one would use Vectors to store the positions. Like so : [code] struct Vector{ float posX; float posY; //.... } [/code] And if your Tree sprite class is something like this : [code] class Tree{ private : Vector position; //... } [/code] You would use composition inside your Tree … | |
Re: >>[b]Is it possible to do function overloading with different return type?[/b] No its not consider this situation : [code] void what(){ return /* nothing */ ; } bool what(){ return true; } int main(){ what(); //which function does this call ? } [/code] As you see, overloading functions with different … | |
Re: try something like this : [code] const int UPPER_LIMIT = 10; const int LOWER_LIMIT = 0; int chosenOne = 3; //within lower and upper limit int random = chosenOne; while(chosenOne == random){ random = randomNumber(LOWER_LIMIT,UPPER_LIMIT); } [/code] I'll let you define randomNumber(int,int) function. | |
Re: First make a matrix class. Have it functional with the appropriate functions. Then open the file and read it into the matrix. Then solve it using the matrix class and its operations. | |
Re: wait, can you repeat your question 1 more time, in a more clear and less anxious manner.Thanks and btw, this [code] BigInt number1; BigInt number2(3484858); BigInt number3("89347893478349234045"); cout << number1 + number2 + number3 << endl;[/code] is possible. | |
Re: Here is an example on how to grow vectors : [code] int main(){ std::vector<int> numbers; //input 10 numbers from user for(int i = 0; i < 10; ++i){ int input = 0; cin >> input; numbers.push_back( input ); } return 0; } [/code] | |
Re: Thats basically it. It divides the problem by 1/2 each time until it either finds a solution or is out of bounds. | |
Re: I think its hear : [code] cin >> userGuess; while (!cin >> userGuess) { [/code] In there you are asking the user to input a guess first. Then say it failed. Then in the while loop it goes to ask the user to input a number again. But the stream … | |
Re: Would something like this work for you : [code] float cut(float num, int maxDigitsAllowedAfterDecimal){ //error checking if you want int wholePart = num; if(maxDigitsAllowedAfterDecimal == 0) return wholePart; float decimalPart = wholePart - num; long factor = pow(10,maxDigitAllowedAfterDecimal); return wholePart + float(( long((decimalPart*factor))/factor)); } [/code] | |
Re: [QUOTE=abhimanipal;1203041]Probably some thing of this sort [CODE=C] void rev(int* arr, int lower, int upper) { if ( lower >= upper) return; // Swap the 2 values rev(arr, lower+1, upper-1); } [/CODE] Where lower and upper are the smallest and the largest indexes of the array[/QUOTE] Where are you changing the … | |
Re: >>well, the compiler fortunately didnt complain :-) No, in fact thats unfortunate. >>anyway, the advantage of this implementation over the next_permutation in STL is, that you can instantly get the permutation at any index. The disadvantages is that this is not a safe code. Its a homemade code, and is … | |
Re: >> for ( c = 0; c < 13; c++ ) should that 13 be 14 ? and go ahead and run the debug mode. It will give you more experience. | |
Re: You can use [URL="http://www.cplusplus.com/reference/algorithm/find/"] std::find[/URL] | |
Re: We can but not the way you showed it. [code] if ( (choice == 'e' || choice == 'E') && (cur == 'd' || cur == 'D' ) ){ //... } [/code] | |
Re: [QUOTE=VernonDozier;1200769]First thing that you need to do is write a driver program that has a main function in order to test it. Test the constructors and printRational. If you haven't written printRational, write it because you'll need it a lot when testing. [code] // driver program // includes int main … | |
Re: 1st Create an array of 20 elements like so : [code] const int MAX_STUDENTS = 20; int Scores[MAX_STUDENTS] = {0}; //create and initialize all 20 elements to 0 [/code] next you need to ask the user to enter 20 integers. Using a for loop is a good idea. For example, … | |
Re: put a break statement inside all of the if statement. Why not combine all of the if statement and provide a generic error message, if the detailed message is not important? | |
Re: You can't define a function inside another function. Here is one way : [code] #include <iostream> void aFunction(int x, int y); //function prototype int main(){ aFunction(2,2); //function call }//end of main void aFunction(int x, int y){ //function header and definition cout << "(" << x << "," << y << … | |
Re: change this : [code] # include <iostream.h> # include <conio.h> main () [/code] to this : [code] #include <iostream> #include <string> using namespace std; int main () [/code] and instead of getch() use this : [code] cin.clear(); cin.ignore(256,'\n'); string pause; getline(cin,pause); [/code] | |
Re: Assuming you are setting it something like this : [code] class Node{ //... }; template<typename Type> class Queue{ //... }; int main(){ Queue<Node> queueNodes; } [/code] If not then post some code so it will be more clearer. | |
Re: First use arrays : Do something like this : [code]struct Poles{ Poles poles[8]; }; [/code] Next, your question : >>[B]I want to make a function which would use correct pole(pole1, pole2...pole8) depending on parametres[/B] I am not exactly sure what you mean, so before I give you a answer, you … | |
Re: Well this is essentially a transversal problem. You need to verify that the left child of the parent is less than, and the right child of the parent has to be greater than the parent. So essentially you will have to transverse the whole binary tree. Whats the usual transversal, … | |
Re: Real Numbers are uncountable, so you can't list all of the numbers. A proof for this is usually, done by the [URL="http://en.wikipedia.org/wiki/Cantor's_diagonal_argument"]Cantor's_diagonal_argument[/URL]. | |
![]() | Re: Change your pre-processors to this : [code] #include <fstream> #include <string> using namespace std; [/code] The main thing you forgot was the using namespace std, in your code. |
| |
Re: Thats because you are doing int arithmatic. Basically : 130/3 = 43 130.0/3.0 = 43.333333... So to solve your problem, and to be safe, put a .0 at the end of each numbers. So in total it will look like this : [code] average = float(100.0-((25.0/(130.0-(50.0-(130.0/3.0))))*100.0) ); [/code] The float(...) … | |
Re: >> I am trying to move a player in direction angle by speed I am kind of hesitant of what you mean exactly by that, can you explain? | |
Re: Trace it out. 1) [code] //returns 2 times the number passed in def T2(x): return x * 2 [/code] 2) [code] //return T2(12) = 12*2 = 24 def dozen(): return T2('12') [/code] 3) [code] //returns T2(3) = 2*3 = 6 def enestrate(): return T2(3) [/code] now this call : [code] … | |
Re: Yes its permitted. 1st of all why do you need to use it? Second, the syntax gets pretty tricky. Here is an example : [code] #include <iostream> using namespace std; struct Foo{ int x; int y; void print(){ cout << "(" << x << "," << y << ")" << … | |
Re: Simulating the heart or something medical? A graphical tour of your school ? Google? | |
Re: what you are looking for are more along the lines of this : [code] void populateUniqueRandom(int Array[], const int size, int start, int end){ assert(end-start == size); //make sure the size the correct size for(int i = 0; i < size; ++i){ Array[i] = end - start + i; } … | |
Re: If you are on windows, then you can use [URL="http://msdn.microsoft.com/en-us/library/aa909766.aspx"] PlaySound [/URL]. If not then there might be something similar to your OS. If all fails, you will have to use a 3rd party library. | |
Re: Another thing to add, I feel like you have a lot of redundant coding. For example, you can implement the operator -() in terms of the operator +(), instead of providing a definition for each one. Did you feel like you have copied and pasted a lot of code? | |
Re: When you say it crashes, when does it crash? Do you know at what line? Also the cipher you are doing is called ceaser shift cipher. If you would like to wrap a encoded char to be within 32-126, then use the modulus operator, although your method looks like it … | |
Re: >>I'm attempting to make it register when i move a sphere beyond it's x,y,z position. I am confused by this statement. Can you clarify a what you mean? Also can you clarify what exactly your problem is. Sorry I couldn't understand what you were trying to say. | |
Re: Past the TVector.h and TVector.cpp here. | |
Re: You will have to work with the graphical window, because once you exit the sdl window, it automatically closes the console window as well. You might be able to get around this by using win32 but thats another language you will have to learn. | |
Re: No you use what someone geniuses already have written for you. It will be pretty hard to create your own graphics command, that does not encapsulates other's functions. I would suggest to start with SDL. [URL="http://lazyfoo.net/SDL_tutorials/index.php"]This[/URL] link will be a good start. | |
Re: Just an idea, since the array is ordered. Consider comparing the mid of the array. If the number X is greater than the mid, then compare the mid of the top half. Keep this pattern. As soon as you have failed 2 greater than comparison, then start with the subList … | |
Re: >>i have this rectangle and i want to be able to rotate this shape around another when i press a key. By default the rectangle rotates around the origin. So if you wan't the rectangle to rotate around an object, then translate the world x units until the object to … | |
Re: [QUOTE=LostnC;1188160]Hello everyone, I am trying to understand composition versus inheritance in C++. I have looked at many web pages, but I haven't found anything that makes sense to me. Can someone please tell me where I can find some examples of programs that might make sense to me? I am … |
The End.