565 Posted Topics

Member Avatar for Brennan_1

The first thing I see is that the frequency code is extremely inefficient. It has a double loop, i.e. you loop over 100 times over all the quanties. If you had 300 numbers to read then you would have 30000 steps!! There is also a horrible memory error. Your array …

Member Avatar for iamthwee
0
789
Member Avatar for mrboolf

First of all thanks for posting something that isn't a homework question :) [or at least doesn't read like one]. Secondly, I assume that you are writing this to do something. So I am guessing to how you want to use them. Next: I have used partitions in real code, …

Member Avatar for jsdncjnsci
1
449
Member Avatar for sgw

Observe that you are calculating factorials as the division : So the quickest route is to remove the common factor. E.g int calc(const int I) { int sum(0); int x(I); // D=(pow(i,5.)/120)-(pow(i,4.)/12)+(23*pow(i,3.)/24)-(83*i*i/12)+(571*i/30) sum+=(120/30)*571*x; x*=I; sum-=(120/12)*83*x; x*=I; sum+=(120/24)*23*x; x*=I; sum-=(120/12)*x; x*=I; sum+=x; return sum/120; } Note that I have used the …

Member Avatar for sgw
0
162
Member Avatar for rebellion346

Your problems include two things that come to mine: (a) the answer that you require is complex, but you are trying to put that into a double. Not going to work. Instead add a [icode]#include <complex>[/icode] to your headers and use [icode]std::complex<double> root;[/icode]. You are also going to have to …

Member Avatar for vencen
0
2K
Member Avatar for tones1986

That looks like an error in getting an appropiate type built. That can occur when you have multiple files. (compile+compiler flag dependent) Add a template instanciation [icode]template class person<std::string>;[/icode] at the end of person.cpp and if we are lucky it will fix/change the problem. Note: If that is the problem, …

Member Avatar for programmerkk
0
271
Member Avatar for ItecKid

Hi, Ok this is a post about HOWTO find your errors, which will result in actually finding one of your problems, but it is more a breakdown of what you should be doing. (a) Ok write some output and it doesn't work. (b) See that your input look ok for …

Member Avatar for Calbert21
0
521
Member Avatar for abhimanipal

Sorry it is a error -- not sure it is a beginners error, but it is an error type I think you should know about. **Solution is to write** display<int>(myBeginIterator,myEndIterator); **Reason:** What you have done is not give the compiler enough information to determine the type of the iterator. That …

Member Avatar for abhimanipal
0
178
Member Avatar for james6754

The first problem is that it is very very difficult to figure out without the class definition, so I could be extemely wrong. (a) I have not idea why you can't add two identical matrixes together, e.g. `MatrixClass Sum=A.sum1(A);` So I think lines 9-11 are strange . (b) The code …

Member Avatar for StuXYZ
0
152
Member Avatar for Labdabeta

Your errors are dominated by overflow. These kind of functions are normally computed in a logorithmic maniford, not the real number manifold. Consider: `pow(x,254)` almost always in overflow for most of your x range. `pow(M_E,-x)` at underflow for most of your x range Those two can be combined: exp( log(x)*256-x), …

Member Avatar for Labdabeta
0
618
Member Avatar for cplusfreak

There are several things I would like to add : ( stuff I would mark you down on (or more likely I would give extra credit for) ). First off, there is not such thing as a guarenteed zero float. If you write this float div(float A,float B) { if …

Member Avatar for thines01
0
159
Member Avatar for nekoleon64

I think that you have a few problems with this, but please put all of the code into a single code block and we can all compile and check it -- *given how difficult I am finding the new coding highlighting system, I can full understand you making the mistake …

Member Avatar for StuXYZ
0
2K
Member Avatar for nschessnerd

If you don't want to post your code, then maybe a cut down version. But the quickest way to do it yourself is to compile with debug info on and then run and wait till it crashes. The backtrace will tell you what memory component has been corrupted. It may …

Member Avatar for MastAvalons
0
217
Member Avatar for jwill222

That has to be the worst error message I have ever seen !!! -- I mean I had no idea when I looked at it. Fortunately, I don't use visual C++ and got a this (from clang++) [code] test.cpp:7:12: error: default initialization of an object of const type 'const int' …

Member Avatar for Ketsuekiame
0
114
Member Avatar for therockon7throw

This doesn't look too difficult, there are going to be several ways to do this: SPOILER ALERT ---- the following works on SOME machines [not all I think]. You only have to change CAPACITY in an instance of Volkswagen and that simply means, reinterpreting the pointer to something that allow …

Member Avatar for therockon7throw
0
195
Member Avatar for rfrapp

There a a few things that are a bit ugly about this code, and likely to be a source of error. [otherwise not a bad attempt] The first is that you are using [icode]char board[70][20][/icode] then you are using stuff like [code=c++] void display(char board[][20], char newBoard[][20], int size, int …

Member Avatar for StuXYZ
0
262
Member Avatar for matt209

Actually, I would much prefer that you wrote line 19/20 as: [code=c++] std::vector<CBoard *> Board; std::vector<CPlayers *> Players; [/code] because what is the point of having namespaces and then just importing everything. Also putting [icode]using namespace std;[/icode] in at header file!!! Somewhere later, you are just going to import that …

Member Avatar for matt209
0
666
Member Avatar for swissknife007

This is hardly a C++ question, it is maths. Anyway, obviously you have made the transform (x,y>0) [tex]lcm(x,y)=\frac{x y}{gcd(x,y)}[/tex] That allows you to create a quadratic equation in gcd(x,y), that gives you what you the condition on gcd. That immediately excludes solutions for a large set of a,b,c. [fractional and …

Member Avatar for StuXYZ
0
106
Member Avatar for compsci91

Not sure that you know what you are doing here. The main part of the program will not work at all. Simply delete it from line 2 to line 14. It is utter junk. First off: Provide a default constructor/copy constructor / assignment operator and deletion operator. I know that …

Member Avatar for compsci91
0
205
Member Avatar for swissknife007

There are many things that are wrong. I am not figuring all of them out for you but will give some help. (a) Consider the test case: 15X2 Expected output 3 (because 30 goes to 3)/ Actual output 1. So what went wrong. It is in your multiplication. You don't …

Member Avatar for StuXYZ
0
523
Member Avatar for CY0T3R

The most scary thing about the above code is the [icode]pow(double(-1),j+1)[/icode]... please think, an alternating pattern is required. I initial thought that it was homework help, but it is actually nicely formatted obstifacted C++. So am not sure that the code deserves the -1 reputation. :)

Member Avatar for ravenous
0
200
Member Avatar for thecoolman5

The problem is that you are passing the string in the wrong order. Consider just the string "10-5". What you are doing is finding the first non-digit and setting that to operator so you loop through doing [icode] running_sum-=10 [/icode] Then you ignore the last number: What you need is …

Member Avatar for thecoolman5
0
633
Member Avatar for phorce

What you are really wanting to do is create a sortable storage form from your map. The obvious way is to just put the map into a [icode]std::vector<std::pair<double,char>[/icode] and sort on the first value in the pair. Obviously, you can reverse that and sort on the second value. As for …

Member Avatar for vijayan121
0
135
Member Avatar for pato wlmc

One of the first real fortran program every written was about the gamma function, and in typical mathematical notation it evaluated [tex]\sum_{i=1}^{6} \frac{\gamma_i}{1+\lambda_i \tau}[/tex] ina typical math function. Unfortunately I haven't seen the original code for it. But the use if i,j,... etc is extremely common for subscript in maths …

Member Avatar for Tumlee
0
5K
Member Avatar for Limiter

Minor comment to the above. You said [QUOTE]I know that constructors go into the .h file [/QUOTE] Fortunately, that isn't true. A lot of beginners (with C++/C) seem to think that there is some magic about .h and .cxx or .cpp files. There isn't. The compiler just (effectively) makes a …

Member Avatar for Limiter
0
207
Member Avatar for coolbeanbob

The error that you are having problems with is the fact that Timer::elaspsed_time is a function so you need to write [icode]double t = time.elapsed_time();[/icode] The reality is you really really need to re-write this. You are using #define's with sign letter values. (a) this is C++ so use a …

Member Avatar for coolbeanbob
0
149
Member Avatar for f4fjks

Without question focus on your other interests and skills... be it sports/hobby etc. If it is in a field outside of the typical domain of these kind of projects it automatically gets a better mark because there is an implicit effect of the marker over estimating the complexity because he/she …

Member Avatar for StuXYZ
0
121
Member Avatar for Dakot

What I find strange is the switch/case statement when you have a choice base on a simple number. [code=c++] if (choice<1 || choice>maxCandidates) votes[choice-1]++; else { std::cout<<"Incorect number... Exiting"<<std::endl; /etc... } [/code] Then the next thing that look strange is calling votes1() from votes1(). Surely write a function getVotes() and …

Member Avatar for StuXYZ
0
183
Member Avatar for maria536

-- Can I suggest that you test your code with 10-6 which should give 4 but doesn't. When you have fixed that problem in the obvious way, you can test -- Then test your code with 5 2 / This will highlight another error.

Member Avatar for maria536
0
142
Member Avatar for vishwanath.m

Not sure how much of the answer I should give. [if it is too much help then I am sorry]. If this insufficient, please reply and let us know. The first thing to note is that any integer number x, can be expressed as: [tex]x=a m + r[/tex] were a …

Member Avatar for StuXYZ
0
205
Member Avatar for v3ga

The error is in the function isanagrams. If you turn on the warnings on the compiler. [No I don't know how to do it on Visual studio.] You will see that you are told that fro that funciton: [I]warning: control reaches end of non-void function[/I]. The problem is that the …

Member Avatar for v3ga
0
276
Member Avatar for Aghtar

The art of programming starts when you carefully crafted code doesn't work. That is when you start trying to make your code do something, (anything), to help you understand it. Yours is a classic case. The first thing to do is add a print statement [icode]std::cout<<"I am here"<<std::endl;[/icode]. The first …

Member Avatar for StuXYZ
0
167
Member Avatar for fatzky_04

Lower triangular normally means that all the element [B]above[/B] the diagonal are zero. I would clarify that first. You are also going to have to be very careful about near zero errors if m is any of the floating point types. e.g. is 3.12e-312 not zero.

Member Avatar for StuXYZ
0
93
Member Avatar for maple123

That doesn't sound useful idea. Consider this (a) A polynomainal multiplication is a N * M process were the length of the polynominial are M and N. (b) The polynominal can be sparse e.g. x^8+x. Ok: the first thing is that an linked list can be used for almost ANY …

Member Avatar for raptr_dflo
0
739
Member Avatar for skylinedrifter

There are several errors. The biggest one is to write [icode](X2 - mean)^2[/icode] since the [icode]^2[/icode] does not mean power, but actually means xor. If you want power, you have to write either [icode]pow(value,2.0)[/icode] or you could of course do value*value. Note that you don't initialize mean, and mean is …

Member Avatar for jhonlarry12
0
191
Member Avatar for digipak

A word of caution because from the question, I think that you don't fully grasp what is going to happen [if I am wrong then apologies]. Your code says this: [code=c++] class fileSys{ public: Filesys(Pdisk& disk); private: Pdisk disk; }; [/code] And that implies that you are going to write …

Member Avatar for StuXYZ
0
507
Member Avatar for nuclear

Several problems exist. First if you reference an array out of bounds you are going to get a mess. Consider your code: [code=c++] for (int i=0;i<V;i++) { for (int j=0;j<H;j++) { ne=0; if ( A[i][j-1]=='*' ) { ne+= 1; } // ..... [/code] What happens as j is zero?? Similarly …

Member Avatar for nuclear
0
702
Member Avatar for totalanonymity

Caut baia correctly points out the error (I believe) but I would like to point out that you seem to have missed the use of PI. You declare a const double PI to be 3.1419 and then don't use it. In the line [icode]x=4.0 * 3.1419 * pow (r, 2);[/icode] …

Member Avatar for WaltP
0
3K
Member Avatar for L0s3r

First off given your question statement, [quote]To Code: rand7() which generates randomly distributed no. from 1-5[/quote] you can do this: ;) [code=c++] int rand7() { return rand5(); } [/code] Ok I guess that isn't your question, you actually want to return rand7 where the result is 1-7. First thing to …

Member Avatar for StuXYZ
0
166
Member Avatar for jmay1327

Your problem is (simplified) this: [code=c++] for (int i = 0; i < numStudents; i++) { Student student; student.fName="fred"; sNames.push_back(student); // Copy the current version to sNames // Do stuff with student ... doesn't matter what. // student goes out of scope } [/code] The problem is the push_back uses …

Member Avatar for jmay1327
0
214
Member Avatar for Marissak

First off welcome Daniweb. Next, now that I have your code, what are the problems with it. Unfortunately, quite a few -- I have listed a few to get you going in the right direction. The first is that you are using this code [lines 32-34]: [code=c++] cin >> line; …

Member Avatar for GouseKSyed
0
234
Member Avatar for Labdabeta

I have a nice little bit of OLD code that I use to count the number of bits, and I have adapted the idea. [Note I didn't write the original idea of using 0333 and 0111, but I do not know who did]. [code=c++] unsigned int uCount = MyInt - …

Member Avatar for murnesty
0
100
Member Avatar for MareoRaft

There is nothing intrinsically wrong with your code. i.e. in a stand alone test env. it works. The error you are getting comes from your library matrixOptLibrary.h. There are any number of reasons that this code is going to break it. (a) the using namespace std; , and more likely …

Member Avatar for MareoRaft
0
190
Member Avatar for massivefermion

Not a bad effort, however, your comments suggest that you would like some feedback... So here are a few things that I have noticed. First off, I don't like seeing [ICODE]using namespace std;[/ICODE] anywhere, but NEVER in a header. In function BToDec, you do this: [code=c++] int *num=new int; // …

Member Avatar for massivefermion
0
475
Member Avatar for radiata

Sorry, but regardless of the errors in your code you have the wrong algorithm. You seem to have assumed that you can translate directly from base 10 decimal numbers, you cant. Eg. Consider 49. That would be written IL. however, your code would produce XL1X. So I would suggest that …

Member Avatar for WaltP
0
178
Member Avatar for barttoo

I will comment, that your programming AND your math need to be strong to do a masters. I believe that you can effectively trade between ability in them. Extremely good math, and ok programming will work as well. If I have to select between two candidates I have a tendency …

Member Avatar for \007
0
251
Member Avatar for Missionary

The main problem is that you have no idea what is going on because you have not put print statements [icode]std::cout<<"I am here"<<std::endl;[/icode] in your code. Next you have a character string that you call string. You actually pass the pointer to the first character. In a typical c-style character …

Member Avatar for StuXYZ
0
78
Member Avatar for literal

Ok this code made me laugh -- I had better explain. So let us consider each line in turn [note i have expanded the formatting] [code=c++] for(int=2;i<1000;i++) // Simple loop { for(j=2;i/j;j++) // Loop to do j=2 to j < i : it works because // integer arithmetic is being …

Member Avatar for Distantearth
0
164
Member Avatar for forumposters

I am surprised reading this, I would have thought most of you knew the +2,+4 rule -- but it hasn't come up, just the old +2 rule. Assuming that you are not going to use the memory that the typical sieve methods use, or the complexity of the more you …

Member Avatar for yashsaxena
0
796
Member Avatar for I Like Pills

First off I agree with Mike, but I will also add that after a while, the C++ aspect of the programming language becomes almost second nature. I will be struggling with the maths, [ that somehow never becomes second nature :( ] and with the main design, or the likely …

Member Avatar for pseudorandom21
0
370
Member Avatar for andylbh

If you are just after the centre and the shape is convex then, what about just taking the average if you do [code] Point C(0,0) // sum over points: for(int i=0;i<Number_of_Points;i++) C+= shapePoint[i]; // divide by the number added up: C/=Nubmer_of_Points; [/code] (Point is just a simple x,y class. You …

Member Avatar for StuXYZ
0
162

The End.