565 Posted Topics
Re: Well what is the recycling system? If you post some/all of that we can see what we can suggest. If you post your attempt then normally this forum will suggest what they think is would improve it. A few iterations later you will then have really nice code.... Don't forget … | |
Re: How is anyone suppost to GUESS what is wrong with that ?? There is no definition for Intstack but a cryptic comment about what is private/public. Beginners using #define macros/parameters are heading for a (100-epsilon)% certainty of having incomprehensible bugs. Use const int or a function. There are no declarations. … | |
Re: Any online reference to priority_queue [URL="http://www.cplusplus.com/reference/stl/priority_queue/"]http://www.cplusplus.com/reference/stl/priority_queue/[/URL] and the include show that the class takes a templated less functor and a default typebase. So: (without using default template parameters we have): [code=c++] #include <iostream> #include <vector> #include <queue> int main () { std::priority_queue<int,std::vector<int>,std::less<int> > pqA; std::priority_queue<int,std::vector<int>,std::greater<int> > pqB; pqA.push(30); pqB.push(30); pqA.push(100); … | |
Re: There are three ways to do this: (a) use the printf style [code=c++] // Note thist must have at least one fixed argument: void foo(int flag,...) { va_list ap; va_start(ap, flag); if (flag) { char* s = va_arg(ap, char *); double d=va_arg(ap,double); std::cout<<"s == "<<s<<" "<<d<<std::endl; va_end(ap); } return; } … | |
Re: Additionally, to the errors above: Errors on initialization. [code=c++] bool solved; int i,j; if (solved) // ERROR: Un-initialized variable { return; } [/code] You have a faliure to limit range on line [code=c++] // Find next empty value for (i=0; i!=9; i++) { for (j=0; j!=9; j++) { if (rows[i][j] … | |
Re: The problem with that line is not that it is in not in function but this: You have defined [code=c++] template <class T> ostream& operator<<(ostream& out, Matrix<T>& m) { m.output(out); return out; } [/code] BUT you need to use it in a context that requires const Matrix& since you are … | |
Re: First of all play with pointers until you REALLY understand, if you are doing sufficient C++/Computer science failure to understand pointers, dereferencing etc. is going to leave you in tonnes of trouble. [The advantage of being old, is that we had to grok pointers, in assembly aged 10 (to crack … | |
Re: I thinks you just need to add { } round the loop part. You add up count each time but then only output n at the end. If you output n for each step of the loop you will get exactly what you want. | |
Re: Probabily not what you want -- But why not have an object class that holds the strings and whatever else you need. Then have each of the classes C+Element as you have except that Element has a pointer to the container class. [version of the handle class -- see Ruminations … | |
Re: Let us start with this: [code=cplusplus] void rightRotate(int *y, int n) { int temp ; for (int i = 1; i<= n, i++) { temp = y[i]; y[i] = y[n-i+1]; y[n-i+1] = temp; } } [/code] I am 100% certain you have absolutely no idea what this does. First is … | |
Re: If you need sqrt of a matrix you are going to need serious heavy duty numerical/symbolic matrix code. If it is numeric then use uBlas. [URL="http://www.boost.org/doc/libs/1_37_0/libs/numeric/ublas/doc/matrix.htm"]http://www.boost.org/doc/libs/1_37_0/libs/numeric/ublas/doc/matrix.htm[/URL] There are simpler forms that probabily are ok, you can always get it by taking a SVD of the matrix but is often non-optimal. … | |
Re: [B]Please note that the code you have is 99% wrong.[/B] Consider [code=c++] Polynominal A; A=A; [/code] And before you say you would never do that, be very very careful of compiler opimization, double loops that i=j (e.g. [icode]for(int i=0;i<N;i++) for(int j=0;j<N;j++)[/icode] and many other places. You should write FOR EVERY … | |
Re: That is no fun comatose!!!! The program should write itself without reference to the source code!!! You want to look up quine e.g.[URL="http://prokutfaq.byethost15.com/Cquine"]http://prokutfaq.byethost15.com/Cquine[/URL] I distinctly remember the first time I saw a quine program,. fortran-77 -- I am getting old :) -- and I was very happy when I finally … | |
Re: First, well spotted nucleon for the additional semi-colons But there are other horrible errors here. First off I am surprised that you don't ask about the doubled/redoubled status, it affects scoring greatly. Second, you should use any of the editors that lay out the code/or do it by hand AND … | |
Re: Well first off, I accept that you didn't get any replies at the previous forum, so I will accept that you should re-post. (I might have waited another day or so but that is minor). Given that, I would like to comment on your problem, and actually ask a few … | |
Re: You are aware that tan(90) [in degree] is infinity, and obviously, so is tan(pi/2) [in radians] as pi/2 radians == 90degrees. That is easy to see if you consider that tan is the ration of the length of the two shorter sides on a right angled triangle. Ie by the … | |
Re: Just in passing: [B]First[/B] [icode]return array[counter],counter;[/icode] is an awful way to say [icode]return counter[/icode]. The code does not return array[counter] in anyway. [B]Second[/B] If I were to enter 100 as the number of numbers. then your code would break since the array is only 70 big. [B]Third[/B] I think that … | |
Re: I am not sure the problem is actually faulty, but you have figured out templates so the problem is far too simplistic. The problem seems to be based on the type of return and the problem that you have to specify the return type. i.e. your code does not compile … | |
Re: You have a problem at the last line of your input file. You read [ICODE]while(partin >> charInput >> numInput)[/ICODE] and you have just = on the last line so it reads into charInput and then waits and waits..... You need to read the char and then the number, and check … | |
Re: Additional to death_oclock, you will need to pass comments and string literals. Since,[ICODE] /* {{ */[/ICODE] and [ICODE]"Some brackets {{{{"[/ICODE] and [ICODE]'{'[/ICODE] are do not need to be in the counter. Other than that you need to check that you don't go below zero. i.e. [code=c++] int main() { //stuff … | |
Re: Returning to the problem asked: The problem is that you have created a class that does nothing. If you take the trouble to create a class don't ignore the values. You can put tar=100000; and it will make ABSOLUTE NO difference to the code. I think you have confused yourself … | |
Re: The horrible hack can be cut by a lot, [icode]printf("%s%",iter->c_str());[/icode] Still it is a bit ugly, but boost::format and alike solve the obvious problems with iostream, and I agree, don't use printf unless you absolutely have to [mainly because it has runtime type problems] | |
Re: Ok the usual rant: I hate system("PAUSE") and CLS. They are non-portable, and I can clear my own screen if that is what I want! Beyond that you haven't given us much to go on. You don't test if displayData2 is successful? Does "userInformation.database.txt" exist / get opened, have Windows … | |
Re: Well there is little to go on here, but.... Consider this, your cat moves from say 100 to 0., then..... you have written [ICODE]cat.x -= cat.movex;[/ICODE] which works fine until cat.x==0. Then you write [ICODE]cat2.x += cat2.movex;[/ICODE] Fine now consider the sequence if say movex=5; 100,95...5,0,5,0,5,0.. That is because you … | |
Re: well you seem to under count a little bit. I personnally like to consider all comparisons. For example: [icode]while(j>0 && temp<list[j-1])[/icode] That is definately 2 comparisons. And [ICODE]for(int i=1;i<N;i++)[/ICODE] is definately one each time. Effectively you have under counted a lot of times. BUT note that if you fill this … | |
Re: Help!!!!!! -- This is awful / Where to start!! Ok consider this: 999*999 is 998001 So count down from that number. Then if you find a palindrom then find the lowest factor. (simple loop works). - - Divide the number by that factor and repeat. You will need to keep … | |
Re: Let me just check, I am seeing goto in a program that you want to submit for marking. The only time I have ever seen that was a stunningly bright student in an advanced class showing how scheme could be used to optimize a mathematical C++ program -- and he … | |
Re: If you have a number to add use this [icode] sum=sum+a; [/icode] or [icode]sum+=a;[/icode] Both do the same thing of adding the value a to the value sum. you will need to expand you if to only add to sum if a is a factor you can use this construct … | |
Re: I think that the problem is not the code, but your maths. Let us start with a number, e.g 89 as use used. What does writing 89 actually mean: that there are 8*10 + 9. If you write in base 4 , say 31, you are saying that you have … | |
Re: code integration: Have a long look at swig [URL="http://www.swig.org"]http://www.swig.org[/URL]. I think it is excellent, and have used it with python and lua, and have been very pleased how easy it was. | |
Re: Please be [B]VERY CAREFUL [/B]with this code. Consider [code=c++] // THIS IS VERY VERY WRONG!!!! char * getName(){ char buf[YOUR_ARRAY_SIZE]; sprintf(buf,name); return &buf[0]; } [/code] The code above is a runtime error, the problem is the you have a local variable (buf) and that goes out of scope at the … | |
Re: I am not certain this is the best way but it seems to work. Note that the disk buffer is also an issue. [code=c++] ofstream Out("File.log"); // stuff Out.flush(); // Necessary since you need to ensure that the // data ends up in the buffer. // Some versions of stdlib … | |
Re: I don't agree. I think that they have a place in modern code. I have a few situtation that I think merit them. (as will all good things, go easy on them, even in my biggest code bases, there may only be 10 of them). Let us consider a function … | |
Re: You can get 99% of what you want (if I understand correctly) You declare a global variable, say outputFlag (or put it in a namespace when doing it properly) and have the function check that. Ugly but gets the job done. Also have a wrapper function (which takes the flag) … | |
Re: I would like to politely disagree. I think that the isdigit is a distraction. First problem is simple: if you write THIS: [ICODE]cin>>digits[/ICODE] then you enter 23d you will get a success with 23 in digits and a very difficult time finding out that you entered 23d. You first want … | |
Re: The real issues are all in #include "DbConfig.h", however, without any includes in TestClass, it will not compile. Can you post DbConfig.h and we can have a look and maybe solve your problem. (also TestClass.h if it exists) | |
Re: well this is the c++ forum, and the reality is that you are going to want a perl/python/ruby/other scripting language. C++ can do it but you are going to write a lot of code to do that. C++ wins out when you have numerics, system level, memory issues, and often … | |
Re: As MosaicFuneral points out, the compiler can do thousands of things. BUT the best way to find out is to examing the machine code. Then we learn the following: The key error in the test code is that you use da/db regardless of the change to the line [ICODE]if (ba==bc)[/ICODE]. … | |
Re: Please do us all a favour and don't double post on multiple forums E.g. [URL="http://www.codeguru.com/forum/showthread.php?threadid=469551"]http://www.codeguru.com/forum/showthread.php?threadid=469551[/URL] You were shown short shrift there, because you code is absolutely awful, and you didn't follow their forum rules either. In addition you didn't take the time to read ANY of this forums rules. Putting … | |
Re: Error on conversion: Sorry classic error: [code=c++] int a=9; int b=5; // this gives 1 std::cout<<"Int division "<<a/b<<std::end; [/code] The code you have written gives the error because of 9/5 == 1. If you write 9.0/5.0 or even 9*(temp-32)/5 you would have the correct answer. [p.s. Sorry Salem was quicker … | |
Re: By the looks of things (I am guessing a bit -- but there is very little code to go on) , you have a rectangle of with top/bottom cordinates. Then you add 1 to top and bottom but if you reach the bottom of the screen the bottom only is … | |
Re: This a mess, and the main reason is that you have tried to do WAY to much in one go. So, you really really need to start again. I can assure you that it will help. Open a clean editor window and start again. The problems of your code are … | |
Re: Assuming that the FIRST warning/error from g++ is [QUOTE]./../frontends/include/../../frontends/include/../../libdatastore/include/../../libtimetable/include/../../libtimetable/include/Course.h:26: error: ISO C++ forbids declaration of ‘list’ with no type[/QUOTE] Then you error is going to be that from gcc-4.0 and onwards, namespace std is not included in the files like list etc. ie. You write this [code=c++] #include <list> class … | |
Re: Let us see what we can do if we think about the algorithm. Let us start with a brute force algorithm. There are 9! ways to rearrange that 3x3 matrix (362880). BUT there are an infinite number of paths to go between any two matrix configurations. So the SIMPLISTIC brute … | |
Re: Ok first off please take a little more care with the code tags, but I can see you just made a mistake so no problem. Second you open a fstream BUT write to std::cout... Then next you can use fstream BUT if it is for output it needs the std::ios::out … | |
Re: I was the original person who suggested using a sieve of eratosthenes. Now does this still hold? I believe so and here is why. You were required to find the factors. The only factors of importance are prime factors, all other factors will be bigger since they are a combination … | |
Re: Ok, three points : Using pointer is required since you can't copy a filestream. That is because it is tied to resource. Yes, you can use pointers. Yes it is ugly. Note that if you want to write the same stuff to a bunch of files then it is probabily … | |
Re: They are both slightly wrong. You are correct that if you delete everything from the vector, you have a vector of dead pointers. Obviously, a simple animatins.clear() would solve that (after the loop). The second form does not call delete on the pointer. Why not this: [code=c++] std::vector<Animation*>::iterator vecIter; for(vecIter=animations_.begin();vecIter!=animations_.end();vecIter++) … | |
Re: there are many horrible errors here: The first that will take you a while to see (and most modern compilers would have flagged as a serious warning) is that you have [icode]while(done=true)[/icode] I am sure that you wanted [icode]while(done==true)[/icode] since the first while loop is ALWAYS true. Interestingly you define … | |
Re: 95% of the time this is wrong. The reasons are: (a) classes with a virtual function you will get the wrong size (too big). (b) classes that inherrit from a base class include the size of the base class but the pointer MIGHT NOT to point to the base class … |
The End.