3,183 Posted Topics
Re: Somehow I suspect you're not providing nearly enough information for us to give you a helpful answer. However, as stated this can be done with a trivial function: double current_ratio(double asset, double liability) { return asset / liability; } That can be extended into a declaration and defnition using two … | |
Re: I'm going to go out on a limb and suggest that the problem is an unlicensed version of the "folder hider" software such that the feature you want isn't available after recent updates. | |
Re: Each node is just an anonymous variable that the pointer points to. It seems like your confusion is more about self-referential structures than anything. So let's take a look at a simple linked list: #include <iostream> struct node { int data; node *next; node(int data, node *next = nullptr): data(data), … | |
Re: Covariance only works within an inheritance hierarchy. What you seem to want is a variant type in general, which can be achieved using Boost::Any or Boost::Variant, depending on your needs. That said, what exactly are the criteria for selecting the type in your factory? This can change how feasible a … | |
Re: > If you want a simple and fool proof way for input handling consider taking everything in as strings and running your own checking functions on them for validity. For standard types provided by the language, end user programmers shouldn't be expected to validate or parse them unless they want. … | |
Re: You could try Daniweb chat for such things. ;) However, I don't think this kind of question is unsuited to a thread, especially since you might get a large number of differing opinions and a very interesting debate out of it. | |
Re: > I have a code that when mouse hovers a button then it fires click event. I would strongly recommend against this approach because it's unconventional and surprising. If an application I used did this, I would stop using it post-haste and look for an alternative. | |
Re: > Huh? How could a downvote become invalid due to changes in technology? The answer may have been excellent 10 years ago, but as technology and techniques change it becomes outdated and bad advice. If posts aren't read in the context of their post date, I can easily see downvotes … | |
Re: > ptr-p should return a address. But here its returning data ? Subtracting two pointers returns the difference between the addresses, not another address. | |
Re: > I want to allow only numbers (int & float data type) input. How will I do that? The usual and recommended approach is to simply allow the user to type anything and then throw errors if it doesn't match what you're expecting. For example with numbers only: #include <ios> … | |
Re: Arrays cannot be copied, but if you really want to do it with the assignment operator, you can wrap the array itself in a structure #include<stdio.h> typedef struct { int data[5]; } array; void foo(array b) { int i; for (i = 0; i < 5; i++) { printf("%d\n", b.data[i]); … | |
Re: > "the exe is not compatible...... make see whether you need 32 bit or 62 bit" Are you paraphrasing, or is that the exact message? Also, how are you running the generated executable? | |
Re: As a huge hint, here is a macro that calculates the number of leap years for a given year: #define LEAP_COUNT(year) ((((year) - 1) / 4) - (((year) - 1) / 100) + (((year) - 1) / 400)) | |
Re: > there is no need for dump and all..simply u get a string using %s..that's it Okay, now type a first and last name. You introduced an error since the original code was retrieving a full line of input rather than a single word. Ideally one would use fgets() for … | |
Re: You need to decide whether you want to use C-style strings or C++ std::string. If you want a C-style string, it's called like this: int main() { char s[] = "apples"; char a = 'p'; char b = 'd'; cout << "Before swap of Char : " << s << … | |
Re: The tree being "mono" is already an invariant as far as nodes go, you'll never have two nodes with the same key. However, you can check for the tree being "mono" with a simple traversal and a test to see if any of the counts are greater than 1 (which … | |
Re: You can pass a ref parameter in C++/CLI using the '%' operator, it corresponds to standard C++'s reference operator(&): int MediaMogul::readlist(String^% name) { name = "changed value"; return 0; } | |
Re: While I appreciate your willingness to share your knowledge, Daniweb's forum isn't a reference manual. If all you're going to do is post an extremely sub-par variant of MSDN, please stick to answering questions. | |
Re: Yes, you can certainly discuss those things. Though the topic is rather broad, and in the case of "is it okay to do/say XYZ" the general advice stands: if you have to ask, it's probably not okay. p.s. The only way to feel comfortable in an interview is to not … | |
![]() | Re: Storage isn't an issue, and storing them as binary won't change the size unless the majority of the size is formatting of record data. The question you should be asking is "how do I need to access this data"? For example, if you're just storing the files and will read … ![]() |
Re: Check your errors. For example, whenever opening a file fopen() returns NULL on failure: FILE *f=fopen(file,"w"); if (f == NULL) { perror("Error opening output file"); /* Whatever exit or recovery strategy you choose here */ exit(EXIT_FAILURE); } If nothing else you may get more useful information in the way of … | |
Re: Theoretical or not, it's against Daniweb's rules. | |
Re: Order of operations, my friend. `(int*)a + 1` converts `a` to a pointer to int, *then* increments it **as a pointer to int**. What you wanted, according to your expected output, was to increment `a` *first*, then convert to a pointer to int: static int *p[] = {(int*)a, (int*)(a + … | |
Re: > How can I do it with sprintf()? Before I posted here, I scoured the internet all over, and all the explanations for sprintf were to complicated. I couldn't understand. If AD's example above was too complicated, I'm not sure what to tell you, because that's as simple as it … | |
Re: Also keep in mind that if you need a destructor, you probably also need a copy constructor and copy assignment operator (and possibly a move constructor and move assignment operator for C++11). I'd also avoid a protected data member in favor of a private data member and public const getter. … | |
Re: The indexing works the same way since it's nothing more than an array of 2D arrays. If you add another dimension of 2, duplicate what you posted each with an index of 0 and 1: 000 001 010 011 100 101 110 111. | |
Re: There are actually a number of problems with that function, though returning a pointer to a local variable is probably what the interviewer wanted. | |
Re: > I can't figure out what type of parameter should my addArticle() function have in order to work for this main. I would like to let the compiler choose if the object passed is a CBook or a CMagazine. Is that possible? Perhaps I'm missing something, but if you want … | |
Re: > I see that a lot of people are already familiar with C++11 to the point that they don't think about it when they use its features. Is it now considered 'best practice' to use the new features? Best practice depends on your needs. If you don't need to conform … | |
Re: I take it you're going to air your dirty laundry every few months just to remind us that you're unhappy with the new system? > Every forum uses your regular [code][/code] but no, not Daniweb. Not every forum, just forums based around or inspired by vBulletin. Hop on over to … | |
Re: Understand accounting, know how to develop software, define the features you want, and implement them. | |
Re: > you'd think it wouldn't build correctly but I guess technically it was correct This is a key lesson with C++. Just because it compiles doesn't mean it's correct, either semantically where the language is concerned or logically in terms of the application's intended behavior. | |
Re: First and foremost, identifier names that are varying case from a keyword like CLASS, INT, or CHAR, are extremely bad ideas. I strongly suggest using something more informative. To answer your specific question, pointers to class types work *exactly* the same way as pointers to built-in types. For example, when … | |
Re: > do u think 1 hour is sifficient ? Certainly not, but as you're hopefully not trying to deceive the interviewer, that's not your problem, is it? ;) > 1.Why amazon ? Why not? > 2.what will you do if you get offer from google after getting offer from us … | |
Re: There's a way to systematically convert a recursive algorithm to an iterative one, but unless you're dealing strictly with tail recursion, some form of stack data structure is still required. Do your contest requirements exclude the high probability of virtual memory on the machine being sufficient to contribute to the … | |
Re: It's not obvious that the check is a button or what it does. I suspect very few people have bothered to click on it. | |
Re: Option 1 would be preferred in this case. In option 2 you're allocating a whole new data structure to hold the filtered results and also iterating the original list in its entirety once followed by the filtered results once. In option 1 you have what essentially boils down to a … | |
Re: Your description of the problem and solution seems dicey. Could you elaborate a bit on what this critical piece of code is so that it's easier to determine what IPC solutions would work best? Right now you basically have a race condition with your locking file, which is a bigger … | |
Re: Ignoring for the moment that this is a horrible example of object orientation and brings into question whether you're qualified to be giving out examples as if you know what you're doing, what exactly is the benefit of an object oriented bubble sort here? | |
Re: I wouldn't say it's a favorite, but I'm cheap, and the best free IDE I've used so far has been NetBeans. ![]() | |
![]() | Re: > Thank you for your reply, but that is not the answer I was looking for. I suspect the answer you're looking for is unreasonable. A better solution is to fix your design such that you don't need to wade into the shithole of pointers to arrays. For example, using … ![]() |
Re: What problem are you having such that you need help? Simply saying "Any help is appreciated" is very broad. For example, I'd do something completely different; does throwing away your code and starting over constitute "help"? | |
Re: At the moment, Baby Steps. Of all time, probably W Juliet or Day of Revolution. | |
Re: The rules don't change just because you're nesting a control structure: if (foo) { if (bar) { // Blah blah } } else { if (baz) { // Blah blah } else { // Blah blah } } | |
Re: > Besides, it is not part of the standard and your code might not work with other compliers. Before each scanf(), put fflush(STDIN); to make sure the input stream is empty. Um...I hate to break it to you, but 1) C++ is case sensitive and STDIN is not a valid … | |
Re: > Actually the C coding standard often used does not allow declaring variables inside a 'for loop' ... It depends on which standard you're compiling for. Prior to C99 you cannot declare a variable in the initialization clause of a for loop. Starting with C99, you can. Note that prior … | |
Re: > I have Not Studied about Pooling in ADO.NET and So I don't Know about the Concept of Pooling Then I guess you're not qualified to answer the question. Why should we help you cheat? > If Anybody can Solve It for me ? Honestly, I don't think any of … | |
Re: Consider this simple example of clearing the input line on an invalid conversion: #include <ios> #include <iostream> #include <limits> using namespace std; int main() { int num; while (true) { cout << "Enter a number: "; if (cin >> num) { break; } cerr << "Invalid input\n"; // Clear the … | |
Re: > I thought that any change in pointer was reflected in main(). You can pass a reference to achieve that behavior. > Is same behaviour expected in C? Yes. |
The End.