565 Posted Topics

Member Avatar for jimJohnson

[QUOTE=;][/QUOTE] Several worring things here , but I am going to pick on one detail. Your wrote this: [code=c++] while(input[i]==input[j] && i<=j) { i++; j--; } [/code] Now what happens with the simple word "a". Let us see: First i is set to zero and so is j. The while …

Member Avatar for StuXYZ
0
135
Member Avatar for completehoax

[QUOTE=;][/QUOTE] I think that you have mis-understood what is going on in your if statements. The condition [icode] if ('A' != 'z') [/icode] is ALWAYS true for the standard ASCII character set. It is the same as writing [icode] if (65 != 122)[/icode] which you can see is ALWAYS true. …

Member Avatar for Kanoisa
0
104
Member Avatar for avarionist

[QUOTE=;][/QUOTE] You should get an error with that code [Nathan's] since size_t is normally unsigned. That means is it is always >0. Use a long int and a cast. Alternatively use an iterator. You can also offset by one [code=c++] for(size_t i=input.size();i;i--) temp+=input[i-1]; [/code] But I prefer iterators.

Member Avatar for avarionist
0
243
Member Avatar for madhub2v

[QUOTE=;][/QUOTE] That is a bit field, so I can't really speak for all of it since I don't know. First off there are not that many completely distinct OS , we have windows, unix (several flavours0, linux, BSD/Mac OS-x then stuff like OS-9 [it is in things like microwaves, digital …

Member Avatar for StuXYZ
0
113
Member Avatar for darelet

First off as Fbody points out correctly, you ideally will give us a bit more information particularly on dataStructure. Second, a large number of "memory" errors come about because of memory freed too early. BUT the error only occurs after the memory is used for something else. This may be …

Member Avatar for mitrmkar
0
383
Member Avatar for Kanoisa

The obvious thing do here seems to be to use a typedef. Consider this [code=c++] class SSE2Vector { // Stuff here that makes use of SSE2 and is fast }; class BasicVector { // General version. Work on everything. }; typedef BasicVector Vector; [/code] What you have done there is …

Member Avatar for StuXYZ
0
96
Member Avatar for hitmanner

Hi, There is a tiny bit of a trick to doing this. Basically, you need to get enough memory for the characters AND enough memory for a pointers to it. This assumes that both the 501 and 41 in your example are effectively variables that are only known at run …

Member Avatar for amin_a
0
357
Member Avatar for daniel88

This has tow issues : (a) the code (b) your expectations of the output. First the code: Since you are re-shuffling the code each time, you don't need to re-assign the groups, just re-shuffle. It is much quicker to do it this way: [code=c++] for(int i = 0; i < …

Member Avatar for daniel88
0
113
Member Avatar for greeran

If you are going to use a C library in C++, you need to compile the headers in C style. That is done like this: [code=c++] #include <iostream> extern "C" { #include <lua.h> #include <lualib.h> #include <lauxlib.h> } int main() { int s=0; lua_State *L = lua_open(); // load the …

Member Avatar for StuXYZ
1
1K
Member Avatar for atman

[QUOTE=;][/QUOTE] The code as posted works find. [assuming that you put a using namespace std; There are two possible reasons [I can think of] that you are not seeing this code working. (a) you haven't actually run THIS code. The error with the lack of std::, includes and using namespace …

Member Avatar for StuXYZ
0
116
Member Avatar for miturian

[QUOTE=;][/QUOTE] You have forgotten to add a [icode]-lgsl[/icode]. That assumes that you want to make a shared library version of your code, and that you have a path to the libgsl.so file [defined in: ld.so.conf]. IF that doesn't work but you have libgsl.so then you can set the path explicitly …

Member Avatar for miturian
0
2K
Member Avatar for jackman05

If you do write your own Gauss-Jorden elimination procedure, be [B] very[/B] careful to deal with the huge numerical rounding errors. Re- stabalization of matrix after most steps is essential. Also please not the obvious test matrix [1,2,3][4,5,6][7,8,9] has zero determinate so has no inverse. Simple approaches in books like …

Member Avatar for mrnutty
0
317
Member Avatar for goulda660

Ok the problem is one and only one line. The first is that you are compiling -O3 ... until you have got all the compilation errors out and debugged it DONT use -O anything! Second the error is on line 428 [code=c++] << "After Motor voltage: " << d.amv[x] << …

Member Avatar for goulda660
0
212
Member Avatar for Cowbox

Try using a string stream: [code=c++] std::ostringstream cx; for(int i=1;i<10;i++) { cx.str(""); // clear the stringstream cx<<"File"<<i<<".txt"; std::string Filename=cx.str(); } [/code] Obviously you have to do something with Filename but it has the basics. Note that since I use a loop, you have to clear the stringstream on each pass. …

Member Avatar for Cowbox
0
109
Member Avatar for Jeff_5_7

Can I add that you have also got a numerator and num, denominator and dem in the class. That is also an area of confusion.

Member Avatar for Banfa
0
263
Member Avatar for NathanOliver

First off: Well done of writing your first "big" class. I have quick question, does the prime check work. E.g what if you have 3, which is prime? I think it give false which is wrong. Also you only need to test as far as the sqrt(N). pow does not …

Member Avatar for NathanOliver
0
151
Member Avatar for bbrradd

There are a few little errors: (a) You have tried to write a factor that somehow works on the whole array. (b) You have forgotten that if you get clever and add two factors because any number N, has factors 1 and N. Not to test them (c) why does …

Member Avatar for StuXYZ
0
105
Member Avatar for riotburn

There are several problems: (i) you haven't given us a piece of code that compiles. What is Bp ? (ii) you haven't given us the input you use , e.g. what does coupon equal? (iii) Then you use what I think is the differential equation approximation at each step. Have …

Member Avatar for riotburn
0
119
Member Avatar for calypso8

Sorry dustreader, but if you are going to be using the STL, do this: [code=c++] // Assign players in any order (not random) shuffle(players,players+10); [/code] The code given is horrific. It has three vectors etc... However Calyso8 is starting, so it is important for him/her to understand the algorithm and …

Member Avatar for calypso8
0
1K
Member Avatar for icelantic

First off: Fix your compiler warnings. They are there for a reason. e.g. [icode]storage[i]="\0";[/icode] should be [icode]storage[i]='\0';[/icode]. Your memory problem is because in both constructors [that are ambiguous by the way] you allocate storage but do not allocate or even set to zero the memory for each location in storage. …

Member Avatar for StuXYZ
0
118
Member Avatar for drewangel

The general way to solve N equations of N unknows of ANY powers (e.g. x^5) is the use Bezout's method. See: [URL="http://www.mathpages.com/home/kmath544/kmath544.htm"]http://www.mathpages.com/home/kmath544/kmath544.htm[/URL] (Also there is a lot of literature to improve the speed and numerical stability). The method is highly tractable to code because as matrix is created and used …

Member Avatar for ninjasmith
0
3K
Member Avatar for sexyzebra19

You could skip the call to the function and just write this [code=c++] std::cout<<"Time taken == "<<static_cast<double(t2-t2)/CLOCKS_PER_SEC; [/code] You could wrap the static part in a funcit

Member Avatar for Salem
0
421
Member Avatar for drjay1627

As written there is nothing wrong with this (except I think that you would benefit from a typedef. e.g. [code=c++] typedef std::map<std::string,int> mTYPE; mTYPE aMap; //.... aMap.insert(mTYPE::value_type(word,i)); [/code] However, I would guess that you have swapped the declarations of fileMap and freqMap. It that is not the problem, please make …

Member Avatar for drjay1627
0
441
Member Avatar for clutchkiller

Actually, it is only partially true. For many template classes you know that you are only going to have a few well known types to create. In that case you can use explicit template initialization. e.g. [code=c++] //file test.h template<typename T> class test { T x; public: void addStuff(const T&); …

Member Avatar for StuXYZ
0
121
Member Avatar for kavithabhaskar

The problem that you have is understanding how the ordering works. (It is like the maths problems of multiply before addition. e.g 6*5+3 is 33 not 48 ) You have written [code=c++] if (s[i] == 'a'||'A'||'e'||'E'||'i'||'I'||'o'||'O'||'u'||'U') [/code] which is the same as [code=c++] if ((s[i]=='a') || true || true || …

Member Avatar for kavithabhaskar
0
94
Member Avatar for callister

[QUOTE=callister;1142426]I know how bisection method works..It just that I don't know how that loop can make it work..[/QUOTE] Well the real problem is that the loop does not work. Or more accurately only works for the specific instance when [ICODE]f(a) <0[/ICODE] and [ICODE]f(b) >0[/ICODE] and there is only one root …

Member Avatar for StuXYZ
1
130
Member Avatar for lanilonzo

Why don't you use dynamic_cast. E.g. [code=c++] class Base {}; class A : public Base {}; class B : public Base {}; Base* Aptr=new A(); Base* Bptr=new B(); A* Ax=dynamic_cast<A*>(Aptr); // sets Ax to a Ax pointer. A* Ay=dynamic_cast<A*>(Bptr); // sets Ay to ZERO [/code]

Member Avatar for StuXYZ
0
85
Member Avatar for naitsirk

If you want help.. ask a question, I certainly have not the slightest idea what your problem is , what you are trying to do and what c++ code you have currently written. Note: When you post code [B]use code tags[/B]. Please read the forum guidelines.

Member Avatar for StuXYZ
0
85
Member Avatar for cassie_sanford

Just about everything about interest is wrong. Basics of percentages: If you wish to calculate a percentage (P) from a total (T) you need [icode] T*(P/100.0)[/icode] Your tax is 6.75 % so, you write totalTax = subTotal+tax. Now the mathematicians say there are three numbers 0,1, infinity. BUT the key …

Member Avatar for Fbody
0
411
Member Avatar for Chetan_

Well I have written a system for extracting maths equations from input text which I currently use in several projects. So I just want to ensure you know what you are getting into it is about 2500 lines of code. So structure: you can break the functions down into a …

Member Avatar for Chetan_
2
112
Member Avatar for Izarian

Have a look at the boost::any class. [URL="http://www.boost.org/doc/libs/1_41_0/doc/html/any.html"]http://www.boost.org/doc/libs/1_41_0/doc/html/any.html[/URL] If you combine it with some of the typelist ideas in the boost::mpl then you can basically do what you want. The downside is that this style of programming often looses type safety, which is "a bad thing" as it moves compile …

Member Avatar for Izarian
0
137
Member Avatar for *Moonlight*

Do note: that for years before 1582, leap years where EVERY 4 years. There was no 400 or 100 year rule. Prior to 325 the system was 1582 is a mess. Since they did not have a 5-14th October completely (10 days). It you are in in Britian/America it wasn't …

Member Avatar for *Moonlight*
0
881
Member Avatar for Amawri

Ok the ugly cin.ignore is simply unnecessary. I have no idea why you might need it, it ignores the next 10 characters of input (say 10 random letters upto a return. Very strange. The std::endl should flush cout, so it should work. If you are using an old compiler you …

Member Avatar for UberJoker
0
234
Member Avatar for vishesh.verma

Several problems are apparent. (a) Turn is not initialized so will definitely be wrong (b) loop variable j run 0 to 3 inclusive (j<4). so you access undefined memory locations in rot. (c) rot is local only to the function rotate so the whole function is pointless. [make it global …

Member Avatar for StuXYZ
0
81
Member Avatar for Carrots

The trouble is that advance does not return an iterator, AND the iterator (i in your code), has to be double derefrenced because the iterator points to a pointer and hence the error message. You need: [code=c++] advance(i,a); if ( (*i)->getName()==someVar ) { } [/code] Note I have added the …

Member Avatar for StuXYZ
0
112
Member Avatar for karthik chinta

Ok you have (a) made a few basic errors (b) confused how map searches work and (c) made it very very difficult to read by using C like layout and constructs. I will address (c) first by writing some c++ like code (others may object but I think it is …

Member Avatar for lyle017
0
10K
Member Avatar for Lukezzz

I think you have made a mistake in your question. If you have 0..25 in your code your compiler will tell you that it is an error. However, if you are trying to go from a string to a number the simplest way is to use a stringstream. The problem …

Member Avatar for fjrivash
0
140
Member Avatar for SurviBee

Hi, I am amazed at this code. The normal way to do a trapezium integral is simply to loop over the value like this const int N(500); const double startTime(0.0); const double endTime(100.0); double area(func(startTime)+func(endTime)); area/=2.0; for(int i=1;i<N-1;i++) { area+=func(i); } area*=(endTime-startTime)/N; What you are doing creating 100000 objects to …

Member Avatar for sweetkim_2008
0
203
Member Avatar for KOFSoldier

Welcome to the real world. There is not free lunch.... sorry. So (a) either attend your classes and actually pay attention. (b) decide that the class is not a good use of time and instead study some books in the library. (c) Fail your degree/course. But because this is the …

Member Avatar for KOFSoldier
-4
180
Member Avatar for pspwxp fan

Ok the original post was about gcc, which has a tolower function that does not return a char, it returns an int and takes an int. That is because it works with internationalized character sets. So you do a functional composite to convert the form both ways or just write …

Member Avatar for pspwxp fan
0
113
Member Avatar for ab_n00b

This forum and others see this question a lot and you get answers that range from none - > everything. So I will point out something that I have noticed, I have never studied and understood any maths that immediately looked useful, but I always seem to find that it …

Member Avatar for kenji
1
116
Member Avatar for ylchen

I understand for quick solutions you would follow AncientDragon's sage advice. However, that always leaves a sour taste since I am sure your want to know how to do it: So here goes [code=c++] template<typename A> struct printFunctor { static void print(FILE*,const T& Obj) { } }; template<> struct printFunctor<int> …

Member Avatar for Ancient Dragon
0
2K
Member Avatar for nick30266

I am sorry I don't like jonsca's solution, it has ugly temporary variables, that aren't necessary. The better way to do this (IMHO) is to add two operators. One is operator<< and the other is operator>> [code=c++] std::istream& operator<<(std::istream& FX,complex& A) { A.read(FX); return FX; } std::ostream& operator>>(std::ostream& FX,const complex& …

Member Avatar for mrnutty
0
347
Member Avatar for pavanbr143

This code is a mess, and 99% is that it is mixed c and c++ , it has not been set out tidily so neither I nor you know what is going on. Things to fix: Why use malloc to allocate memory use [icode]int* wt=new int[5];[/icode] Then remember to delete …

Member Avatar for StuXYZ
3
412
Member Avatar for paddowan34

Sorry but the main problem is that you have over complicated the if structure in FindFirst. Several points (i) You pass the value first BUT don't actually use it. Let me elaborate. You use a variable first BUT you don't use the value you pass. So I put the variable …

Member Avatar for StuXYZ
2
119
Member Avatar for StaticX

Ok you have a number of problems: So let me (a) post some working code: (b) tell you what each line does: [code=c++] int main() { std::fstream bfile("file.bin", std::ios::in|std::ios::out|std::ios::binary); int a = 2; int var(0); bfile.write(reinterpret_cast<char*>(&a), sizeof(int)); bfile.seekg(0,std::ios::beg); bfile.read(reintepret_cast<char*>(&var), sizeof(int)); std::cout << "Variable:" << var<<std::endl; } [/code] Note that I …

Member Avatar for Nickg140143
1
270
Member Avatar for BosByte

As far as I understand the standard, this is not possible [I stand to be corrected]. There are slightly upsetting work-arounds. First: If you don't need the virtual aspect, this is easy use a template return type. Easy. Second: If you require the virtual part you can then return A_1 …

Member Avatar for StuXYZ
1
110
Member Avatar for bpt0004

Ok I am not going to deal with all of this mess but point out some of the basic errors and then ask how did you manage to get to this point. -- Talk your first effort, [code=c++] double Individual:: SchwefelsProblem(vector <double> schwefel_population) { for (int i=0; i <schwefel_population.size();i++) square_of_sums=square_of_sums+ …

Member Avatar for StuXYZ
0
1K
Member Avatar for amishraa

[B]First: [/B] [B]USE CODE TAGS[/B] [B]Second: [/B]you don't not have to declare the variable name in definitions e.g. [icode]void resultsfn(int& A);[/icode] is the same as [icode]void resultsfn(int&);[/icode]. This often makes code clearer [B]Three: [/B]Dont use [CODE]system("pause");[/CODE]. [B]Four:[/B] You use references BUT the fail to use references in namefn for example. …

Member Avatar for amishraa
0
137
Member Avatar for uncbball

First thing that comes to mind is that [icode]a[9][/icode] and [iCODE]c[9][/iCODE] are not initialized. Next you are using variables columns and row. So check that this->rows == u.columns. Then set the data in this. as c[] is just ignored. Other than that it looks ok.

Member Avatar for abhi_elementx
0
156

The End.