The Big Programming Thread - Page 480
| 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. | ||
|
Manit0u
Poland17496 Posts
| ||
|
nunez
Norway4003 Posts
edit: you can just use auto i think. integer types round down(right?). alternatively you could enforce the 'default constructibleness' (LOL) with a static assert like so: template<class T> if you are commited to size_type, you gotta use typename ...::size_type, since the type is dependant on the template. | ||
|
Manit0u
Poland17496 Posts
93:35 note: mismatched types `const std::basic_string<_CharT, _Traits, _Alloc>` and `void` And I'm getting a wall of weird errors, mostly relating to ostream and not being able to convert from void to different chars. What should I do about it? | ||
|
nunez
Norway4003 Posts
| ||
|
nunez
Norway4003 Posts
however the printing is done internally in your display function, so you don't have to. intStack.Display();would do the trick instead of std::cout<<intStack.Display(); nitpick on your interface is that getMean, getSum and Display should be const functions. | ||
|
Manit0u
Poland17496 Posts
On May 15 2014 06:33 nunez wrote: the Display functions return value is void, so you can't pass the result to std::cout's << operand. however the printing is done internally in your display function, so you don't have to. intStack.Display();would do the trick instead of std::cout<<intStack.Display(); nitpick on your interface is that getMean, getSum and Display should be const functions. Doh... That's what you get for trying to do stuff for fun after an entire day of looking at some completely different and unrelated code... Edit: There were a couple more errors. Didn't make stuff const because the compiler was complaining a lot and I really don't have time or strength for it today. Anyway, here's a working program if anyone needs anything like that in the future: + Show Spoiler +
| ||
|
Shield
Bulgaria4824 Posts
http://www3.ntu.edu.sg/home/ehchua/programming/cpp/cp3_OOP.html | ||
|
netherh
United Kingdom333 Posts
On May 15 2014 07:27 darkness wrote: Why do methods start with a capital letter? I've checked some C++ code, and all start with a lowercase letter such as here: http://www3.ntu.edu.sg/home/ehchua/programming/cpp/cp3_OOP.html C++ doesn't have fixed style rules / guidelines: median() Median() get_median() getMedian() GetMedian() Take your pick. | ||
|
Shield
Bulgaria4824 Posts
On May 15 2014 09:05 netherh wrote: C++ doesn't have fixed style rules / guidelines: median() Median() get_median() getMedian() GetMedian() Take your pick. Well, that's bad for C++ then. However, (some of) C++ STL methods start with a lowercase letter. So why don't you follow the standard? | ||
|
Nesserev
Belgium2760 Posts
| ||
|
WolfintheSheep
Canada14127 Posts
On May 15 2014 09:26 darkness wrote: Well, that's bad for C++ then. However, (some of) C++ STL methods start with a lowercase letter. So why don't you follow the standard? There is no universal standard. There is only "currently accepted standards" which seem to change every decade. And C++ spans basically very age of coding standards. That means Pascal and Camel case, underscores in variables/methods, underscore prefixes for private, and on and on and on. | ||
|
Frudgey
Canada3367 Posts
Basically I want to know where I can find any information about running a particular python program over multiple computers. I guess to be more clear, I'd want multiple computers running the same program at the same time. One computer is capable of running the program just fine and it doesn't take very long, but I'd be able to collect data much faster if I could have several computers crunching numbers into the program at the same time. I'm not sure if I'm describing what it is exactly that I want to do in the right way, so if you have any information that you think might be remotely helpful, or if you could point me in the direction to find said information that'd be much appreciated. Thanks! | ||
|
phar
United States1080 Posts
https://wiki.python.org/moin/ParallelProcessing http://blog.cloudera.com/blog/2013/01/a-guide-to-python-frameworks-for-hadoop/ | ||
|
Cyx.
Canada806 Posts
On May 15 2014 10:20 Frudgey wrote: Do you guys know where I could find any information about running a .py file over multiple computers? Basically I want to know where I can find any information about running a particular python program over multiple computers. I guess to be more clear, I'd want multiple computers running the same program at the same time. phar's post is a good place to start... I just though having these three sentences one after another was a little overkill rofl | ||
|
sluggaslamoo
Australia4494 Posts
On May 15 2014 10:20 Frudgey wrote: Do you guys know where I could find any information about running a .py file over multiple computers? Basically I want to know where I can find any information about running a particular python program over multiple computers. I guess to be more clear, I'd want multiple computers running the same program at the same time. One computer is capable of running the program just fine and it doesn't take very long, but I'd be able to collect data much faster if I could have several computers crunching numbers into the program at the same time. I'm not sure if I'm describing what it is exactly that I want to do in the right way, so if you have any information that you think might be remotely helpful, or if you could point me in the direction to find said information that'd be much appreciated. Thanks! This would be much the same as doing merge sort algorithms over multiple cores I presume. Number crunching can mean a lot of things so you might have to be more specific. Basically some software have multicore capability built in, you will need to decipher these and learn how to code them manually, so that instead of doing multicore, you are doing multiprocessor. Basically there is almost no difference between the two except that data is transferred over the wire rather than exclusively inside the motherboard. After that it shouldn't be difficult at all, it would be like torrenting, each computer is given a piece of the pie to number crunch, and it all gets inserted into the final collection. This collection then does a basic sort using presumptions made by the smaller pieces to put everything in order very quickly. http://en.wikipedia.org/wiki/Merge_sort | ||
|
3FFA
United States3931 Posts
As part of this she wants us to check that this segment works properly: public DownloadInfo getDownloadInfo(String title) She told me to write the following in main to check it (unless I misunderstood / misheard) : DownloadInfo temp = music.getDownloadInfo("Pompeii");Any help with determining how to fix this would be great. Thanks guys ![]() | ||
|
Nesserev
Belgium2760 Posts
| ||
|
Amnesty
United States2054 Posts
On May 15 2014 06:06 Manit0u wrote: I guess I'm overthinking this...
93:35 note: mismatched types `const std::basic_string<_CharT, _Traits, _Alloc>` and `void` And I'm getting a wall of weird errors, mostly relating to ostream and not being able to convert from void to different chars. What should I do about it? This is not good design. Ideally, you wouldn't do this at all. A better design would not having them be members at all because they don't need to be. Then you can use whatever container you wanted too and It would just work. But of course, you cant do that because it would be a failing grade and you need to turn in poop. I had to cringe my way through programming courses before heh. First It asked for an array class. So make it an array class and not a dynamic array class (vector). You can't remove elements in your vector approach even though vector can do removes. You cant use the algorithms on it because you didnt provide the the standard iterator interface. Its hard to initialize. No constructors taking std::initalizer_list Don't make display functions member functions. That should be separated. It's hard here because you didnt provide a iterator interface.
First of all. The only member is a public data. No constructors, everything is public. This makes the class an aggregate type so you can use array initialization on it like you can on regular arrays making it more natural. Has iterator interface. Overloaded [] operator to make it similar to array. Here I made a member function called for_each. This is kind of a trade off. It technically does not need to be a member, because there is a global equivalent so this should scream bad design. But after using C# for a long time, i find the member function ForEach's much more readable when you can just pass it a lambda and turn a multi-liner into a one liner. And easier to read code screams good design.
Other thoughts
Having math functions return T is weird. If you have are working with an int's and you run averages and other statistical math functions on it usually you want the decimal places too. Returning float or double causes other problems. | ||
|
3FFA
United States3931 Posts
On May 15 2014 21:52 Nesserev wrote: First part of code should work as intended, I think. In the second part, you're calling temp.getTitle(), even though you just checked that temp == null. You should store the 'search string' ("Pompeii", "Jingle Bells") in a string first, and then reuse those to print the messages (or put the thing in one function, you're basically doing the same thing 2 times). Yes the first part does work, as I commented. 1) I can't put it in a function because she said I HAVE TO do it in main for this assignment. =/ 2) I don't understand why the second part doesn't work. How come calling temp.getTitle() again after checking that temp == null has any effect? 3) Why should I store the 'search string' in a string first?(Probably goes hand in hand with #2) Lastly, I want to make clear that this is to check whether or not the song titles were downloaded. Pompeii was downloaded, but Jingle Bells was not. | ||
|
Ben...
Canada3485 Posts
On May 16 2014 09:27 3FFA wrote: 1) I can't put it in a function because she said I HAVE TO do it in main for this assignment. =/ 2) I don't understand why the second part doesn't work. How come calling temp.getTitle() again after checking that temp == null has any effect? 3) Why should I store the 'search string' in a string first?(Probably goes hand in hand with #2) Lastly, I want to make clear that this is to check whether or not the song titles were downloaded. Pompeii was downloaded, but Jingle Bells was not. 1) That sucks. 2) Because you just checked if the title was null. In the case where it is null, trying to call the getTitle() function to print out that the title was not found will not work because the title doesn't exist in your temp variable in the first place. That is where your null pointer exception is coming from. getTitle() retrieves the title from the song object, but if the title doesn't exist, you can't exactly retrieve it to output it. In the case where it is not null, it will work as you expect. Don't worry, this is a common mistake people just getting used to OO will make. I made it a few times myself back when I was first doing stuff with classes. This leads to: 3) Since you cannot access the title from within your container of songs (because it is not in your container of music files), having a separate variable that stores the title is useful (for example, if your test fails, you can put System.out.Println(songTitle + " was not downloaded!")or something, rather than having to update the error message every time). This will allow more flexibility for your program (if you continue on with CS you will find that having programs that are flexible and can handle many situations are quite useful, and usually expected in assignments). If you replace each time you filled in "Pompeii" and "Jingle Bells" that with a variable storing a song name (just update the variable between songs. IE: String songTitle = "Pompeii"; ), then you can search for whatever the title you need while only having to update one variable. Ideally, you would create a boolean search function that would return true if the song was found, but it doesn't sound like that is allowed according to your post and the link you provided. Also, small nit-pick on your comments. You should not use "return" to describe things unless you are actually returning something. In the case of your comments about the if statements, you should use something like "evaluates false" rather than "returns false", since the boolean expression inside the if statement is evaluating whether or not the statement is true, and isn't technically returning anything. It's a small technicality, but it makes it easier for others to understand. Hopefully I helped a bit. | ||
| ||
