200 Posted Topics
Re: A static class member exists on a class level as opposed to non-static class members that exist on an object level. For example, what you can do with s_b but not with b is access it without having an "A" object, as it's not part of an object but of … | |
Re: Example of b #include <stdio.h> int Highest (const int l, const int r) { return ((l > r) ? l : r); } int Lowest (const int l, const int r) { return ((l < r) ? l : r); } void FindMinMax (const int A[], const int n, int* … | |
Re: *Hands Ranjan_1 the "Post-of-the-day badge". | |
Re: Depends on how you want it to work. If you expect the formula as a single string you could do something like: #include <stdio.h> #include <string.h> #include <stdlib.h> int main(int argc, char *argv[]) { int num1, num2, result; char op; int check=0; if (argc != 2) { printf("usage: %s <formula>", … | |
Re: Muh. first, askk for the initial balance of the bank accounts So what have you tried, and what isn't working as expected? If you haven't gotten to the point of coding yet, what part of the design is it you cannot develop? reject negative balance So what have you tried, … | |
Re: You could "outsource" validation. If your regex is working, you could use [match_results](http://www.cplusplus.com/reference/regex/match_results/) to obtain the different section, create a [tim structure](http://www.cplusplus.com/reference/ctime/tm/) and pass that to [mktime()](http://www.cplusplus.com/reference/ctime/mktime/) for validation. | |
Re: ASAP PLS..TENKS WOOF! NO PRAPLEM. #include <iostream> #include <cctype> #include <algorithm> using namespace std; int main() { string answer; do { cout << "Enter \"y\" or \"n\": "; getline(cin, answer); // Trim whitespaces before/after input. We tolerate those. answer.erase(find_if(answer.rbegin(), answer.rend(), not1(ptr_fun<int, int>(isspace))).base(), answer.end()); answer.erase(answer.begin(), find_if(answer.begin(), answer.end(), not1(ptr_fun<int, int>(isspace)))); if (answer.size() … | |
Re: I don't really understand what you're trying to say, but can the arrays be modified? Or must their content remain in-place? If the first I'd probably sort and compare if based on that. Something like this: (something quickly made, not tested) #include <iostream> #include <algorithm> using namespace std; bool SortedIsPartOf(int … | |
Re: Will your ID determine which of the two types the struct value is? Or do you have special guard values? I'd first consider if storing them like this is what you want. (You could use two containers) Do you need the type-specific values, or it is only the ID you're … | |
Re: You know that a linked list is basically a value and a pointer to the next element in the list. (if any) So somewhere you define what the starting point of your linked list is. (the head) With that you can access every element in the list by using the … | |
Re: I don't really get what you're trying to describe. What do you mean by "the probability of Malik"? The probability of what? From what you're describing it seems to me that you just want to count how many times every name occurs, pick the one with the highest occurrence (question: … | |
Re: > have any ways to solution this problem? please help me get some idea.Now i dont have any good ideal for this problem. How about you read the replies? There is no solution to your problem because it's not possible to do what you want. Add another argument to "func" … | |
Re: char first[100], last[100]; Why use character arrays when you can use string objects? Change this to: string first, last; cin >> first, last; Is incorrect. You're applying the [comma operator](http://en.wikipedia.org/wiki/Comma_operator) here, which is why it compiles. The following will do what you're probably expecting: cin >> first >> last; You … | |
Re: printf("\nFile Will Not Open!!!!\n); You are missing a terminating quotation mark. Also I would be very scared if an application would respond to me using so many exclamation marks, but this is not technically an error. printf(\navg is beint calculated!!!"); You are missing the opening quotation mark. Void open(void); "Void" … | |
Re: As far as trimming goes, the following might be useful: // Trim the start of a string. string& TrimLeft(string& s) { s.erase(s.begin(), find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))); return s; } // Trim the end of a string. string& TrimRight(string& s) { s.erase(find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(), s.end()); return s; } // Trim … | |
Re: I'm pretty sure the std::string overload was added in C++0x. I can only imagine they didn't add it earlier o prevent a dependancy between the <string> and <fstream>. I haven't been able to find an official statement about why they made the choice to add it in C++0x, although I'm … | |
Re: Your GCD function will divide by zero when you enter 0 as its second argument. You can also supply negative numbers. You're lacking return types as well.. I assume that you don't feel the need to check your arguments as you have full control over them. You should still assert … | |
Re: > Yes this works but I have been asked as a task to do: That task just makes no sense. To get this straight, you've been given this piece of code: New(Shoe[num], num); And you're supposed to make that work in a way that it adds a new element to … | |
Re: You are applying "&" to an array variable. This works differently from pointers. It gives the memory address to the first element, so basically it can be considered int*. (cast to) Something like this will work as you'd expect it to: #include <stdio.h> int main (void) { unsigned int i … | |
Re: There's a bunch of things to be said about your code. Below is your code with some comments, I didn't change anything though. #include <iostream> #include <string.h> // C-header, iew! using namespace std; int main() { // We're using C++, use a string object instead of a char array. char … | |
Re: There's some edge cases that could make it somewhat complex. Mostly because you could have lines bigger than your buffer. This will result in two types of reads: those that end in newlines, and those that do not. (and a newline happens to be exactly the symbol that marks the … | |
Re: The term "pointer to arrays" could be somewhat misleading, depending on how you interpret it. Just as a heads-up: pointers and array aren't the same thing. One example that illustrates this: #include <iostream> using namespace std; int main (void) { const char* pointer = "Hello world!"; const char array[] = … | |
Re: Haha, I love how you thank deceptikon for his advice to "do anything" as if it's something you hadn't considered previously. Good luck! | |
Re: You're very close. You do have to pay better attention to the loop range however. Below is a fixed version of your code where I kept the changes minimal. The comments should speak for itself: #include <stdio.h> #include <string.h> int main(void) { int loop,count; char* string = "myname"; // The … | |
Re: Your code doesn't take leap year into account, and "magic numbers" are generally a bad idea. (Although they are unlikely to change in this case..) You could try something like this: #include <iostream> #include <cassert> using namespace std; enum Month { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, … | |
Re: C-string don't automatically grow. You have to be aware of the array's dimensions. Why don't you use 'string' objects instead as we're talking about C++ here? | |
Re: Note that a palindromes don't take punctuations and word dividers into account. For example: > Bush saw Sununu swash sub. is a palindrome, although your application would say it's not. These types of problems are easy to think about recursively. The general idea would be that 'the first and last … | |
Re: I find your code pretty difficult to read. Why don't you divide problems into a smaller problems by using functions? I don't really know the theory behind perfect numbers that well but on a quick attempt I would go for something like this, which is quite different and (in my … | |
Re: > so I spent 3 days trying to make the program and still have it not done yet :( vs > I've done nothing and that's the problem :( Hmmm.. Anyway, what are you supposed to use? I guess you want to implement it using an array or linked list? … | |
Re: #include <iostream> #include <cassert> using namespace std; void Repeat (const char symbol, const int amount); int RowToWidth (const int row); int ObtainHeight(); int ObtainHeight() { int height(0); do { if (cin.fail()) { cerr << "Invalid input.\n"; cin.clear(); while (cin.get() != '\n'); } cout << "Enter the height of the pyramid: … | |
Re: > Now I need to do the validation for( date and madein). (1) to decrease 10% of price if date before January 2012 (2) to add 10 Rm if the madein country is Malaysia. stuck again! Why? If you have a day, month and year what is stopping you from … | |
Re: It wants an array of bytes and extracts a "length" value from that array by combining the bits in the second and third byte to form a 16 bit integer. (later stored in a 32 bit one..) The most significant part of this 16-bit integer is formed by the third … | |
Re: I am a little bit confused as to what output you want your program to have, or rather what it is supposed to represent. You don't really seem to want substrings as you also mention "ac" but you do not mention things like "cb". Would "cb" be the same as … | |
Re: People are using the term "leaf" differently.. A leaf node would be a node without any children in my book. I assume you just want to delete any node from your tree, meaning you could delete the leafs too if you wanted. > I am trying to delete the leaf … | |
| |
Re: I think the memory representation "images" are vague but I'll try anyway: 1. Answer should be "a". You answered B. That would result in an array consisting of 3 pointers to "Foo" objects in memory, so that would be [Foo*][Foo*][Foo*] according to the notation used in your example. (I think) … | |
Re: What does your design look like at the moment? (How are you handling multiple clients on the server? Threads, I/O multiplexing? You could apply the same solution on the client side to detect incoming messages and send things at "the same time" (not really ofcourse). | |
Re: The supplied piece of code isn't wrong. If it's not working it is something else within the program that is causing issues. | |
Re: Try to do it with 1 array first. There is no added value when working with two, and with your code you lose track of how many elements A contains. Your code also doesn't compile. (You call swap with 2 arguments while it has 3 for example) Try to explain … | |
Re: You could try something like this: #include <iostream> #include <sstream> #include <limits> #include <iomanip> std::string double_to_string(const double value) { std::ostringstream stream; // Go for maximum precision and take into account that converting could fail. if (!(stream << std::setprecision(std::numeric_limits<double>::digits10) << value)) { // Possibly throw an exception instead. return std::string(); } … | |
Re: for (i=0; i<Number_entrys;i++) { scanf("%s",names); } You are looping here to obtain "number_entrys" entries, but you do not use your counter. Change it to this: for (i = 0; i < Number_entrys; i++) { scanf("%s",names[i]); } I'm also not sure what the goal is of this statement: printf("%s",names); But be … | |
Re: Typical case of TL;DR but I did notice the following words: > A text-based menu driven program should be created. Could try there I guess. | |
Re: > int &count That is not allowed in C. Reference parameters are C++, use a pointer instead. > const int MAXSIZE = 100; > char line[MAXSIZE] = {'\0'}; I think this falls under "variable length arrays" (VLA's) which is a C99 feature. I'm not entirely sure because of the const … | |
Re: How about you first create a class representing a linked list that contains some basic operations? * Insert a value at a given index. * Remove a value at a given index. * Obtain the size * Get the value at a specified index ([] operator?) * Remove the first … | |
Re: > let me know if anyone has any pointers thankS! 0x0F021016 0x0E031418 0x08051033 *Ba dum tss* > any help would be greatly appreciated!!! thanks! Anyway, at a quick first glance I don't really see anything that could cause errors. What have you established yourself already? At what point do problems … | |
Re: It is because of this line: scanf("%c", &yesno); This will also read '\n' when pressing return in addition to whatever you entered. On the next iteration this will still be in the buffer so that statement will read that directly. It fails the input check so the next iteration is … | |
Re: Hmmm... I think i'd start like this, just an idea though. int main(void) { return 0; } | |
Re: Such C++ includes in C code. The way you do it will become problematic when using 48 bits as the amount of possible permutations is huge. You don't have to store them though and just output them as they get calculated. Another thing that might become an issue is the … | |
Re: It's not skipping input, you already supplied it. Say you enter 1 for the 1st number. What you really enter is: '1' and '\n'. The '1' is read into 'a' and the '\n' remains in the stream. When calling scanf() a next time it reads the newline character that was … |
The End.