- Strength to Increase Rep
- +9
- Strength to Decrease Rep
- -2
- Upvotes Received
- 59
- Posts with Upvotes
- 49
- Upvoting Members
- 48
- Downvotes Received
- 2
- Posts with Downvotes
- 2
- Downvoting Members
- 2
I am the lord of the wind.
147 Posted Topics
Re: Are you familiar with functions? If not, it's a good time to start learning about them. As pointed out by others above, breaking the task into smaller steps helps a lot. So, let's focus on building a line first. Take a look at these lines: 122222221 123333321 123444321 There is … | |
Re: > Less overhead Not really. I don't know what compiler you're using, but any decent one would seize the opportunity to perform [tail call optimization](http://en.wikipedia.org/wiki/Tail_call) in np complete's code, and generate output **identical** to the one corresponding to an iterative implementation. > easier to read I think this is the … | |
Re: You can always use the C version of ostringstream -> [url]http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/[/url] | |
Re: Careful! The relevant threads in the Software Development and Web Development forum categories are not sticky! Or at least that's what I see...  | |
Re: >I fixed it. i downloaded the dll from a website and added it to my bin folder. Downloading dlls from random sites is not a very wise thing to do. You never know what kind of code these dlls may contain. I'm talking about security issues. Your pc could as … | |
Re: > Ok so what i was thinking was add the nodes in sequence. so the text file would be Does it have 4 legs? Does it purr? Cat Dog Does it swim? fish What you do here is called printing the tree using [preorder traversal](http://en.wikipedia.org/wiki/Tree_traversal#Depth-first_traversal). > Does this **require** recursive … | |
Re: > There are no tests what-so-ever in your code. Yes, there are. They are inside the [strncpy](http://www.cplusplus.com/reference/clibrary/cstring/strncpy/) and [strncat](http://www.cplusplus.com/reference/clibrary/cstring/strncat/) functions. > I've had some people say to do result_maxlength-1 They are right. In your first `concat` call, this -> `result[result_maxlength] = '\0';` turns to -> `c[5] = '\0';`. You're going … | |
Re: I have a couple of questions: What happens if you increase the number of calculations you have to make per iteration? Are you sure you're timing the hardcoded approach properly? What optimization flags are you using? Check this out: #include <windows.h> #include <iostream> #include <algorithm> #include <vector> using namespace std; … | |
Re: > I was thinking about somehow using a static member that all the matrix cells will be defined by their value + the static value. This is a very interesting idea. It also is easily generalized. You could have a stack of (different) operations and apply them in order when … | |
Re: cin is fine too. What you need to do is clear your stringstream's buffer and state before you use it again. Either add this here -> `ss.str(""); ss.clear();` before using ss or create ss right before you use it. Also, the condition in your if statement should be `!ss || … | |
Re: Now, let's add some [basic AI](http://ideone.com/2ND3o). Nothing too serious, just a simple, suboptimal (you could use the [KMP algorithm](http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm) to improve it), history matcher. It searches the user's previous moves for recurring patterns and uses this information to predict the user's next move. For anyone interested in more advanced stuff, … | |
Re: > `num = ((-b) + sqrt(b*b-4*a*c))` > `den = (2*a)` It's unlikely that `sqrt(b*b-4*a*c)` will be an integer (or even a rational number). A better approach would be something like this: ... p = -b q = b*b-4*a*c r = 2*a ... print "x = (" print p print " … | |
Re: [Looks](http://ideone.com/9pjS4) like [Perl](http://www.perl.org/) to me. | |
Re: Or better yet, vectors, since the number of lines in the file is not known during compilation. #include <iostream> #include <fstream> #include <vector> #include <string> using namespace std; int main() { ifstream fin("main.cpp"); vector<string> lines; string curLine; while (getline(fin, curLine)) lines.push_back(curLine); for (size_t i = 0, size = lines.size(); i … | |
Re: >I wonder which is better :to start learning a new programming language or develop my skills in the C++ language ? Both have advantages. What you should do depends on several things. One of these things is what is it that makes you face this dilemma. Do you have some … | |
Re: There is a problem with the logic you use to generate the random indexes. Let's start with something simpler. Suppose you want to get three unique random values from a unidimensional array of four elements. The easiest way to do this is by using [random_shuffle](http://www.cplusplus.com/reference/algorithm/random_shuffle/): #include <iostream> #include <string> #include … | |
Re: >im thinking of a game in the Command Prompt Read [this](http://www.cplusplus.com/forum/articles/28558/) first. IMO, the thing with the best result-to-effort ratio you can do right now is grabbing a graphics library (e.g. [SFML](http://www.sfml-dev.org/)) and writing a simple [scrolling shooter](http://en.wikipedia.org/wiki/Shoot_'em_up#Types). And if you 're worrying about your artistic skills, don't. Computer software … | |
Re: ATB - Ecstacy -> [url]http://www.youtube.com/watch?v=1bVYgYW6410[/url] | |
Re: Here's an idea: #include <iostream> #include <string> template <class A, class B> struct SameType { static const bool Result = false; }; template <class A> struct SameType <A, A> { static const bool Result = true; }; template <bool C, class True, class False> struct IfThenElse; template <class True, class … | |
Re: > I've tried to do some research on this minimax thing, but I couldn't find anything helpful. How much did you search? I just googled **connect four c++ minimax** and I found this [video](http://www.youtube.com/watch?v=kHJRdHCSQLE) on youtube. In the description of that video, I found this [link](http://users.softlab.ece.ntua.gr/~ttsiod/score4.html), There, you can see … | |
Re: Judging by the way you use getline, `teamnamesquestion` must be a char array. The problem with this is that `teamnamesquestion == "no"` performs a pointer equality check, that will, obviously, always return false. If you don't believe me, try this: #include <iostream> using namespace std; int main() { char str[10]; … | |
Re: > You are missing endl or flush at the end of most of your output statements. This is a joke, right? It has to be a joke, because neither is it true nor does it have anything to do with the OP's problem. The OP's problem arises from mixing istream::operator … | |
Re: So, what you essentially want is **efficient calculation of [multinomial coefficients](http://en.wikipedia.org/wiki/Multinomial_theorem#Multinomial_coefficients)**. I googled that, and the first link I got was [this](http://home.comcast.net/~tamivox/dave/multinomial/index.html). | |
Re: > not all control paths return a value This means that you have code that looks like this: ReturnType load_image(ArgType1 arg1, ArgType2 arg2, ...) { //... if (some_condition) return something; // What happens if some_condition is false? // You don't return anything in that case... } > The first two … | |
Re: @OP: [Moschops](http://cplusplus.com/forum/beginner/72307/#msg385772) is right. I fixed these errors, compiled the code you posted and got the [expected output](http://zifda.wordpress.com/2011/12/16/morphing-pada-opengl/#more-331). | |
Re: > If you are writing a simple program that resembles a language interpreter, and it is capable of computing non-trivial equations of more than a fixed size, then you really are talking about writing an intepreter. You'll want to go the whole route of tokenizing and parsing the input, even … | |
Re: If you have to do it using sscanf, you could do it like this: #include <iostream> #include <cstdio> using namespace std; int main() { string path = "main/articles/animals/giraffe"; char * cPath1 = new char[path.size()]; char * cPath2 = new char[path.size()]; sscanf(path.c_str(), "%[^'/']/%[]", cPath1, cPath2); string path1(cPath1), path2(cPath2); delete[] cPath1; delete[] … | |
Re: I think you may be using the wrong language for this. It's certainly doable, but there are much better alternatives (at least on windows). One such alternative is [Autoit](http://www.autoitscript.com/site/autoit/). Here's an example that does what you want with notepad: $file = FileOpen("C:/in.txt") $line2 = FileReadLine($file, 2) Run("notepad.exe") WinWait("[CLASS:Notepad]") ControlSend("[CLASS:Notepad]", "", … | |
Re: You don't really need to understand how std::map works in order to understand how to use it. I have an idea. Let's ask the OP which version (s)he finds easier to implement / understand. This one -> http://ideone.com/ojv1H ? Or this one -> http://ideone.com/Vz9oh ? | |
![]() | Re: > Why not just create array as a large array? Say int array[1000]? While this would work if this is just homework, it's not a good idea in general, as it creates a huge security hole in the application. [Here](http://stackoverflow.com/questions/2039953/frame-pointer-program-counter-array-overflow)'s an interesting thread I found regarding that matter. > The … |
Re: It's impossible to pass a C array by value (see why [here](http://stackoverflow.com/questions/7454990/why-cant-we-pass-arrays-to-function-by-value)). If you want a function that can handle 2x2 and 3x3 and, in general, MxN arrays, you could use a function template. #include <iostream> using namespace std; void print2x2(int array[2][2]) { for (int i = 0; i < … | |
Re: Don't forget to get the debug privilege before opening a process other than your own. [Useful link](http://www.daniweb.com/software-development/cpp/threads/372173/how-do-i-search-for-a-memory-address-containing-a-specific-value-). Also, don't forget to close your handles once you're done (I forgot to do it...). [Another useful link](http://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx). | |
Re: [Here](http://zetcode.com/tutorials/javaswingtutorial/swinglayoutmanagement/)'s another good link. My personal favourite is the Box Layout: import java.awt.Dimension; import java.awt.Font; import javax.swing.*; public class Main extends JFrame { void init() { // we'll use a main panel and four row-panels JPanel basicPanel = new JPanel(); basicPanel.setLayout( new BoxLayout(basicPanel, BoxLayout.Y_AXIS)); JPanel titleRow = new JPanel(); titleRow.setLayout( … | |
Re: Oh, come on, guys, don't be so harsh. Let's help him get started... You could use two big sized arrays to represent your stacks. You'll have to also use two integers (initialized to zero) to keep track of each stack's current size. When you want to add a number to … | |
![]() | Re: What if you cast **rnd2** to an int? `ques.setText(questions[(int) rnd2]);` Note that you don't really need **Math.ceil** here. You could just do... `ques.setText(questions[(int) (Math.random() * questions.length)]);` |
Re: Obviously, this... for(int i = 0; i > nrEle ; i++){ for(int j = 0; j > nrEle; j++){ should be... for(int i = 0; i < nrEle ; i++){ for(int j = 0; j < nrEle; j++){ | |
Re: If you have to code this yourself, one way to do it would be to use the [inverse transformation](http://en.wikipedia.org/wiki/Inverse_transform_sampling) and [acceptance-rejection](http://en.wikipedia.org/wiki/Rejection_sampling) methods. I had to simulate normal distribution a while ago and that's how I did it: #include <iostream> #include <algorithm> #include <vector> #include <cstdlib> #include <ctime> #include <cmath> using … | |
Re: >I have a vector of doubles and I need to [...] write the contents to a **text** file. What's wrong with simply opening the file in text mode, iterating through your vector and outputing each double? **main.cpp** #include <iostream> #include <fstream> #include <vector> using namespace std; int main() { vector<double> … | |
Re: > I'm not sure how I would check if the values are 'parse-able' or not You could use a stringstream for that. First, get rid of the trailing whitespace characters in your input. Then, create a stringstream out of your input and use it to set your variable's value. If … | |
Re: You really should google more before posting. Look, I found a [thread](http://www.dreamincode.net/forums/topic/205131-about-bar-chart/) with a guy having the exact same code and a very similar problem to the one you're having. Considering the degree of similarity, I believe the replies he got should also be applicable to your case. | |
Re: > [...] The second should accept two arguments of type string (not C-string types) [...] Why do you use C-strings in your code then? > [...] Intuitively I would think template in C++ [...] You're right. Your maximum function template works fine for both doubles and std::strings. Also, as nullptr … | |
Re: It didn't work because you did something like this: while (numbersList >> type >> num1 >> num2) // you read a line here { Complex *object = new Complex(type,num1,num2); numbersList >> type >> num1 >> num2; // and then you read another line here cout << "For line number " … | |
Re: If you want to restrict input to integers in [1, 5], your while condition should be different. One way to do it is by using two relational operators and the logical OR operator. | |
Re: What if you make your get functions return references? vector<string> & getcoursename() {return coursename;} vector<double> & getmark() {return mark;} | |
Re: Actually, this is one of the things the OP, surprisingly, did right. I'm saying "surprisingly" because this is a very common mistake among beginners. Assuming... [CODE]string word; ifstream file("in.txt"); // in.txt contains a list of words[/CODE] ...what most beginners do when reading that file is this: [CODE]while (!file.fail()) { file … | |
Re: Geia sou Giannakh :D Kalws hr8es sto daniweb! Einai polu wraio na vlepw atoma apo thn patrida edw :) (translation ->) Hello, John :D Welcome to daniweb! It's very nice to see people from home here :) | |
Re: I have a couple of things to say regarding the base choice. In general, you'll want your base to be as big as possible, because this implies faster operations. However, there are other factors you should also consider, such as potential overflow during operations and conversion time from and to … | |
Re: Without optimizations, I get: [ICODE]0.078 seconds. 0.047 seconds.[/ICODE] With -O3 (best speed optimization) and after setting [ICODE]numberOfIterations[/ICODE] to [ICODE]1e9[/ICODE], I get: [ICODE]0 seconds. 3.297 seconds.[/ICODE] I use the version of mingw that comes along with the latest Code::Blocks. | |
Re: It shouldn't be too difficult. You could either create another function to display the polynomial or add a couple of cout statements in your current function. In either case, you'll probably need two for loops, an outer one that will iterate over f(x0), f[x0, x1], ..., f[x0, ... xn] and … | |
Re: Why do you want to specify the template parameters explicitly? I'm not really sure I understood what you want, so I'll just list a couple of things hoping one or two of them suits your needs. [CODE]#include <iostream> #include <vector> template <class T> class Simple { }; template <class T> … |
The End.