The Big Programming Thread - Page 255
| Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
|
Blisse
Canada3710 Posts
| ||
|
supereddie
Netherlands151 Posts
On February 25 2013 01:50 nakam wrote: [MySQL] Lets say I have the following table *snip* I now want the sum of the score for each player at that date so that the result becomes: *snip* It's almost like a SUM(score) and GROUP BY playerid, datetime. How do I achieve this in MySQL? I know it is possible and very easy if I process this in php and I know how to do that, it's just that I'd like to do it with SQL if possible. You don't want a sum, you want a running total. Just use your favorite search engine on how to do a running total in MySQL. | ||
|
nakam
Sweden245 Posts
On February 25 2013 03:02 supereddie wrote: You don't want a sum, you want a running total. Just use your favorite search engine on how to do a running total in MySQL. That's it! Searched like crazy but I couldn't figure out what it was called in english. Thx. | ||
|
Sky101
United States1758 Posts
| ||
|
Shield
Bulgaria4824 Posts
On February 25 2013 02:18 Kambing wrote: Assuming that you are generating this sequence in a loop, this is an example of a fencepost loop. Your for-loop likely looks like this:
This generates the former sequence rather than the latter sequence. You can think of the for-loop as a stamp that repeatedly generates "number(space)". The trick is to recognize that this stamp cannot possibly generate the form on its own because of the special case at the end which has no space. Your only recourse is to factor this special case out of loop:
This is called a fencepost loop because the problem is analogous to laying down fenceposts and wire.
There is one extra fencepost (n+1 overall) that you must account for when using n pieces of wire. The code ends up being easier to read if, rather than special casing the last post, you special case the first post and change the pattern accordingly:
Thanks. I ended up with using a temp variable to achieve the same result. ![]() I'm slowly but surely starting to understand C a bit more on the other hand. Pointers make more sense to me now. Also heap too. | ||
|
waxypants
United States479 Posts
On February 25 2013 01:01 Arnstein wrote: Is this true? I thought indexing started at number 0? So by creating [1][1] you get index 0 and index 1; 2 indexes? Also, I seem to have misunderstood operator overloading syntax. This is added to the previously seen code: + Show Spoiler +
This doesn't give any compiler errors, but it does give a warning since I don't have a return on the +operator. Also, when I test it by making two matrices, a and b, then c = a+b;, I get this: + Show Spoiler + Program received signal: “EXC_BAD_INSTRUCTION”. sharedlibrary apply-load-rules all warning: Unable to restore previously selected frame. warning: Unable to restore previously selected frame. warning: Unable to restore previously selected frame. warning: Unable to restore previously selected frame. (gdb) When you declare an array, you give its size. This is different from indexing. If you want it 2x2 in size, you give [2][2]. Treat "warnings" as errors unless you perfectly understand why there is a warning and why it doesn't matter (you should probably try to clean up all warnings anyway though). The + operator takes in two matrices and returns a result matrix. Clearly you are not doing that (and you recognize it), so how do you expect it to work? I believe the correct thing is to create a new matrix "Matrix2x2 result;" And use result.setValue to initialize it, and then return result. I'm not 100% sure about this though because I don't really program much in true C++, but I think it will set your variable "c" to a shallow copy of the result, which sounds like what you would want. edit: Someone please tell me if I'm right or wrong, but I believe for more complex classes (ones that allocate memory), you would need to implement a destructor and copy constructor. And in that case, +operator would invoke the copy constructor to copy result to c (in the c = a + b example) and then call the destructor on result. | ||
|
obesechicken13
United States10467 Posts
On February 25 2013 06:22 Sky101 wrote: Is anyone familiar with the Magento platform? I could use some help, your time will be compensated, please pm me, thanks! Not familiar. Played around with it. Should be easy to work with for simple stuff with no coding background. | ||
|
Blisse
Canada3710 Posts
On February 24 2013 22:35 Arnstein wrote: + Show Spoiler +
I get really many errors on this one. Why doesn't this work? Okay so I'll just point out some stuff. I could be completely wrong, but I do not believe it is possible to access with a double like that. Even from logic, since doubles aren't ever the same number twice, it doesn't seem to make sense, unless there's some auto-correction going on. Your setValue function should take the arguments, (int, int, double) thus. Similarly, your getValue function should take the arguments (int, int). You should also be using [2][2] for your matrix size. That will properly initialize a 2x2 array. From what kambling mentioned in the previous page, your print has an extra space because you don't handle the syntax there well at all. You can follow his method, but really, since your array is so small, unless you have plans to make it scalable, you should just write it in two lines of std::couts. Similarly, if you have plans of making it scalable, in the class constructor use the nested for loops instead of hard-coding it. (edit: technically you can't really make it scalable, so I mean in the copy&paste sense, haha) You may want to implement a destructor for your class that simply deletes the array (Matrix) you have. Not really necessary because it is really small, but it is a good habit to take note of. And finally, like AKnopf mentioned, while your syntax is technically correct, you should always be using this->member or this.member when accessing member variables or functions, because this clears ambiguity at times when you're debugging, like now. On February 25 2013 11:33 waxypants wrote: When you declare an array, you give its size. This is different from indexing. If you want it 2x2 in size, you give [2][2]. Treat "warnings" as errors unless you perfectly understand why there is a warning and why it doesn't matter (you should probably try to clean up all warnings anyway though). The + operator takes in two matrices and returns a result matrix. Clearly you are not doing that (and you recognize it), so how do you expect it to work? I believe the correct thing is to create a new matrix "Matrix2x2 result;" And use result.setValue to initialize it, and then return result. I'm not 100% sure about this though because I don't really program much in true C++, but I think it will set your variable "c" to a shallow copy of the result, which sounds like what you would want. edit: Someone please tell me if I'm right or wrong, but I believe for more complex classes (ones that allocate memory), you would need to implement a destructor and copy constructor. And in that case, +operator would invoke the copy constructor to copy result to c (in the c = a + b example) and then call the destructor on result. Yes, you are right about the sizes, but I don't believe the copy constructor is required. I don't think Arnstein is really clear in what he wants to do with this overloaded operator. What you've done is created a new matrix (with incorrect sizes), then you attempt to set values in this matrix to the sum of the two matrices you've put as arguments. But then you do nothing with this final matrix as matrix you created is not returned, and it doesn't modify the class matrix either. So nothing happens, and you should be getting array out of bounds errors. Except your overload function has incorrect syntax. You want
I'm also going to say I'm not sure why you're using pointers to classes in your arguments. I don't think that's necessary (or valid). | ||
|
waxypants
United States479 Posts
On February 25 2013 12:50 Blisse wrote: You may want to implement a destructor for your class that simply deletes the array (Matrix) you have. Not really necessary because it is really small, but it is a good habit to take note of. ... I'm also going to say I'm not sure why you're using pointers to classes. I don't think that's necessary (or valid). I'm quite sure you don't need a destructor for this class because it doesn't allocate any memory. There is no "may want to implement a destructor", you either need one to delete some extra stuff or you don't. Of course you can use pointers to classes. "this" is a pointer to the current instantiation of the class whose instance method you are in. | ||
|
Blisse
Canada3710 Posts
On February 25 2013 13:08 waxypants wrote: I'm quite sure you don't need a destructor for this class because it doesn't allocate any memory. There is no "may want to implement a destructor", you either need one to delete some extra stuff or you don't. Of course you can use pointers to classes. "this" is a pointer to the current instantiation of the class whose instance method you are in. meh, might as well have thrown it out there. I'm rusty on my C++ and I'm not sure if you really need to or not without invoking new. Wait nevermind that was dumb. Scratch thattt. | ||
|
Arnstein
Norway3381 Posts
On February 25 2013 12:50 Blisse wrote: Okay so I'll just point out some stuff. I could be completely wrong, but I do not believe it is possible to access with a double like that. Even from logic, since doubles aren't ever the same number twice, it doesn't seem to make sense, unless there's some auto-correction going on. Your setValue function should take the arguments, (int, int, double) thus. Similarly, your getValue function should take the arguments (int, int). You should also be using [2][2] for your matrix size. That will properly initialize a 2x2 array. From what kambling mentioned in the previous page, your print has an extra space because you don't handle the syntax there well at all. You can follow his method, but really, since your array is so small, unless you have plans to make it scalable, you should just write it in two lines of std::couts. Similarly, if you have plans of making it scalable, in the class constructor use the nested for loops instead of hard-coding it. (edit: technically you can't really make it scalable, so I mean in the copy&paste sense, haha) You may want to implement a destructor for your class that simply deletes the array (Matrix) you have. Not really necessary because it is really small, but it is a good habit to take note of. And finally, like AKnopf mentioned, while your syntax is technically correct, you should always be using this->member or this.member when accessing member variables or functions, because this clears ambiguity at times when you're debugging, like now. Yes, you are right about the sizes, but I don't believe the copy constructor is required. I don't think Arnstein is really clear in what he wants to do with this overloaded operator. What you've done is created a new matrix (with incorrect sizes), then you attempt to set values in this matrix to the sum of the two matrices you've put as arguments. But then you do nothing with this final matrix as matrix you created is not returned, and it doesn't modify the class matrix either. So nothing happens, and you should be getting array out of bounds errors. Except your overload function has incorrect syntax. You want
I'm also going to say I'm not sure why you're using pointers to classes in your arguments. I don't think that's necessary (or valid). You are right, I have no idea what I'm doing, haha! I'm not good with overloading, as this is the first time I see it! Also, how am I supposed to use this? The book we use(Absolute C++) is usually pretty clear, but I didn't like the overloading chapter in it. I've update my code now, and in the bottom you can see how I try to use operator overloading, that is wrong. + Show Spoiler + /* | ||
|
WindWolf
Sweden11767 Posts
On February 25 2013 16:30 Arnstein wrote: You are right, I have no idea what I'm doing, haha! I'm not good with overloading, as this is the first time I see it! Also, how am I supposed to use this? The book we use(Absolute C++) is usually pretty clear, but I didn't like the overloading chapter in it. I've update my code now, and in the bottom you can see how I try to use operator overloading, that is wrong. + Show Spoiler + /* Just a tip from another ESL coder. Name files with English names for the sake of consistency. It will make your life easier in the long run since all code "is in English". | ||
|
Arnstein
Norway3381 Posts
On February 25 2013 16:39 WindWolf wrote: Just a tip from another ESL coder. Name files with English names for the sake of consistency. It will make your life easier in the long run since all code "is in English". Thanks, will do this from now on! Also, any tip you guys can give me, please do! I want to become a good programmer! ![]() | ||
|
nunez
Norway4003 Posts
On February 25 2013 17:00 Arnstein wrote: Thanks, will do this from now on! Also, any tip you guys can give me, please do! I want to become a good programmer! ![]() they just want to be able to reverse engineer your code more easily! obfusk8 your cøde to the max. you might want to do a re-read on reference, de-reference operators and this keyword. this line looks a bit faulty! double x0 = this.getValue(0,0) + &other.getValue(0,0); | ||
|
Arnstein
Norway3381 Posts
| ||
|
nunez
Norway4003 Posts
On February 25 2013 17:36 Arnstein wrote: Yes, that's the line that is messing up! I don't know how to do this inside of a operator overload function, so I just copied some stuff from the header in the class, and also tried to copy something from the book. In the book you had leftHandSide and rightHandSide, but it didn't seem like these were declared. Then how does C++ know which one they mean? i am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question! you've got all the info you need to solve that exercise lined up in just the right order the institution you are attending deems best. i think you need to trace back a couple of exercises and make sure you understand what the words in the code you are compiling mean (in this context)! | ||
|
Arnstein
Norway3381 Posts
![]() | ||
|
Savi[wOk]
United States81 Posts
Since computers are made out of code, why don't windows computers come with something like a "C compiler"? I heard that the Commodore 64 and the Atari 8-bit came with compilers. It feels like buying a music sequencing software, and all you can do is listen to music, put together loops, and insert samples. While being unable to compose your own music. | ||
|
adwodon
United Kingdom592 Posts
On February 25 2013 20:35 Savi[wOk] wrote: Out of curiosity. Since computers are made out of code, why don't windows computers come with something like a "C compiler"? I heard that the Commodore 64 and the Atari 8-bit came with compilers. It feels like buying a music sequencing software, and all you can do is listen to music, put together loops, and insert samples. While being unable to compose your own music. Computers aren't made out of code... ![]() Commodore 64 and Atari 8-bit were before the internet, where you can go online and download visual studio express for free and write / compile programs with a nice IDE. Then there are all the other compilers you can get like gcc in MiniGW, also for free. Considering most users have no use for a compiler, and those who do are going to know how to download it, it doesn't make sense to bloat an already bloated OS with additional features like this considering it would require a full installation of VS, or microsoft to make MSBUILD separate, which makes no sense because you just get something like MiniGW if you want to do something like that. For something like Linux it makes sense to have compilers on it, its generally only used by devs / serious tech heads who are significantly more likely to use it. Plus you do more stuff on the command line in linux so having a compiler you can use on the command line is useful and keeping with how people use the OS, plus its open source so making a full suite like VS would be impossible. | ||
|
AmericanUmlaut
Germany2581 Posts
On February 25 2013 20:52 adwodon wrote: Commodore 64 and Atari 8-bit were before the internet, where you can go online and download visual studio express for free and write / compile programs with a nice IDE. Also, back in those days, writing the code that ran on your hardware was a very common way of interacting with a computer. In those days, for example, it was common for a computer magazine to come with a game in it in the form of code to be copied by hand and compiled. Now general-purpose commercial software is available to do every common task, and writing code is a very rare way of interacting with a computer. | ||
| ||

