- 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
565 Posted Topics
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, … | |
Re: Hi, [icode]operator++(int)[/icode] and [ICODE]operator++()[/ICODE] are the post and pre increment signatures respectively. Note that the (int) in the post-increment does not get assigned or used i.e. you might write [code=c++] class A { public: A& operator++(int) { // do stuff here; return *this; } }; [/code] Note: You do not … | |
Re: The problem with this code is firstly that it just doesn't work, but much more problematic it shows some little mis-understandings in the basics of type conversion. First of consider types: By this I mean the storage for a variable or constant. Examples are int (an integer type), or double … | |
Re: Sorry but you have steped into one of those nasty legacy areas from C. There exists a function [in stdlilb.h which is included via cstdlib] `long int random()`. Thus the first of your errors. To avoid this either (a) rename your functions e.g. random100 or something (b) give it an … | |
![]() | Re: [QUOTE=;][/QUOTE] First off I commend you for investigating what I think is one of the most difficult classes to write. As always with a polynomial class, it is a case of compromises, and further improvements as scope and efficiency are improved. There are a few aspects that I think the … |
Re: I think the code should have been : if (size==next_element) { // THIS Function doesn't work yet p_values= growArray(p_values,size); } p_values[ next_element++ ] = val But then you will have to fix growArray that also doesn't work. I will leave that for you to figure out. | |
Re: The obvious uses are all around -- I will list a few: Control room of a complex system (e.g. a nuclear reactor). In a typcially control room, you want the imformation that matters to be salient. That doesn't just include alarms but information that leads up to an alarm, e.g. … | |
Re: Memory leaks in C++ are about balance and understanding scope [a bit]. First of the fundermentals: for every allocation there must be an equal deallocation. That is about it. Consider your example: void afunction(int *x) { // Memory allocation BUT no deallocation x=new int; *x=12; } int main() { // … | |
Re: Ok -- it compiles and that is great! Well done... However, that is were the good stuff stops [Sorry] I am not going to post a working and viable solution. But I am going to point out some of the problems that are leading to segmentation faults/undefined behaviour, and things … | |
Re: There really is not enough to go on here. sorry. But here is my memory error check list: (a) Have you zeroed the pointer before trying to free it e.g. CvPoint* PointArray=new PointArray[10]; // stuff PoinitArray=0; delete [] PointArray; (b) are you mixing C++ and C style memory allocations e.g. … | |
Re: It is just that you have left a trailling `'\n'` in the input stream. You can tidy that up with code like this: for (int i=0; i<MAXSTUDENT; i++) { s1[i].enterDetails(); std::cout<<"Enter number of modules:" ; std::cin>> x; for(row=0;row<x;row++) { std::cout << " Enter module code and marks :" <<(row+1)<<" "; … | |
Re: Your problem is one or two things: (a) the line STOP in your input only has 11 characters in it. (b) You don't check the input size in your code before cutting. If you put this in your code : `operand = (opCode.size()>12) ? opCode.substr(13,6) : "";` the code runs … | |
Re: However as well as that problem, which you can solve as suggested above. You will find that value is constant for long period of the loop. That is because you have done int t = n/freq; value[n] = amp*sin(2*pi*freq*t); n is an integer and freq is an integer, and using … | |
Re: Ok there is lots and lots of little problems with this code. But before I talk about some of them, I don't understand your use of the word iterator. In C++, the standard template library provides iterators to most container classes. In your instance you are providing a container class … | |
Re: The first error is that you have a single collon (:) and then the word Rainful [line 14]. After that without Rainfall.h is would take me too much time to guess what you are doing. So please post that file. | |
Re: There are a number of issure with various aspects of this coe: `int GetGuess()`, I assume is there to return the number of guesses that the player took to get the correct number. However, you use the variable guesses twice. This a scoping issue. First, there is the variable `guesses` … | |
Re: You logic is flawed because you put == instead of >= . Consider the lines 15 -19 . while (num ==900) { cout <<"CM"; num = num - 900; } Now if number is 901, that isnt going to be executed, so you want to change the == to >= … | |
Re: You error seems to be in the copy constructor/assignment operator of way. If you add : Way::Way(const Way& orig) : id(orig.id),name(orig.name) {} Way& Way::operator=(const Way& A) { if (this!=&A) { id=A.id; name=A.id; } return A; } All works as I would expect. [Note you also have to add a declaration … | |
Re: Ok this is a standard top-tail queue. Let us walk through the process of putting objects into the queue and taking them off again to see how it works: The important variabes are front/back. **Empty Case** Let us first conside the test case that you build an empty queue: `front=back=0`, … | |
Re: ok -- you start with some input and checking -- kind of ok -- Note that you have not checked if the user inputs that he wants 50 numbers... you program would break. After than finding the min positive value: That is a bit of a mess of logic/coding etc. … | |
Re: There are several issues with this program that will result in problems. First off the cause of the error is likely to be the lines: cin >> end; bool arr[end]; You just can't do that in standard C++. The array is sized at compile time not runtime. [I know several … |
The End.