- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 16
- Posts with Upvotes
- 13
- Upvoting Members
- 14
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
59 Posted Topics
Re: I think this is quite good program. Some could say that redundancy is an issue but I don't think so. This program is quite good, however a bit redundant. Redundancy isn't so bad, it can be useful sometimes. Redundancy in this example isn't bad, it's important that this program is … | |
Re: Just to tease you, this is quick program (written in 10 minutes) to generate primes using linear sieve. [CODE]#include <iostream> #include <vector> #include <cmath> using namespace std; void genPrimes(int n, vector<int>& result){ vector<bool> temp(n+1,true); temp[0]=temp[1]=false; for(int p=2;p*p<=n;){ int q=p; int x; while((x=p*q)<=n){ while(x<=n){ temp[x]=false; x=p*x; } while(!temp[++q]); } while(!temp[++p]); } … | |
Re: [QUOTE=Fbody;1505376]Some compilers, such as GCC, automatically initialize integers to 0 [/QUOTE] No, GCC doesn't initialize ints to 0. I run following program three times: [CODE]#include <iostream> int main(){ int a; std::cout<<a<<'\n'; }[/CODE] On GCC 4.4.5 it gives me -121776192, -1217650700 and -1218613260. Only global variables are initialized automatically to 0, … | |
Re: According to system function discussion. For me system("pause") is the best way to leave window open for Windows users to see results. On my system I just get info in terminal that this command was not found and program finishes normally. If someone would use appreciated (according to sticky) getchar, … | |
Re: Your primality tester is flawed, for example 49 according to this primitive test is prime (but for every number <49 it is correct). Also it will not finish if k>0, because only manipulation you do with k is incrementation in line 24, and in the following line you test it … | |
Re: There is [URL="http://www.cplusplus.com/reference/algorithm/for_each/"]for_each[/URL] in c++, but I think this is not what you mean. There probably will be extension to for statement to allow Java like foreach, but for example it is not yet included in release version of GCC (it will be in 4.6, but it is now in … | |
Re: Try using bigger table. For every 1 kb you use, you are outputting line to stdout and then you are flushing it (endl). If you try to do this for about 10^6 times it will take some time, allocating memory is a LOT faster then outputting text using cout<< <<endl. | |
Re: In minus one day you can get negative day, and in function toname you only treat properly positive idx. If you give to this function negative number this value is not handled by switch, and you return nothing, and this nothing is treated as string, and after statement in line … | |
Re: I just really like this "better" C++ code then #define MAX(a,b) (a>b)?a:b. Yes, I know that in this usage MAX(i++,j++) is wrong (to be honest I'd just use using namespace std and max function). | |
Re: Unfortunately I can only write Polish-English, French-Swahili and Chinese-Russian dictionaries. | |
In my project I tried to use boost RNG in such manner [CODE] inline int rand(const int m){ uniform_smallint<> us(0,m-1); variate_generator<rnggen_t&,uniform_smallint<> > vg(rng,us); return vg(); }[/CODE] where rnggen_t is type of random number generator (rng). But using this (for every generator) instead of rand()%m, is slowing my program at least … | |
I am making basic project for "Computer simulations of polymers and biopolymers" using Monte Carlo simulation and I currently have access only to ASUS eee PC netbook. Could anyone run attached program on a faster hardware for input data [ICODE]100 50 50 1000000[/ICODE]. Last part of data is number of … | |
Re: Wouldn't FSQRT on x86 processors be quicker? Or for many values SQRTPS? | |
Re: Iterator is not a pointer and you cannot automatically cast it in line 33 (also you try to convert it to char, I think you intended to write ThisOne = text.begin();, which isn't correct). If you want to use char* I would suggest using array of chars instead of string … | |
Re: That depends. I wouldn't care much about overhead in constructors and destructors, they are called rarely. Pointers would be better if you move a lot of data inside Image container and are a must if you want to use Node derivatives. But for example you can have Image<Node> and use … | |
Re: Don't update height during first phase of insertions. You have this tree: [CODE] B |1 \2 A C \1 D \ E [/CODE] And you mark D node to update, it gets 2 and on C node there is imbalance. You left rotate it and update C height. This way … | |
I was researching this topic for a some time, but I can't find definite answer (and I don't hope to find it there). Is it feasible to do heavy computations using C++? I mean specially computations on large multidimensional arrays. C++ has mechanisms which can help writing quite clean optimised … | |
Re: Maybe you should just learn other language first, before diving into advanced C++. I suggest reading [URL="http://norvig.com/21-days.html"]this[/URL], it gives nice perspective how to learn programming. If you decide to still program in C++, you will find yourself in position, where pointers, or other elements of this language, are the best … | |
Re: You need to think about how templates work. When you write vector<int> compiler have to generate code specially for vector of ints, vector<int> and vector<char> are two different classes. If you use templates it is necessary to have definition of them while compiling objects files for every .cpp file which … | |
Re: polyinstance.setcoeff(Termholder[]); -- you don't need []. Also void setcoeff(Term)!=void poly::setcoeff(Term Termholder[]), first declares function taking one Term argument, and the second defines function taking array of Term argument. | |
Re: I think the easiest solution would be to try VBA. If you already have good knowledge of other programming languages you would pick sufficient (to write dirty, inefficient and unmaintainable script) knowledge of this language ("basically" you just need to find necessary function in reference manual). I don't know if … | |
Re: Std::set is ordered, you can't change order of numbers. You could just use presorted normal array (vector) for next_permutation. | |
Re: First of all get some better c++ book, as I can see it is not very modern (iostream.h was deprecated a long time ago and now using it is an error). But in this example you just made spelling error with inc[U]lu[/U]de directive. | |
Re: Char can be signed, or unsigned, it is implementation defined. Obviously in your compiler char is signed. | |
Re: This program doesn't calculate distancem when p is pressed. Try moving line 24 outside if statement. | |
Re: Also (rdecimal % 1 != 0) is always false. Maybe you should try parsing the number, for example: [CODE] int posdot; int wyn=0; char c; while(c=cin.get()){ if (c=='.') posdot=i; else if(c<='9'&&c>='0') wyn=wyn*10+c-'0'; else break; } [/CODE] | |
Re: You are just defining global const double variables. You need to use the same syntax as in methods, ie. const double A::member=3.0 . | |
Re: I think first of all you should buy new keyboard. In programming it is really important not to miss letters in words, and with your current equipment I see it is impossible. Or maybe you just write in such manner, but I don't suppose anybody would ask for help with … | |
Re: In line 13 you mustn't add lowest and index variable should be integer (you could get some nasty rounding errors, maybe not in this example, but also it will be faster). This is not so important, but random_integer is bad variable name. You can also look into [url]http://www.boost.org/doc/libs/1_45_0/doc/html/boost_random.html[/url] , it … | |
Re: rand()%2 is not guaranted to generate random number. Try something like rand()/((RAND_MAX+1)/2). | |
Re: Have you looked at this: [url]http://www.microsoft.com/downloads/en/details.aspx?familyid=2204a62e-4877-4563-8e83-4848dda796e4&displaylang=en[/url] ? (I didn't but I think it is what you were looking for). Most of major languages is capable of doing infinite number of things, main difference is in easy of programming (for specific task) /speed of program. From my experience python is quite … | |
Re: First of all, the compiler knows only about functions in object class definition. In your try it will just recursively call Object::findIntersection (or would call it if you use this->findIntersection). But you can declare function as virtual, then function call will be resolved during the runtime. Google some more info … | |
Re: Maybe use sprintf, thanks to it you can have digits in char table. | |
Re: Libreoffice is just rebranded OpenOffice with some additional patches from goOO (most of them are already in ubuntu version of OO) | |
Re: You can't call non const functions on const objects. You can declare const function by adding keyword const at the end of declaration, for example bool cmp(const Obj& snd) const. //nevermind, didn't see later code | |
Re: [url]http://en.wikipedia.org/wiki/Polyglot_(computing[/url]) ? | |
Re: You can try using vector.begin() as a pointer to a first element of table and use it as normal char* (but I didn't test it). You can make your function declaration fun(vector& v) and use it fun(v). //edit: you can't pass iterator as pointer, but &*vector_name.begin() should work | |
Re: vector<>(int n) constructs n objects, so above code is wrong, employees.size() is 10. The difference between push_back and default constructor is most of the time negligible. | |
| |
Re: Cin doesn't read characters after number. Try using cin.ignore after cin>>. | |
Re: I don't think conio.h is depraceted. I don't know other simple Windows terminal library, and in standard libraries you have only reading and writing to streams. You can use cin.get() instead of getch, but it doesn't exactly do the same. And how do you want to do clrscr() in standard … | |
Re: Double has precision close to 10^-16, your weird results are caused only by this. You also lose precision on every addition, specially in Trap function (that's why for n=10^10 you get e=10^-5). | |
Re: [QUOTE=Excizted;1090296] Hey Narue :), I'm just wondering, what difference does your example there have to this, without const? [CODE]int getx(){ return x; }[/CODE] [/QUOTE] Without const you could change x, for example std::swap(a.getX(), a.getY()). | |
Re: drawboard() is writing to standard input, and is returning void, so you can't print result to file. If you change function void Game::drawboard(void) to get reference to ostream, you will be able to print board on screen and to file. PS: Why do you flush cout so much? | |
Re: ('r' || 'p')==1 You need to change approach to this problem, || is just logic or. | |
Re: Try to [B]return[/B] some value. Compiling with -Wall is helpfull. ![]() | |
Re: IIRC enemies is 2d array of Enemy. To compare in this way, you need to declare array of pointers to Enemy(dirty solution), initialized to null. Of course you need to remember to delete every not needed enemy etc and change every function, which use enemies. You can also make state … |
The End.