1,296 Posted Topics
Re: There are lots of defects in this code but it works after minimal corrections. 1. Uncomment choices 2-4: replace bad function name from taxcal to tax_cal. 2. Avoid unnecessary label and goto statement. Use normal C loop in that case, for example: [code=c] for (;;) { /* input payrate_index with … | |
Re: Keep it simpler, thuyh83 ;): [code=c] if (a != 0) { double d = b*b - 4.0*a*c; if (d > 0) { /* Two real roots */ } else if (d < 0) { /* Two complex roots */ } else { /* Two equal roots */ } } else … | |
Re: A triangular array is not builtin type. It's a program (or may be application domain artifact). For example: [code] aaaa - row 0 bbb - row 1 cc - row 2 d - row 3 or a - row 0 bb - row 1 ccc - row 2 dddd - … | |
Re: Alas, it's impossible now to separate template class declaration and implementation. Why? Have a look at [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12[/url] So place all your cpp file contents into template definition header file (then wait for a new compilers generation ;))... | |
Re: Have a look at the recent (solved 11 days ago) thread: [url]http://www.daniweb.com/forums/thread149945.html[/url] ;) | |
Re: Never use this approach in math calculations: 0.02 is a double type approximation of the real number 0.02 so 100*0.02 != 2.0. In that case you have 100 intervals (and 101 points): [code=c] double t; int i; for (t = 0.0,i = 0; i <= 100; ++i, t = i/50.0) … | |
Re: Alas, M_PI constant name is not defined in the current C++ standard. For example, VC++ defines it (in <math.h> header - <cmath> is a wrapper for it) only if _USE_MATH_DEFINES macros is defined at the moment of <cmath> compilation. Well, define your own pi if you wish: [code=cplusplus] #if !defined(M_PI) … | |
Re: If your data file contains numbers only, no need to read it in line by line manner: use fscanf directly: [code=c] double x; int rc; ... for (int n = 0; (rc=fscanf(f,"%lf",&x)) == 1; ++n) { /* you have got the next number... */ } if (rc == EOF) { … | |
Re: Well, you have three how-to problems: 1. Detect the word: it's the simplest problem - see code stub below 2. Select the word (detect end of word): see code stub below... 3. Detect a number of occurences of every word (make the dictionary): it's much more harder task. You need … | |
Re: The sprintf does not implement itoa functionality (radix in 2..36 range). Fortunately, it's so simple to get itoa portable solution: [code=c] /* The Itoa code is in the puiblic domain */ char* Itoa(int value, char* str, int radix) { static char dig[] = "0123456789" "abcdefghijklmnopqrstuvwxyz"; int n = 0, neg … | |
Re: It's cool!.. What is it: a new character in C++? Can you post an example of this animal? | |
Re: Reread overloading specifications then have a look at your overloaded operators. Overloaded operator + must return CollegeCurse (what's a strange idea ;)) and overloaded operator / must return double (why "also"?)... | |
Re: Probably you have a wonderful talent to work on the project before it's started. It's a pity I don't know how to do that... Well, define a class with back (to parent object) link (up pointer) and std::vector of down links. After that create root node then start to scan … | |
Re: Allow me to paraphrase your help request: I have a program which do something but sometimes it does not do it. Any ideas?.. | |
Re: It's not a scope error: ipaddr is in scope from if clause to the end of else clause. See prev post: you initialize ipaddr by (inet_addr(s) == -1) - it's eaual to false, so ipaddr == 0 after conversion false to in_addr_t. You should write: [code=cplusplus] if( in_addr_t ipaddr = … | |
Re: 1000+1 fairy-tails about storage class specifiers and storage duration in C... [quote]Older systems used to make a distinction between "stack" and "heap" (e.g older IBM compatible PCs used different memory chips for "stack" and "heap", and needed special drivers to access heap).[/quote] It was extended/expanded memory, not a heap. The … | |
Re: Don't waste a time and bandwidth to get freezed Dev-C++ or 400 Mb Visual Studio 2008 Express. Download compact Code::Blocks IDE with MinGW compiler (g++ Winsows port). | |
Re: 1. The 1st problem is undefined. Please, explain what you need: do you want to access private member arrays from the outer world? If so, why you declare these arrays as private? I can't understand your (sub)question "how can I use [] operator for my use, something like following,". No … | |
Re: Just imagine that all your numbers are scaled. For example, let 1 is equal to 1 billion, 2 == 2 billions and so on (append nine zeroes when printing)... What's a pleasure to summarize very BIG numbers with short int arithmetics: no need in GMP and other stuff... ;) | |
| |
Re: The std::set is an intrusive container: it has its own copies of inserted elements. So the program creates three incarnations of class Stone: one obtained from new op and the 2nd allocated in the container member and the 3rd in stones variable . The 1st object does not deleted (you … | |
Re: You must define overloaded assignment operator and copy constructor for the class ChainMesh. Default assignment and copy constructor are not valid for this class. If you assign this class variables or pass them as arguments then you will deallocate memory twice with default operator= and ctor... Also check up the … | |
Re: Don't forget to check argc value before [icode]argv[1][/icode] using, for example: [code=c] if (argc > 1) { switch (*argv[1]) { case '1': ... break; case '2': ... default: ... } } else { /* argv[1] is NULL! */ } [/code] | |
Re: Is it a joke? Are you sure that it's possibble to crack a cipher if you can compose some method name like [code=cplusplus] class CrackAllTheWorld { public: bool InvokeSuperCracker(void* ciphertext) { return true; } }; [/code] Better download this article on TEA cryptanalysis topic: [url]http://cs.ua.edu/SecurityResearchGroup/VRAndem.pdf[/url] (~1.73Mb). May be it helps... | |
Re: Probably it's user32.lib from Windows SDK lib directory... | |
Re: Your code returns 0 (see the last statement of main ;)). It PRINTS 1. Logical expression value is true, true printed as 1 (false as 0). What's a problem? You want to print bool value - that's the value printed. If you want to print x - do that! | |
Re: [code=c] const int N = 6; int n1 = 1, n2 = 0; int i, k, n; for (k = 0; k < N; ++k) { n = n1 + n2; for (i = 1; i <= n; ++i) printf(" %d",i); putchar(','); n1 = n2; n2 = n; } putchar('\n'); … | |
Re: It's suprising that you "have spent a long time trying to find library or useful class to help me perform matrix inversion". I have found then download some tested and ready-to-use freeware libraries in C++ with matrix classes and inverse operation for 10 minutes... Regrettably at the moment I have … | |
Re: OK: "array and pointers are not allowed to be used". What is it "batch"? I don't know such type (I hope, it's not an array ;)) in C++... | |
Re: It's too early for start without debugging: you can't compile the source w/o errors. I think it's not only this error message was emitted by the compiler. Obviously [icode]Mortgage myMortgage();[/icode] was not recognized as a valid declaration too. May be Evan's post hits the target but stricktly speaking in this … | |
Re: 1. [icode]int main()[/icode] 2. Nope. For any initial i and j the loop runs until i or j comes to zero (for positive initial number - after integer overflow). Of course on 64-bit platform it's a long way to... | |
Re: You declare local variables in if-else alternatives. Of course, they were discarded outside if-else statement: [code=cplusplus] if (a > 0 && b > 0) { // New block started Account customer(a,b); // Local variable defined (on the stack) } else { // Prev. bock is ended. Another block started. Account … | |
Re: 1. It's not a constant pointer - it's a pointer to const int. You can't modify referred int value via this pointer. 2. All 10 elements of array b are short int. 3. It's a function parameter declarator (the only context where this declaration occured w/o extern prefix or initializer … | |
Re: What's a problem? [code=cplusplus] typedef box<int> MyFavouriteBoxType; ... MyFavouriteBoxType b1; [/code] Look at STL headers on you C++ installation. There are lots of (useful) typedefs in STL templates... | |
Re: Fortunately, no need to count ways yourself. Let a dumb computer do that ;)... | |
Re: Don't forget: std::cin is not alias for a keyboard input. It's an abstract char input stream. You can attach it to a file, for example. Moreover, std::cin is not defined for windowed applications. You describe possible keyboard input errors. But std::cin does not bear a relation to online user behaviour. | |
Re: Don't muddle yourself by a structure (or class) definition inside (or outside) another class and a declaration of a class member. The type S declared inside class X has qualified name [icode]X::S[/icode] (S at X ) and you can use this type (the type - not variable of this type) … | |
Re: Of course, you may ask the user to input size or what else. The problem is what to do with the answer. Better explain your problem, present source code snippets... | |
Re: Are you sure that it's a telepathic forum? Where is a wrong line? See [url]http://www.daniweb.com/forums/thread78223.html[/url] There is a wonderful F1 key on your keyboard... | |
Re: Well, it's so simple. Enclose this dialog in do-while loop then (after the calculation) ask the user if he/she want to continue then test the answer in trailing while condition. What's a problem?.. | |
Re: [code=cplusplus] int grade; const char* reply; while (std::cout << "Enter the Students Grade [1..100]\n" "or not-a-number to quit: " << std::flush, (std::cin >> grade) && grade > 0 && grade <= 100) { if (grade < 50) reply = "F!"; else if (grade < 60) reply = "D!"; else if … | |
Re: All libraries written in C?!.. Hundreds of million (or billions) lines of codes?!.. Probably you are multi-multi-millionaire: not all C libraries are freeware... | |
| |
Re: It's not "a very stupid question". It's a good question. You define Blah::getValue member function outside the scope of the Blah class (you declare it inside the class definition but define it outside the class definition). The struct Values is declared inside the Blah definition so its scope is class … | |
Re: Have you ever read your own posts? [url]http://www.daniweb.com/forums/thread149947.html[/url] Well, if you want the answer in this new post: no such function as getfilepathname so you can't get the path of anything from a function which is not in existence. | |
Re: That's the fateful (and typical) mistake in the average value calculations: [code=cplusplus] double average; int sum = 0; ... average = (sum / 5); // *** integer division! [/code] You try to assign the result of integer division to double value. You want to get exact average value. But 7/5 … | |
Re: The std::string class has no builtin conversion to the char* type: std::string object is not a char array. It has c_str() member function - it returns const char* pointer to the string contents buffer, but don't try to modify the string text directly (that's why it's const pointer). Why you … | |
Re: The answer to your question is so simple... it's equal to your homework complete solution. But it's your homework, not mine. Look at your original post carefully. That's the answer. Or search daniweb C (and C++) forums: there are lots of thread on this extreme popular topic... | |
Re: Try _fullpath from stdlib.h (see MSDN help on this function). It has its own restrictions. If you have a file name only and know nothing about this file location you can't get its full path w/o your own search process. For example, you have 10 files named oneof10.txt in partition … | |
Re: Oh, it's much more absurd example of a recursive method than famous recursive factorial! It's rather rough C++ to C translation. Slightly better one: [code=c] int recursivePalindrome(const char *str, unsigned int index) { unsigned length = (str?strlen(str):0); ... and so with obvious code correction [/code] ... and so on with … |
The End.