3,183 Posted Topics
| |
Re: Comparing floating point values for equality is also fraught with peril. You'd be better off converting them to strings and then doing the comparison. That way the not insignificant work of handling a precise representation of the value is deferred to the standard library. A "close enough" test is often … | |
Re: > That means the size of the array is unknown. That means you shouldn't be using an array. Use a List<> instead, unless this is a homework assignment where the whole point is to learn how to work with arrays. Though such an assignment seems silly since the Array class … | |
Re: Didn't you write it? Why would you need someone to explain to you how your own code works? | |
Re: > and change line 138 to use getchar(). That won't work because getchar() requires a newline to terminate input in the shell. getch() is used because it's a non-blocking input function. This is an appropriate usage of the conio library. > perhaps a while loop around lines 138-168 Yes. Basically … | |
Re: > How can I calculate CLOCKS_PER_SEC.. It is defined as 1000 in ctime. I don't want it defined. I want to calculate the actual value.. `CLOCKS_PER_SEC` is a standard macro, you can ignore it if you'd like, but you shouldn't redefine it. > So what is CLOCKS_PER_SEC and why is … | |
Re: > Now that I've converted the formula over to C++ it's not working out. It's the wrong formula. This is correct: bool is_leap_year(int year) { return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); } > if ( year % 4 … | |
Re: > What is the simplest way to do this? It's not a matter of simple or not, it's a matter of *possible* or not. If you're not given a size, can't assume a size, and there's no sentinel value marking the end of the array then you're shit out of … | |
Re: > Can any 1 please help me with it? What kind of help do you want? You clearly haven't done anything yourself, so it's hard to construe "help" to mean anything except "tell me the solution and how to code it". | |
Re: In lines 75-79, you unconditionally delete the head if it's the only node in the list. What if `id != head->st.id` in that case? As for successfully deleting the first node when it matches the id, consider adding another clause between lines 79 and 80 that handles a true deletion … | |
Re: > operand types are incompatible ("char" and "const char *") You should use the standard C++ string class. C-style strings are awkward, low level, and easy to get wrong (as evidenced by this thread). However, let's look at the problems in your original code, and ignore all of the wrong … | |
Re: > Now, there is no way to esure safety, and this is a potential unsafe operation.(if the pointer tries to access data from Derived) It's completely safe...because it won't compile. ;) > I feel i am missing something here. Why is there no way in C++ to ensure the safety … | |
Re: > What is the benifit to classes? They help with the organization of large projects. ![]() | |
Re: > also will the answer be same even i declare the array dynamically?? The results will typically be *worse* when accessing dynamically allocated memory out of bounds. | |
Re: Please ask a specific question. Guessing what kind of "help" you want will result in a lot of wasted time and frustration. | |
Re: > @AD: toupper() and tolower() seem to return int and not char. That's only to support an argument of EOF (in which case EOF is the return value). If you never expect to pass EOF, such as when it's a stopping condition prior to calling toupper() or tolower(), there's no … | |
Re: > delete CurrentNode; > CurrentNode = CurrentNode->pNext; This is the problem. You aren't guaranteed to have a valid pointer even immediately after deleting it. It could be reused just that fast, or more likely, invalidated for debugging purposes. The correct way to traverse and delete a linked list is with … | |
Re: > My problem is after change the value of Masked raider the jimmy changed,but when set jimmy = "not ok"; > Masked raider did not change,how to explain it? When you changed `jimmy` to "not ok", you pointed it to a *different* object (the string literal "not ok"). At that … | |
Re: > So any title regarding this field guys??? Why don't you figure out what the project will be, then devise an appropriate title? It baffles me how people can take *years* of college and still be unable to think of something as simple as a title. Did you learn nothing … | |
Re: You could build the array up manually using nested explodes: $fields = explode(',', 'Name: John, Age: 20, Phone number: 12343223'); $result = array(); foreach ($fields as $field) { $kvpair = explode(':', $field); if (isset($kvpair[0]) && isset($kvpair[1])) { // Both key and value exist (expected case) $result[trim($kvpair[0])] = trim($kvpair[1]); } else … | |
Re: What have you done so far? We require proof of effort before offering any help. | |
Re: Well, an obvious first attempt is to loop through the items in the listbox and not update your textbox if the random number already exists: xhiro = "1301" + numri; bool exists = false; foreach (var item in listbox.Items) { if (item == xhiro) { exists = true; break; } … | |
Re: I think it's a good choice in general, but I know nothing about you, so I can't say if it's a good choice for *you*. | |
Re: I think in posting only a "portion" of the code, you've edited it into nonsensicalness. Could you post more code, or ideally, a small but complete program that exhibits the problem. | |
Re: Warning 4996 is the height of stupidity, so I'll hard disable it in the project settings without any hesitation. Go to your project properties, then uder C/C++->Advanced there will be an option for disabling specific warnings. Add 4996 to that list and enjoy never seeing that ridiculous warning again. | |
For those of you familiar with the latest C++ standard, what do you think of [uniform initialization](http://en.wikipedia.org/wiki/C%2B%2B11#Uniform_initialization)? Listening to folks like Herb Sutter, it seems like the intended purpose is to be completely pervasive, which obviously changes the look and feel of C++. Do you plan on using it everywhere … | |
Re: > 'Systems' and 'Programmer' sound like 2 separate jobs to me. They're not. The difference is that a systems programmer will generally write code that sits below userland and provides services to the hardware or OS. This is as opposed to an application programmer that writes programs for users. I've … | |
Re: > `gets(rm[i].type);` > `fflush(stdin);` These lines are in the wrong order. I'll let someone else chastize you over using fflush() on an input stream, because it's obvious that you're using Turbo C++. I'll also let gets() slide, but keep in mind that it's the worst possible choice for string input. … | |
Re: You can do a simple replace on the string: textBox.Text = textBox.Text.Replace("Yes", "NO") Changing the color is a different matter. I assume you want to change only the replaced text to red, which won't work unless you're using a rich text box. If it's just a regular text box then … | |
No bells and whistles, just a quickie millisecond timer showing an alternative to the far less portable clock_t method. A test main() is included, just define TEST_DRIVER as a macro or remove the conditional compilation at the end. | |
Re: Yes, you're probably screwed. Consider using source code version control in the future. As a last ditch effort, you can check your autorecovery backup files for the project. It depends on your OS, but the folder is under your documents. For example, on my Windows 7 machine it's: C:\Users\jdaughtry\Documents\Visual Studio … | |
Re: > In any instance, the purpose of the response really seems to be to get the signature displayed in the thread. Yup, and that's against the rules. | |
Re: > double DivSales::totalCorpSales = 0; Move this line into the implementation file for your DivSales class. | |
Re: > but kept getting an error It's never a bad idea to post the error. | |
Re: > As long as the numbers are recorded as int and not as string or array of chars, getNrDigits provides the correct answer. cout << getNrDigits(0) << '\n'; | |
C++ conversion of [this C snippet](http://www.daniweb.com/software-development/c/code/445012/simple-interactive-menu) for a simple interactive menuing system. The code shows three files: * menu.h: The header file for the menu class. * menu.cpp: Implementation of the menu class. * main.cpp: A sample driver that uses the library. The menu library is fairly generic in that … | |
Re: `O(mn)` where `m` is the number of integers you process and `n` is the number of bits in an integer. How did I figure that out? The outer loop is obviously `O(n)`. The inner loop is also obviously `O(n)` and adds to the outer loop, but the value of `n` … | |
Re: > can any one help me out to identify this problem? Do you have a time machine that can take you back to 1990? If not, you'll have to wait until someone happens by who remembers how to use your ancient compiler. | |
Re: I haven't experienced that. Sometimes when I'm working quickly it takes the highlighter a second or two to catch up, but other than that it works immediately. | |
Re: > i just ask how can i do that program ? Please read [our rules](http://www.daniweb.com/community/rules) concerning homework, then ask a *specific* question. By the way, "How do I do it?" is silly and unproductive because obviously the answer is you think about the problem, devise a solution, and write code … | |
Re: Please see my response to your other thread on the exact same project: http://www.daniweb.com/software-development/c/threads/445335/convert-list-into-a-dictionary-using-open-hashing-cursor-based#post1919485 The key is the tutorial I linked you to, as it covers a whole lot of *everything*. | |
Re: > There is an error while using 2nd stack. how to debug it. Start by telling us the error and line. Here, I'll help. This error occurs on line 173: 'void Stack<long double,50>::push(T &)' : cannot convert parameter 2 from 'long double' to 'long double &' And it has nothing … | |
Re: I'm sure everyone is familiar with this random piece of disassembled code. :rolleyes: Do you have an actual question that I'm not likely to answer with "go read a book on assembly language"? | |
Re: Sounds like a kernel panic and automatic reboot. Are you using Windows? The first thing I do on a new Windows install is go into the startup and recovery options of advanced system settings, then disable the option to automatically restart on a system failure. That way when the fault … | |
Re: > How do you organise yourself when working on a project? It really depends on the project. Some are small enough that strict organization is unproductive or even counterproductive. Others are large/complex enough to warrant full bug and feature tracking system and a formal development life cycle. For inbetween projects … | |
Re: If the total amount is greater than $399, multiply it by .9 to get the total after a 10% discount. Otherwise, if the amount is greater than $199, multiply it by .95 for a 5% discount. Otherwise, don't make any changes: // Apply discounts if (total > 399) total *= … | |
![]() | Re: The only real problem I see in that line is your query isn't correct. You still need to add single quotes *in the query* to make string values SQL strings. It helps to copy the string verbatim into Management Studio (or whatever database utility you use), replace the VB.NETisms and … ![]() |
Re: > What does it help to make a class object as a pointer? In your code it doesn't matter, but there are a number of reasons you might want or need a pointer. Dynamic allocation comes immediately to mind as a case where you need a pointer. > and also … |
The End.