565 Posted Topics
Re: First off I assume you are taking a course and haven't covered arrays. Otherwize please use [icode]int num[10];[/icode] and a for loop. But that is how to write this problem in 10 lines. It doesn't make you code incorrect. What you have done wrong is use the comma separator between … | |
Re: Ok I have to compile for "target" machines that I don't have access to now and again [The horrible world of the hetrogenious grid :( ]. The first thing is to ensure that you produce a 100% static link. use gcc -static which will cause errors if you try to … | |
Re: hi You have made a small error with your makefile. I think it is because you have mis-understood what is going on. First off I have written <tab> to mean a real tab but it would not be clear if I had used one. The lines of a makefile are … | |
Re: Nor sure what you are trying to do here. I would like to see logbook.h and logbook.cpp please. | |
Re: The obvious stuff is wrong : use of [icode]'\n'[/icode] rather than std::endl. the complete lack of tests for input values. e.g Would this be wrong [code=c++] IntStack stack(-40); [/code] so that is why you have a problem with [icode]IntStack stack(0)[/icode] since you initialize [icode] p=new int[0]; [/icode] and then things … | |
Re: CPPRULZ: I often require that the program says 16.0f 16L or some such thing. There are three reasons: (a) to be clear about what sort of number is being used. (b) to avoid implicit conversions, (c) to help control/understand/document roundoff error. (a) Often comes about in cases when we have … | |
Re: This is a problem that requires thought NOT code. The answer can be easily found on a piece of paper. So without giving you the whole solution try thinking about this Obviously 20! (20x19x...1) is a solution but it is not the minimum. Now you have two types of numbers … | |
Re: you have more problems in the assignment constructor. [in addition to horrible code repeat!] e.g. [code=c++] m_length=strlen(other.m_buffer) + 1; m_buffer = new char[m_length]; strcpy(m_buffer,other.m_buffer); [/code] Now consider what happens if other.m_buffer is a null pointer. That is a seg fault. | |
Re: Ok without a lot more of this program I am guessing. BUT it is obvious that many things need to be fixed. (a) The start? [icode]const int len=arraySize;[/icode] you don't change arraySize until the last line ? so why len? (b) The first while loop [CHECK for i>=number of savings]: … | |
Re: Sorry I am not sure that boost has anything that you really want. [I can always be wrong about boost it is HUGE] But the Gnu scientific library, has the structure for coordinate transforms (all the matrix stuff + differentuals). And the octave library, (which needs a little care to … | |
Re: The worst error here is the lack of virtual destructor. The WRONG destructor is called. Regardless of you writing you own or letting the compiler write it. Doesn't matter. So you should have [code=c++] class customer { public: customer(string N, int c); // << -- Added virtual ~customer(); // << … | |
Re: Without a bit more code this isn't going to be easy. I would guess that the error is two different Color classe. It is very common in things. I will add I would start by using std::map<> etc, and not using [icode]using namespace std;[/icode] The use of List and Map … | |
Re: This is the worst assignment I have ever seen. The series is the Geogory-Leibniz series. It is one of the slowest convergent series for pi. You need about to sum 300 terms to get 3.14 accurately, to get 10 digits you need about 10 billion terms and to get to … | |
Re: Your code is slightly ugly since you have two levels of derefrence and that can slow down understanding. There are several methods that can be used. But what about using a policy class [code=c++] class Conv1 { public: static const int data[]; }; class Conv2 { // same declaration but … | |
Re: Before you get strangled with compiler errors. Please note that in c++ you write [icode]public:[/icode] Then all things below are public (until either the end of the class or one of [icode]private:[/icode] or [icode]protected:[/icode] The reason I am flagging THIS error up, is that the compilation error you generate is … | |
Re: Coming back to the original post. (sorry). I think it is a level of depth. For Java, yes you do GUI/ graphics from a previously written library. For the c++ you are seeing a deeper part of computer programming, i.e. the lower level, the bit that builds the library. If … | |
Re: Try [icode]CC = g++[/icode] and [icode]CFLAGS = -Wall -g[/icode] BUT once you have changed them is it 100% essentual to do a [icode]make clean[/icode] before your [icode]make all[/icode]. Otherwise you will fail to implement the change. | |
Re: Please don't use rand() for anything but test applications. This is especially true if you have strong consequences for short sequences of very high/very low random numbers. Additionally, if you need randomness immediately, for the first few numbers, then don't use rand(). [Especially since most people random number seeds are … | |
Re: Basically, there are two scales in the problem based on the initial conditions. The first is that the planet and the start are going to orbit each other. The second is that the planet is going to escape on a hyperbolic or parabolic orbit. You can test the possiblity of … | |
Re: Acutally this is a "classic" interview question. (Which I have never used/heard). You start with two pointers, you advance one two time, and the other one time. If you go past the end, you set it to the first item. If the two pointers match at any time before the … | |
Re: Just to be clear. The problem is that you have allocated an array as [icode]user users[2];[/icode]. This gives you two user objects. They can be referenced as users[0] and users[1]. When you start doing [icode]users[2].logonName;[/icode] etc, you have corrupted the memory of your program and what happens next is pure … | |
Re: The first thing you have to correct is the [icode]class englishwieght::getnumber() [/icode] etc in your def.h file. It should be a .cpp file and you need float englishweight::getnumber() etc. Not class. Note that by spelling it [icode]wieght[/icode] and not as you spelt it in the first part of the program … | |
Re: This isn't something simple, i.e. that you output nothing in what() and then you are double throwing the exception. You are always going to get [quote]terminate called after throwing an instance of 'std::exception' what(): std::exception[/quote] with this code, it is just a question of what you are going to get … | |
Re: Ok Let me try to get some order: You have a line [icode]class2 ** PointerClass2;[/icode] Now that means effectively that you have a set of pointers that point to arrays of objects of type class2. The use of class2 is irrelevant to the problem ( I think). Now then you … | |
Re: Sorry I am going to be harsh. This is by far and away the worst prime factor sort that I have EVER EVER seen. Do not code until you have considered the maths. Consider a number[TEX] N[/TEX]. (which is a positive integer) First if a number has a prime factor, … | |
Re: Let me see now your first post you were told that we don't help with assignments unless effort is shown. THIS post you decide to ignore that reality and persist in asking [I]please do my assignment for me[/I]. The ONLY way you are going to get help is to actually … | |
Re: First off the error that you have made is that in C++ void print(char*); void print(); are two different functions/methods. Thus you HAVE NOT defined a print() method in class IVM. You defined some weird function called `void print(IVP* iv)` and that is not `void print()` That is why the … | |
Re: The short answer is yes, BUT it does [B]not do[/B] the obvious thing. Let me explain a bit. It is the same as: (assumes that matrix[][] is of type char.) [code=c++] bool X= (matrix[1][1]==matrix[2][2]); bool Ans = (matrix[0][0] == static_cast<char>(X)) [/code] Note that it is VERY unlikely that is what … | |
Re: I think that vector methods, cross/dot product etc. Polynomial intersections (Bezout matrix methods etc) for 3d-surface-3d-surface intersections rate as minimally essential. Trigonometry is just a given. If you can't handle basic quaternions and vectors don't even think about 3d games. There are all the specialist discrete numerics stuff for approximations … | |
Re: Hi Well, I am not going to comment on the purpose of the code. It does make me very very glad I don't use windows for anything (including work). So things that I would pick you up on if you worked for me. [I am a bit picky but that … | |
Re: Your real problem is either (a) the resolution of your clock. (b) that the insertion runs in a different thread. You are likely to find that CLK_TCK is a very big number. i.e there are very very few CLK_TCK per second. On my computer there are only 200 per second. … | |
Re: The question should be asked "how do I delete a pointer if I allocate the memory using xxxx?" Let us review: if you write double* Ptr=new double[50]; // Allocate space for 50 double s // ... other code delete [] Ptr; // Delete the pointer to 50 doubles // CARE: … | |
Re: I wish to (a) reinforce Chris's comment you have posted 18 and should have figured that out. Use the advanced button and enclose you code. Use the # button. Solution to the problem is that you missed out a : on the definition line properties [B]General Note:[/B] I believe that … | |
Re: As cikara pointed out, you are incorrectly using [icode]trys!=b[/icode] and that is going to get you into a mess. I would (a) suggest that you use a count of the zeros to decide if you have succeeded. (b) Have a look at your algorithm. (c) check the rules of since … | |
Re: [QUOTE=ArkM;769539]It seems you like adventures:[/quote] The rabbit hole can get deeper :) [code=c++] template<typename T> T convert(const std::string& SRef) { T x; std::istringstream ostr(SRef); ostr>>x; return x; } template<typename T> struct Type { Type() {} // THIS DOES not set types that don't have default constructor Type(T n):value(n){} operator T&() … | |
Re: The problem here is that g++ knows that only 64 bit can effectively be handled at the processor level. So the authors/steering committee have decided that if long int (which is 8 bytes long) is insufficient then you should be using the gmp (gnu multiple precision library). Since this is … | |
Re: Your problem is the overloading of the instance of number. Let me illustrate. [code=c++] int num=6; { int num; // This num is not the same as above num=7; } // In this scope cout<<"num =="<<num; [/code] In your case you have put [icode]void definenum(int num) {} [/icode] and this … | |
Re: Hi, If you are doing cards for any general card game, which makes use of suit, then you will benefit greatly from using a 64 bit card system. Then each bit refers to one card (with three left over). That way in instances where suit doesn't matter it is easy … | |
Re: Looks like you are coping the pointer BUT not coping the array. [This is often called weak-copy]. What happens is the memory for array1 is overwritten with something else and you have a copy of the memory location. You need something like this [code=c++] void sceneObject::setPositionMatrix(float* nPositionMatrix) { if (!positionMatrix) … | |
Re: Hi k59, Sorry, I understand that google can be used but these are the practice problems on daniweb's C++ forum. So I feel an answer should be forthcoming! -- i.e. they are not homework questions! So this is what the questions ask and what I think you will learn from … | |
Re: [QUOTE=spanigrahi_situ;754818]Added to that ,my doubt is if we created a general template lets say for swap two value.In the main of that we created objects of in t type,float type.Will compiler treat both in compiler side implementation?[/QUOTE] The answer to your question is yet unless you tell it to do … | |
Re: So what is your question ?? What is a loop?? A loop is a group of statements that get called multiple times e.g. [code=c++] for(int i=0;i<10;i++) { // statements here } [/code] which calls the statements 10 times or [code=c++] while(x>18) { // Statements here } [/code] which calls the … | |
Re: What you have clearly doesn't work: Consider insertBack, you do not set first. It can be anything! IF you had set first then conversion is easy. [code=c++] newNode->link=first; [/code] Now consider deleteFront, I do not understand what you are doing checking first->info (and what would happen if first was zero!) … | |
Re: The function nCr should not be calculated using direct factorials. Very often nCr is within the MAXINT range BUT the factorials are not. You should use the property of the factorials. An initial optimization is to divide on the n/2 decision e.g. [code=c++] long int nCr(const int n,const int r) … | |
Re: Quick comment: Top can show the total memory (although it actually sorts on CPU until you set the options ) pmap PID Shows the total memory, including a breakdown of stack/heap memory and all the shared libraries used. [PID :: process id (use ps to find it) It is a … | |
Re: Try replacing the whole while loop stuff with this. [code=c++] std::cout<<std::string((people+500)/1000,'*')<<std::endl; [/code] If you don't want to use the string constructor then try... [code=c++] for(int i=(people+500)/1000;i;i--) std::cout<<'*'; std::cout<<std::endl; [/code] | |
Re: Assuming all the other definitions are correct (e.g. defined MAX, friends etc) The first/second problem is that tempZ is defined as an single int, and therefore is not an array. you will need to create it as an array e.g [icode]char tempZ[a];[/icode] to get that line to compile. I am … | |
Re: Just commenting you can chain them together but you need: [icode]if (game[1]&game[2]&game[3])==play)[/icode] BUT you get away with this because the possible values of game[] are 0,1,2. The above logic will fail if you are not using powers of 2 as the flag values. Normally, the shorthand version I have written, … | |
Re: You haven't looked at the messages at the top of the forum. You haven't looked at google. You haven't actually done any reading. You haven't read the forum rules. Therefore: I haven't decided to post any examples/links or other help until you show some effort. |
The End.