565 Posted Topics

Member Avatar for hawita

This kind of question is designed to show you that a loop for all the numbers N=1 to N=LOTS [because the answer is big!], is not the way! Even if you got your div function you work, you could easily be spending a long time waiting for it to work. …

Member Avatar for StuXYZ
0
92
Member Avatar for Wakesta

I am going to ask about firstPerson's code here. So first some initial thoughts, first I always like to separate output from function, i.e. don't do logic/maths in the same place as you are telling the user what happens or what is wanted. Especially, as often initially you develop going …

Member Avatar for mrnutty
0
153
Member Avatar for hawita

The obvious approach most Vector3D classes use it to represent the data in one form and convert from input in another form into it (e.g. leave the vector in cartesian for and convert from spherical and cylindrical input). Depending on the problem that is a viable solution [not always]. Then …

Member Avatar for jonsca
-1
121
Member Avatar for Climber Ty

The issue isn't really the coefficient value that you have with the polynomial, it is that you have to realize, that the size of your polynomial will change dramatically, on addition, subtraction etc. Once you have figured out how to handle that, [in particular to remove zeros e.g. (x^2+3x) + …

Member Avatar for Climber Ty
0
477
Member Avatar for toferdagofer

Sorry to say, it is the usual problems. Basically, if you get a problem like this put some std::cout statements in the inner loops that are doing stuff. .e.g in reverseArray. You would find: [icode]for(count=5;count = 0; count--)[/icode] is wrong since I think you intended to write [icode]for(count=5;count != 0; …

Member Avatar for toferdagofer
0
107
Member Avatar for Kase42

First of all, welcome to Daniweb. Thank-you for writing a coherent, well constructed post, with code tags. Your problem in this code [which actually causes the core dump] is that both of the findCoord functions can return an undefined number. Consider your code: [code=c++] int findCoord(std::vector<MazeCoord> &maze, int xarg, int …

Member Avatar for Kase42
0
2K
Member Avatar for sirpampos

First off before you actually code this, you need to think about the maths that is involved. Let us consider it. Using "pen and paper" first, is often the quickest way to write a computer program (and it also gives you all the test cases quickly). Consider the cat is …

Member Avatar for StuXYZ
0
106
Member Avatar for Tamlyn

It is not strange that it runs, however, the problem is that exitMinutes is uninitialized. That means that when the value in exitMinutes is read, it could be ANYTHING. To see how that came about, consider your program. In the main program you write [icode]int exitMinutes;[/icode] which creates a variable …

Member Avatar for Tamlyn
0
151
Member Avatar for jowana

The question is really do you know how to draw stuff in a c++ program and want help with the maths for making a 36 pointed star shape [10 degrees]. Or do you want help writing a C++ program to draw stuff. If it is the maths, then the obvious …

Member Avatar for Stefano Mtangoo
0
199
Member Avatar for pharoah85

Well appart from the strange layout, it works. That is always good. Do note that a*a is the same as pow(a,2). It is also a lot more normal to do the calculations in the double form. E.g. [icode]pow(a,2.0);[/icode]. It is often quicker as well, since the floating point unit is …

Member Avatar for pharoah85
0
217
Member Avatar for BTW8892

You almost have the code for that... You have written: int winnerIndex(int votes[]) { int i; int maximum; maximum = votes[0]; for(i=0; i<5; i++) { if(votes[i] > maximum) maximum = votes[i]; } return maximum; } Now if you add something like this: int winnerIndex(int votes[]) // This function now returns …

Member Avatar for BTW8892
0
1K
Member Avatar for TheWolverine

In addition to gerard143's solution, which is fine. You may want to make getitsvalue virtual. This is problem is a specialization of the common construction: [code=c++] class Base { public: // Stuff... virtual void write(std::ostream&) const; }; class Derived : public Base { public: virtual void write(std::ostream&) const; }; std::ostream& …

Member Avatar for TheWolverine
0
354
Member Avatar for daviddoria

There is a third part the equation here: To illustrate consider this: [code] class AClass { public: AClass(const int,const int) { std::cout<<"Constructor"<<std::endl;} AClass(const AClass&) { std::cout<<"Copy Constructor called"<<std::endl; } AClass& operator=(const AClass&) { std::cout<<"Assignment operator called"<<std::endl; return *this; } }; int main() { AClass Object(1,1); // Object constructed with constructor …

Member Avatar for daviddoria
0
251
Member Avatar for beejay321

Firstly all variables are scoped. That means that if a variable is within a set of brackets [icode]{ }[/icode] then the variable will exist only within that region. Each time the execution leaves that region, the variable is said to be out of scope. [code=c++] int myFunc() { int A(10); …

Member Avatar for sfuo
0
140
Member Avatar for kutuup

First welcome to Daniweb, second please use code tags! It make life easier for all of us. The problem is possible with the use of [icode]srand(time(NULL));[/icode]. What you are doing is re-initializing the random number generator with a number and that number is from the time. HOWEVER, time(NULL) normally only …

Member Avatar for mike_2000_17
0
130
Member Avatar for Crutoy

You seem to think that intermediates are attempts that is not the case, I don't understand how you can skip that test of 875, it is a guess, and too high a guess. e.g. [code] computer value: 789 minValue=1; maxValue=1000; for(int i=0;i<10;i++) { guess=(maxValue+minValue)/2; // set maxValue minValue based on …

Member Avatar for Crutoy
0
801
Member Avatar for atticusr5

There is always the ostream methods e.g. [code=c++] void print_list_four(const std::list<cProg3>& lst) { copy(lst.begin(),lst.end(),std::ostream_iterator<cProg3>(std:cout,"")); } [/code] However, you will want two things, (1) to change your [icode]void Print_f(fstream &Outfile);[/icode] to something slightly more general.[icode]void Print_f(std::ostream&) const;[/icode] and (2) to add this functions [code=c++] std::ostream& operator<<(std::ostream& OutStream,const cProg3& A) const { …

Member Avatar for atticusr5
0
134
Member Avatar for KazenoZ

It sounds like you are looking for an interpreted language which can interact with you c++ code. If that is the case, then look at languages like lua, e.g. [URL="http://www.lua.com"]http://www.lua.org[/URL]. Used with swig it makes a really quick interface, [url="http://www.swig.org"]http://www.swig.org[/url] There are others, but I found these two worked well …

Member Avatar for KazenoZ
0
148
Member Avatar for doublecheck

Several things come to mind. [and in no particular order]. You will have to judge what you think the importance is. (a) You test a double precision number to be exactly equal to zero, that very often doesn't happen, e.g. your get 1e-314 or something very close to zero but …

Member Avatar for doublecheck
0
157
Member Avatar for holocron

Without all the code to test this, we are just guessing. BUT: the for loop in the copy constructor looks horribly suspicious. [code=c++] for (DLNode *sourcePtr = source.head->next->next; sourcePtr != tail; sourcePtr = sourcePtr->next) { // ... } [/code] You see that tail is set to [icode]tail(new DLNode::DLNode(head, 0, NULL))[/icode] …

Member Avatar for holocron
0
243
Member Avatar for ivaylo91

First off, absolute brute force isn't going to work in this case as the input is in floating point, and you can easily get a function that has maxima at non-integer values. Next, the finding of minima/maxima of a function in a range, is still an active research topic. Even …

Member Avatar for ivaylo91
0
2K
Member Avatar for vanalex

The code that you wrote correctly works in both cases because you didn't actually do anything with obj2 or obj1. Note you wrote this: [icode]cout << "ob2.tab[0] = {" << obj1.getTab()[0] << "}" << endl;[/icode] That should have been [icode]obj2.getTab()[/icode] not [icode]obj1.getTab()[/icode] Additionally you have incorrectly written the constructor: This …

Member Avatar for vanalex
0
152
Member Avatar for effizy

First off, well done for thinking about contributing to OSS [Open source software]. Personally, I think the best way to get a project is to actually look at your secondary skills and interests. Almost everyone involved in OSS is actual able to program. The skill level is surprisingly high. The …

Member Avatar for daviddoria
0
260
Member Avatar for helpfullProgram

Well you really are going to have to give us a little more code. There are no obvious things that you are doing wrong: [code=c++] #include <iostream> #include <iomanip> #include <sstream> #include <string> #include <vector> int main() { std::ostringstream cx; typedef std::pair<int,std::string> PT; std::vector<PT> XX; for(int i=0;i<10;i++) { cx<<"a"; XX.push_back(PT(i,cx.str())); …

Member Avatar for Narue
0
199
Member Avatar for FutureWebDev

I expect that you wrote somthing like this: [icode]std::cout<<"result == "<<a<<std::endl;[/icode]. The problem with that is the default precision, [B]for output[/B], is 6. The number itself is of a higher precision. If you write this [code=c++] #include <iostream> #include <iomanip> int main() { double a=1.2345678901234567890; std::cout<<std::setprecision(20); std::cout<<"results ="<<a<<std::endl; // Not …

Member Avatar for FutureWebDev
0
188
Member Avatar for alexchen

Sorry the solution given is just too inefficient. You simple don't need to copy the whole array each time. Taking ravenous's code base: [code=c++] const unsigned int range = 100; const unsigned int numberToSelect = 10; int* remainingNumbers = new int[range]; int* chosenNumbers = new int[numberToSelect]; // Initialise the list …

Member Avatar for ravenous
0
18K
Member Avatar for Isbella

Something that avoids all the graphical stuff, [Well use an external program - not part of the project] is a simulation. That can go from easy, to [B]extremely[/B] complex. There are a number of classes of simulation, but it is easier to give an example, what about a set of …

Member Avatar for StuXYZ
0
278
Member Avatar for lasl0w

Obviously, it would be a lot easier to look at this if you had posted all the code. [B]However: [/B] Find_Trav_Subtree looks very strange [to me]. You see it calls the right branch [icode]if (current->Right)[/icode] AND then [B]always[/B] returns Find_Trav_Subtree from the right branch REGARDSLESS of it returning a NULL. …

Member Avatar for lasl0w
0
200
Member Avatar for ScreamingPsycho

There are several mistakes in the above code. The main one is that you wrote the code in one long block without debugging each section. It is almost always easier to write the code in little bits, keeping a running program that does a little more each time. Let us …

Member Avatar for ScreamingPsycho
0
155
Member Avatar for miturian

On reading this I thought that the obvious solution is to use a functional. The functional can be defined as a member of your class, or not. Additionally, I wasn't actually sure what algorithm you were implementing, in this example I consider that you have an vector of values, and …

Member Avatar for StuXYZ
0
2K
Member Avatar for chamika.deshan

[QUOTE=;][/QUOTE] Ok the class is a policy class. So let us understand what you can do with the original code and your code. First consider two classes: [code=c++] class SimpleObj { // Stuff.. public: SimpleObj(); // Simple default constructor }; class ComplexState { public: ComplexState(const int,const std::string&); // THE ONLY …

Member Avatar for mrnutty
0
147
Member Avatar for i_luv_c++

There are two issues here (a) code given doesn't do the assignment. (b) you don't understand the recursion. First let us deal with (a). Code given returns false if stones are greater than 5. That is not true. Consider the case that there are exactly 6 stones. If I take …

Member Avatar for mrnutty
0
130
Member Avatar for jsav

Sorry I am not impressed with your teacher. Most compilers of c++ and a lot of other compiled language split the program up into individual files. Each of those files are normally compiled into object files. These normally have the .o extension. They are the machine code of each block …

Member Avatar for jsav
0
283
Member Avatar for doogidie

Your problem is that you have masked length. You wrote this: [code=c++] # void file(char* Filename, int length) { int length; // UNINITIALIZED VARIABLE: for(int i=0;i<length;i++) { } } [/code] Note that length is NOT the same length as the one passed to the function, you have masked it with …

Member Avatar for alexchen
0
118
Member Avatar for raheel_88

You problems are in your fuction changeGridStorage. You do this [code=c++] x.resize(n); // this is fine y.resize(m); for(int k=0;k<=m;k++) // I REALLY don't think that you need <= BUT this isn't your // main problem v.resize(n,vector<double>(k,0)); // Ok talk about packing a lot into one line: // I will discuss …

Member Avatar for StuXYZ
0
1K
Member Avatar for jamesl22

Well done! I haven't seen this bug/error before. Anyway it made me smile. What you have done, is simple use istringstream in a very odd way, the effect is to create a local variable [code=c++] std::string str; while(getline(input,str)) { istringstream(str); // This line is the proble: // str is a …

Member Avatar for Agni
0
180
Member Avatar for foliot

Ancient Dragon is nearly perfectly correct in what he said, but can I say that you have to think about the deletion of the memory as well. First off, he has made a couple of typos, however, I think that is caused by fiolet. The AD code should be: [code=c++] …

Member Avatar for StuXYZ
0
194
Member Avatar for lasl0w

you have two problems with your code: (a) missing typename on the in the template file. [code=c++] std::vector<RecordType>::const_iterator it; // THIS IS WRONG // This is correct: typename std::vector<RecordType>::const_iterator it; [/code] There are many explanations around for this, it basically is because since depending on what std::vector<RecordType> is specialized as, …

Member Avatar for lasl0w
0
455
Member Avatar for GURU1349

The problem that you seem to have with this code is understanding the pathway of the if / else construction and the way to define it. There is a "formal" way to define it, but I think that first time it is easier with an example: So here goes: [code=c++] …

Member Avatar for GURU1349
0
127
Member Avatar for NichtSoGut

I don't like the example given. I thisk that it misses the opportunity to be a useful learning tool: I would like it modified like this to allow the user to actually see what went on: [code=c++] // bad_alloc example [+ modification] #include <iostream> #include <new> int main () { …

Member Avatar for StuXYZ
0
482
Member Avatar for Othisstuffisfun

It is a bit more complex than that. You have made a whole set of basic errors, and I think you have to fix all of them to get yourself out of jail here. Let me start: First off you have TWO constructors, (a) the default constructor and (b) a …

Member Avatar for StuXYZ
0
642
Member Avatar for someguyjbb

I am not surprised this doesn't run! You have a head node called root. However, rather than add a new copy of the memory for it, you do this: [code=c++] if(root == NULL) { // THIS IS A RUNTIME ERROR: root->data = Person(name, number); root->left = NULL; root->right = NULL; …

Member Avatar for StuXYZ
0
132
Member Avatar for NinjaLink

This is just a simple multi-file program. The big advantage of this [Particularly for big projects] is that you don't have to keep recompiling all the program in one go, just the bit that you are changing. Although it doesn't do anything you can compile it like this: (as individual …

Member Avatar for NinjaLink
0
294
Member Avatar for firework

You unfortunately have several problems: So i am going to give you a quick summary of the problem and why I think you have made the mistake. (i) In the constructor fraction::fraction(), you have written [icode]integral, numerator, denominator = 0;[/icode] This DOES NOT do what you think, it does NOT …

Member Avatar for StuXYZ
0
163
Member Avatar for cwarn23

Sorry but I REALLY don't understand what you are trying to do. I would appreciate an example or two. However, that leaves the code, which is simply horrible. It cannot possible be necessary to write so much code to do this, and it cannot be necessary to using strings to …

Member Avatar for cwarn23
0
112
Member Avatar for lochnessmonster

Absolutely fine, (IMHO), obviously it depends on your needs, but what about classes that return some kind of evaluation, e.g. a class that calculates the global density from all the objects in a simulation. It knows the materials, object locations and orientations. It has only one public function that returns …

Member Avatar for mike_2000_17
0
129
Member Avatar for kelechi96

As Vernon says, you are very lucky that line 40 and 46 compile. HOWEVER: if they do, the (which in your case they obviously do). The actual error is this: [icode]cout << letterlist [3][0];[/icode]. That is because possible is an integer an actually over flows!! [code=c++] for (int n = …

Member Avatar for kelechi96
0
133
Member Avatar for anglwthnati2de

Ok the first and most important problem is simple that you have gone about this task in the wrong way. Start with the assumption that the compiler is your friend not your enemy, it is there to help, but if you write your whole program and then try to compile …

Member Avatar for anglwthnati2de
0
204
Member Avatar for MasterGberry

The problem is basically simplified to this: [code=c++] double **array = new double* [size]; array[i]=3.0; [/code] What you have done is declare a array as a pointer to a pointer of arrays. That is effectively a double array like dynamic version of [icode]double A[10][20];[/icode]. However, you did not initialize the …

Member Avatar for MasterGberry
0
92
Member Avatar for TinhornAdeniyi

One of your problems is the error in CheckTitle: [code=c++] bool CheckTitle(VideoGame*& first, string title) { VideoGame *current; current=first; while(current!=NULL) { if(current->Name==title) { return true; } else { return false; } // You can't get to here : current=current->link; } // If you get here what do you return ??? …

Member Avatar for TinhornAdeniyi
0
236

The End.