- Strength to Increase Rep
- +11
- Strength to Decrease Rep
- -2
- Upvotes Received
- 152
- Posts with Upvotes
- 134
- Upvoting Members
- 84
- Downvotes Received
- 4
- Posts with Downvotes
- 4
- Downvoting Members
- 2
Mathematical software developer
- PC Specs
- Windows 7 Visual Studio 2013
466 Posted Topics
Re: I think that you should probably think about indenting your code a little, so that the various blocks are a bit easier to pick out. Also, I think that it's generally best to have [icode]main()[/icode] return [icode]int[/icode] rather than [icode]void[/icode], that way you can check the return value of the … | |
Re: You have mixed up the way your variables are used in your functions. For instance you call [icode]toOctal[/icode] on line 19 without any arguments, but [icode]toOctal[/icode] take a [icode]long int[/icode] argument and the way they are used in the function will give you an infinite loop! The function [icode]toHex[/icode] also … | |
Re: Hmm, what you have shown here are three *functions* or *methods* from a class. Two of the methods are used in the setup of your output (`setOutputStream` and `setMessageCallback`) and the other (`outputMessage`) is used to actually output the things that you want to output. You haven't given much code … | |
Re: [QUOTE=Tomi1988;1532016]I don't know. What is the solution?[/QUOTE] The solution is to write your own arbitrary precision integer version, which isn't as complicated as it sounds. | |
Re: > i thought of the boolean route but i dont know how to implement it. I cant even get the Part 1 to work Think about what are the biggest and smallest numbers that have six digits, all valid pass codes must be between these two values, right :) | |
Re: I reckon that you'll get rid of some of your compilation errors by correcting lines like this: if (head == NULL >> tail == NULL) I think that you just want something like: if ( ! head && ! tail ) | |
Re: OK, you're current program is not going to do what you want it to at all. If I were you, I'd start by looking at the question more carefully and breaking it down into a number of small parts. So, the question is: [quote]write a c++ program that given the … | |
Re: Use std algorithms where possible: #include <string> #include <algorithm> // Store the password in a string std::string password; /* Do things to get password from user */ // Count the upper and lower case letters size_t upper_case_count = std::count_if( password.cbegin(), password.cend(), std::isupper ); size_t lower_case_count = std::count_if( password.cbegin(), password.cend(), std::islower … | |
Re: There is a school of thought that says that you should not really design your class such that you're having to actually do things that could fail in the constructor. You should instead "inject" the things that the class needs directly into the constructor, which should simply be a thing … | |
Re: > `for(int i=0;i<10;std::cout<<i++<<std::endl); Yikes! Don't write code like this :) In general, tricks in code made code unreadable in the long-term. I think it's a reasonably good rule that one should *never* write a loop unless if can't be avoided. I have a hierachy of things that one should try … | |
Re: You can do it with a single array and a single value of the type in the array (an `int` in your case). Use the single value as a temporary to swap the first and last elements and then the second and penultimate elements and so on. Or, you could … | |
Re: I agree with the comments so far that you probably need to explain what it is that you're trying to acheive when writing this code. All these raw pointers are generally not necessary in modern C++. Further to what Decepticon said about your assignment operator, your programm `main` looks like … | |
Re: You want it to "work better" how, exactly? Are you looking for general code standards tips, hints on using more C++-like paradigms? etc... | |
Re: You can check for even numbers using the `%` operator on an `int`: int even = 2, odd = 5; std::cout << "even: " << even % 2 << " odd: " << odd % 2 << std::endl; any even number will return 0 when you do `% 2` to … | |
Re: I notice that you're making a vector of vectors of doubles. Are you planning to use this like a matrix to do algebra on and such? Or, are there other constriants (all the "rows" have to be the same length, or something)? If these things are true, then you might … | |
Re: Even broken up into individual little programs, I don't think these will even compile. Probably best to get them compiling first and go from there. Efficiency is not your biggest issue right now. If you don't know how to do that, then ask questions about the errors that occur when … | |
Re: You can open any file and access the bytes in it. However, making sense of those bytes is much more difficult in the case of something like an mp3 or jpg file. You'll probably want to use an external library for that... | |
Re: I think that you need another `for` loop inside the `count` function, which will go over the array of random numbers and count each value. You should also use more descriptive names for the arguments to the `count` function; so `x` and `n` should be something more like `values` and … | |
Re: I think that you could do something like point 2 using Zero Install, or something similar. Although, I'm not sure that I want things auto uninstalling! Zero Install might allow a more dynamic installation of programs (as well as a more traditional model). In regard to point five, I think … | |
Re: Hmm, I'm not sure what your original question is asking exactly. I do have some comments on your snippet though. 1. If you use `QList` to hold stuff, then the `QList` is actually holding pointers to the stuff for you. So, if own the objects in the list, then you … | |
Re: Just a comment, but if you have an array of strings, you can iterate through them with one of the std algorithms to count the ones that you want. So, to count the number of "hello" strings, you can simply do: auto number_of_hellos = std::count( S.cbegin(), S.cend(), "hello" ); It's … | |
Re: What compiler are you using? It might be helpful if you posted the error message that you're getting (or at least the first couple of errors that you get) :) | |
Re: You can't do this: tmm += ("Minutes: " + tmm); th += ("Hours: " + th); `tmm` is an `int`. What would it mean to increment and `int` with the sum of a character array and an `int`?. There are probably a bunch of other things wrong with this code … | |
Re: What code do you have as your attempt at this problem at the moment? | |
Re: have you tried adding some debugging output to your code? For example, print out the value of the indices and values that you're trying to swap in that inner if statement... | |
Re: You've definitely created logic of sorts for doing the tasks in the question, but the logic isn't *encapsulated* in any functions. The question definitely says that you should write *functions* to add data to the class room's attributes, etc. Also, you should avoid the use of `goto` in your code---you … | |
Re: I would say: - Don't use the macro version - Use the const int version if you plan to use the variables in arithmetic (your intentions are clear to the reader this way), I.e. if the numerical value of the thing is actually important to you. - Use the enum … | |
Re: I was basically really hungry for most of my early twenties. My housemates noted this and started calling me Ravenous. It seemed like a cool user name so I use it wherever I can. It's actually kind of common, so I also use Ravenacious (which I don't think is a … | |
Re: Does something like this do what you want? std::uint32_t Checksum = 0; std::uint32_t CheckSum2 = 0; std::uint8_t* Ptr = Pixels; int K = Width < 12 ? 1 : 12; for (int I = 0; I < K; ++I) //Start at 0 offset { for (int J = 0; J … | |
Re: who can help me when i shut down my window ,it show a massage which tell us .(waiting for background programme to close ).any advice would be appreciated .Thx all friend It's probably best to start a new thread if your question is totally unrelated to this thread, which your … | |
Re: Your problem is on line 225 of `gen_map`. It's quite a subtle problem that is causing a stack corruption. You need to change `map_g[yt][xt][1] = 1;` to `map_g[yt][xt][0] = 1;`, there's only one unit of z-dimension, so you can't access element `1` in this dimension. The explanation of why you … | |
Re: > Inhertance is very good concept in c and c++. I don't think that C has inheritance, only C++. You can simulate a kind of inheritance in C, but it's not pretty and the compiler can't help you detect coding errors that you've made. Here's an example of inheritance in … | |
Re: Same thing again. `sign != 'Q' || sign != 'q'` is *always* going to be `true`, you want ANDs there... | |
Re: To get a better understanding, the task >b. write text to that binary file Does that mean that you have to read in the text file and then write the text into a new file, which is a binary file? Or, does it mean that you have a pre-existing binary … | |
Re: >Once the results were calculated, it would then move to excel to show the results I think that you should try to move away from the idea that your program should *automatically* open Excel to display the results. There are a number of issues with this approach. For example, I … | |
Re: >This is what i have so far im new to this site This doe not appear to be C++. Do you have any C++ for this logic? If so, you should post that with some explanation as to what goes wrong when you try to build & run it. | |
Re: The best thing that you can do is to think of your own project. You can do basically anything in C++, so you have a wide range of areas that you can choose from. Some things are easier in C++ that others. I work in mathematical modelling, so I find … | |
Re: The [GNU Radio wiki](http://gnuradio.org/redmine/projects/gnuradio/wiki) has some documentation that might be useful to you. | |
Re: When printing out the array backwards, you don't need to read from the file again, since you've already stored the values in the array. You have also done something odd with the curly braces, so that I'm not sure that the loop is doing what you want it to. So, … | |
Re: > I tried to change the type to double, and print out without decimal part, it can deal with larger numbers than unsigned long. Maybe this is the best? `double` isn't magic though. A number like 100,000,000,000,000,000 (or 10^17) will not be represented *exactly* as a `double`. It will be … | |
Re: From the image you posted, you've got a `std::bad_alloc` exception being thrown, which can't be a good thing. I'd find out where that's comming from. One possible source of that exception is that the loop isn't finding the node that you're asking for. If this means that you reach the … | |
Re: I think it means that the functions of `Set` should call the functions of `Vector` to do their tasks. For example: bool Set::IsEmpty() { return V->IsEmpty(); } | |
Re: This is slightly confusing. I assume that `sizeof( BYTE )` is 1, but the value `0x9100` is at least two bytes big? Also, the size of `myKey[ 10 ]` is going to 10, so that isn't expressed by `0x9100` either. I think that you can do what you want to … | |
Re: You have to be careful when using iterators to vectors. When you call `push_back` on line 59, the vector has to grow by one element. If the capacity of the vector isn't sufficient to hold the new element, then the vector will re-allocate memory to accomodate the new element. Since … | |
Re: As mentioned by tinstaafl, you can do it `std::find_if`. To do this you will need a function that returns `true` when you hit the element that you want. Say your struct is called `A` and has a member `x`: struct A { int x; }; You need to define a … | |
Re: Are you allowed to use `std::string` and/or `std::vector`? If so, you can use `getline` to read each line into a `std::string` and add them to a `std::vector`: std::vector< std::string > grid; std::string line; while ( true ) { getline( file, line ); if ( line.empty() ) break; grid.push_back( line ); … | |
Re: You could have some 'padding' around your array. So, use a 5-by-5 array instead of 3-by-3. Then, just ignore the values of the elements in the first and last rows and columns. Alternatively, you can have an array of pointers to updator functions that is the same size as you … | |
Re: >It's not leaking the old memory from s2. When the object goes out of scope, i.e. cannot be referenced or be reused in your program (or to be "revived"), the destructor is called automatically, thus freeing the memory of the s2 pointer. I'm afraid you have mis-understood how memory managerment … | |
Re: This doesn't work like you think it does. You never initialise the pointer `m_p` to anything. Also, on line 17 you leak the memory that you `new` on line 16. And I think that line 18 will the cause a stack corruption or segfault or something. Here's what your code … | |
Re: I think that you should make a distinction between the question's ID and its number in the test. I would make the ID constant throughout the life of the question, but allow the number to change. You could do this by having a `GenerateQuiz` (or similar) function that goes through … |
The End.