- Strength to Increase Rep
- +11
- Strength to Decrease Rep
- -2
- Upvotes Received
- 171
- Posts with Upvotes
- 145
- Upvoting Members
- 100
- Downvotes Received
- 1
- Posts with Downvotes
- 1
- Downvoting Members
- 1
Re: You still have a couple of design issues (bugs). In particular look at the value n. It is suppose to be the number of data items added, but actually you set it in the constructor, why not increase it each time that you add some data, and set it to … | |
Re: Your problem is assuming that x1 and x2 are integers when you print them out. Additionally, a,b,c are all likely to be floating point numbers. So read them in as floats. So make your output statement [icode]printf("%g and %g\n",x1,x2);[/icode] Also you can use the sqrt function in line [icode]k=sqrt(d);[/icode]. HOWEVER: … | |
Re: I would worry about line 31 : f`or (int I = 10; I >= 0; I--)` When you read in the data for (int I = 1; I <= 10; I++) { cout << I << ")"; cin >> N[I]; cout << "\n"; } You populate the value N[1], N[2]... … | |
Re: This method seems strange to me . The first thing that is obviously wrong is these lines: while((*bIter)<(*aIter)){ bIter++; } What happens if bIter is at the last position in the array. So in short I would have written something like this std::vector<int>::const_iterator aIter=aList.begin(); std::vector<int>::const_iterator bIter=bList.begin(); if (bIter==bList.end()) return 0; … | |
Re: Doesn't matter which method you use -- pointers and new (remembering the delete when you have finished with the array) is perfectly fine, however, so is declaring three arrays of size 20 and filling only the first part of each. Note you need to check the user input isn't bigger … | |
Re: Tiny typo -- Line 38 : `s.setval(5.1,0);` Should have been` s1.setval(5.1,0);` There are ways round this kind of error (scoping the two test etc) but in reality better naming is more important. I hate any name that can be confused with another name by one character missing/changed etc. However I … | |
Re: I agree a bit with rproffitt, but without actually running the code I noticed the following: line 51 : `elements[x++]= M[i][j];` x is not initialized. Might and might not start as 0. line 64 `elements[k] = elements[k+1];` In the first parse if elements[i] == elements [j] then this line sets … | |
Re: There are many many things wrong with this. Let us start with MergeSort. Ok explain [code=c++] int k = 1; for ( i=0;i<k;i++) { q = q->next; } [/code] Ok we have (A) a global variable as a loop index !! (B) a loop that never does anything more than … | |
Re: The problem here is ownership and responsibility. The aggregate class would normally take ownership of the object being passed to it. [Sometimes that aggregate class would build the object via a factory object -- but let us keep this simple]. So in words this is what I think you want … | |
Re: Your code is nearly correct but I am not 100% sure that it is giving your what your want: So here is your code with some comments -- just to make sure: // This line sets the random number seed. // you only need this call once only in your … | |
Re: I think the fatal error says everything [B]Disc quota exceeded[/B] I think it is time to talk very nicely to the system admin. or delete that large cache of movies.... ;) | |
Re: You seem to be asking a lot of questions about developing a C++ 3D geometry system of some sort. I think it would be a lot better to show us the framework you have built, and the problem domain. For example, the answer to this questions needs us to understand … | |
Re: Sorry but I really don't like this piece of code from skaa. The problem for me is that double precision numbers have floating point error, so you really don't know [most of the time] if they are going to be equal e.g. is 1e-76 equal to 1.1e-76. This kind of … | |
Re: The chances are that your error is actually the accuracy of the return value from the dot product. With floating point calculations you often get a little bit of an error, so you might be returing -1.0000000001 from your vector dot product. The quickest way to check that is to … | |
Re: The problem here is (a) the typo error with write `*num1= num2;` rather than `*num1=*num2;` (which doesn't actually affect the problem). And (b) what you are defining by const. Let us start by looking at the definition of limit: const int limit=100; That says limit is 100, and the compile … | |
Re: NullPtr is 100% correct -- just a litle brief I think! Your question is what is wrong with this code. So as was pointed out the error lies in the line temp >> num[i][j]; Let us consider a similar expression: int a=5; int t=2; int x = t >> a; … | |
Re: I am really guessing here because you don't tell us what you expected and what you got. But maybe you got no output -- if that is the case was it because you forgot to put a std::endl in your code e.g. add line 25 : cout<<endl; The algorithm is … | |
Re: Nothing complex just a typo/minor miss-understanding. You wrote this: property <string> caption{std::bind(&tooltip::GetCaption, *this),std::bind(&tooltip::SetCaption, *this, std::placeholders::_1)}; Note the *this , that should be just : this. You are trying to binding a class method pointer to a class instance pointer. If the class instance pointer is no such thing then things … | |
Re: Fundermentally, the loops are highly inefficient. You have the condition that a+b+c == 1000, so why not loop on a and b BUT calcuate c. Second you can limit the loop extent based on the idea that c>b>a. Thus a can never go beyond 333 (1000/3) and b extends from … | |
Re: You have three mistakes: (a) Your output is outside of the loop, you need to output each time that you get a new letter. (b) you don't output the letter just the number. (b) you don't deal with the special case of temp=1, i.e. you don't need to output the … | |
Re: The obvious errors are things like : In [code=c++] int stepOne(Graph &g, ListCell* l, int u) { int lowestVert = l->next->adjVertex; // Seg fault here if l is null double lowestWt = l->next->weight stepOneHelper(g,u); // THIS test is too late. if(l == NULL) { return lowestVert; } [/code] Also [code=c++] … | |
Re: First of all I don't think I can tell you what is wrong to fix your current bug.. but here are a few thoughts, and I think we need to see the calling code for Picture. However, the following might help [hopefully!]. The key elements here are that your default … | |
Re: The principle of this type of hash map is that when two objects have the same key they are stored in the hashmap using a linked list. i.e if you store say 12345 and 23456 at key number 7, then both will be stored at location 7. Now if it … | |
Re: There are several problems with this code : (i) you are using double's which can represent non-integer numbers. The problem with that is if you say `if (a==b) ` but actually a=3.00000000001 and b=3.000000000000000, they are not equal. When you do arithmatic between two numbers you are certain to have … | |
Re: The quick solution to this is to actually know the algorithm that the knights tour works on. It can be shown that for any size square and rectangular board (above a minimum size), that simply selecting the unvisited square with the least possible open moves from it, is the optimal … | |
Re: That is a LOT of if statements for a nice output. Acutally there is a quicker way to do it [ assuming that you don't want to use printf or boost format etc ] #include <iomanip> // other stuff... cout<<setfill('0'); cout<<setw(2)<<hour<":"<<setw(2)<<min<<endl; cout<<setfill(' '); What that does is set the fill … | |
Re: It is unlikely that you really want a switch statement. The problem is basically a set of decision based on two different criteria: age/gender. That ends up as a two state switch statement embedded in another two state switch statement... uck!! What is wrong with float membershipFee; if (age < … | |
Re: I think you have made another mistake: Consider the line of code f.write((char *)&array[i][j],sizeof(array)); Now for your test example you have an array of [3][3], which if we assume you have 4 byte integers: `sizeof(array)` evaluates to 36. Ok so you then take each point on the array in turn … | |
Re: Have you looked to actually see what you have done with memory allocations. It seems that you have the following : rol=(struct roll*)malloc(t1*sizeof(struct roll)); yr=(struct year*)malloc(t2*sizeof(struct year)); mn=(struct month*)malloc(t3*sizeof(struct month)); da=(struct day*)malloc(t4*sizeof(struct day)); But then given that month has the structure : struct month { day* da; }; However, at … | |
Re: Some of the things you will see are that you have looped over the end of your arrays. e.g. line 18 and 36. You have written: double y[21]; // stuff... for(int k=0;k<21;k++) { y[k+3]=-((a1*y[k+2])+(a2*y[k+1])+(a3*y[k]))/a0); } Note that k+3 means that k goes to 24. That will cause memory corruption. Additionally, … |