518 Posted Topics
Re: You should be using some sort of linear data-structure ( an array or a vector). Consider an array: [code]Arr _______________________ Pos: | 0 | 1 | 2 | 3 | 4 | |___+___+____+____+___| Value: | 1 | 5 | 10 | 23 | 8 | |___|___|____|____|___|[/code] We find the largest … | |
Re: Guess what!! I derived a O(1) formula for the same. If it is your homework, don't try to copy the formula. I am sure you teacher will ask you derive it if you do so. [tex]r=floor\left (\frac{3\times n}{2} \right )-1[/tex] where floor() is the greatest integer function floor(3.2)=3 floor(6.1)=6 floor(6)=6 | |
Re: >On the downside: no more time for office-sword-fighting This reminds me about the cover of the Dragon Book [img]http://www.stewart.cs.sdsu.edu/cs524/spr08/bookCover_51XtGJ64tZL._SS500_.jpg[/img] | |
Re: Linux is(and based on) one of the most well-designed operating system, while M$ is one of the most ill designed operating system. But this fact is realized only after you start using Linux. Linux is free, open source. M$ is costly (over rated) Linux of course has more of a … | |
Re: >I'll try to help you to the best of my abilities, and if I did help you, please add to my >rep ;D ROFL. I think begging is against rules or something isn't it? Even I would have put that to my signature if DaniWeb could redeem those points with … | |
Re: Always use the [I]size_t[/I] type for indexing a container, or for container size. That means -> instead of [icode]for ( int j = 0; j < item.length(); j++) [/icode] use [icode]for (size_t j = 0; j < item.length(); j++) [/icode] -> instead of [code=cplusplus] int size= 5; int* x= new … | |
![]() | Re: You can exploit the multiplication operator for strings [icode]"Hi"*2="HiHi"[/icode]. The solution is pretty trivial and is a one-liner: [code=python]>>> for a in range(7): print "*"*a ... * ** *** **** ***** ****** [/code] Now modify this code so that it can print the pattern you want. |
Re: Congratulations, Your code is rusted!! That means it uses the style of coding that was used aprox 13 years ago. You are using all the deprecated and non portable headers. You are using void main, which is a sin. In short you are practicing everything that a Standard C++ developer … | |
Re: The script on which the login details is to be sent is [icode]https://webconnect.bloomfield.org/Zangle/StudentConnect/logincheck.aspx[/icode] and not [icode]https://webconnect.bloomfield.org/Zangle/StudentConnect/[/icode] I know this because I opened the HTML source of the page /StudentConnect/ and then looked the action attribute of the <form> tag | |
Re: In python 2x, print is a statement, not a subroutine, subprogram, or function. Hence it exists as part of core language. That is, it is integrated as part of interpreter. In python 3, print is a function which is found in builtins module (but I am not sure since I … | |
Re: >It's practically the same thing, in my example I used a struct anyway. Not in C. A C compiler do not know what a class is. I agree that struct and class are related ( and they are the same thing in C++ ( except for the default access providers) … | |
Re: My question : Do we really need this? Why? If you are needing to open 100+ files at once, you should perhaps re factor your code and design. BTW, if you are on *inx (Unix,Linux), you can run the following command to know what is the maximum number of open … | |
Re: You should not be using enum if you intend to do this. You must know the real objective/point/motive of using enums. Look at this brilliant page: [url]http://enel.ucalgary.ca/People/Norman/enel315_winter1997/enum_types/[/url] In short, enums are just a way to give symbolic name to the group of logically similar integers. | |
Re: Not so fast. Although the solution provided works well, always ask yourself [U][I]why[/I][/U] do you need to know the name of the class? typeid() is a slow construct, it is evaluated at runtime. (Though the most compiler optimize it so as it can be determined at the compile time. This … | |
Re: " .h files are smaller than .cpp " is a convention and a strong convention. There are many well established libraries which do not follow this convention. One of the infamous example is Boosts; they have header-only libraries. (well, mostly) | |
Re: Cheesey, You sure need to have a reading on this page. It is written by one of the most profound hacker, Eric S Raymond : [URL="http://www.catb.org/~esr/faqs/smart-questions.html"]How to ask question the smart way[/URL]. Please go and read it first before attempting to seek any help. I specially like to quote a … | |
Re: Well, I know that guide was not exhaustive. It was not a reference material, it was just a guide. I clearly mentioned that you will have to search for more information about specific topic on the web. Learn to use a search engine well. There is a sticky [URL="http://www.daniweb.com/forums/thread70096.html"]thread[/URL] about … | |
Re: Do you mean how can you pick up a random number from given sequence of numbers? follow this thread :[url]http://www.daniweb.com/forums/thread198944.html[/url] | |
Re: Oh, what a junk piece of codes (Post #1 and Post#3). It is pretty much expected from Turbo C++ users. Your code is rusted. It is the C++ what it used to be 13 years ago. Now the world has changed. Most of the C++ developer use the Standard C++. … | |
Re: Others suggestion is right and should fix the code.: 1. change the "B.h" to A.h while including in the 1st line of B.cpp 2. You are calling f() without an object. Note that f() is a member of B so you need to create an object of B and call … | |
Re: C/C++ are considered best for system level programming.[1] You should be using some more abstract language like Python ( I strongly recommended this language: its heaven ). Strictly speaking, Python, C/C++ (in general all the well-designed languages) do not support such operation using just the core language only; you need … | |
Re: SQL and C++ are two completely different language. C++ is a (real) programming language. While SQL is a query language intended to interpreted by a RDBMS. In fact, the entire MySQL is written in C++ [1]. What you can do is perhaps call the SQL queries from a C++ program; … | |
Re: Why do they use the same words for different things? I always thought Entropy S: [tex]dS = \frac{\delta q}{T}[/tex] and [tex]S = - k\sum_i P_i \ln P_i \![/tex] Edit: The second formula is from Statistical Thermodynamics. | |
Re: Oh no please. Not Sams teach X in Y days. I hate it. Read this :[URL="http://norvig.com/21-days.html"] Teach Yourself Programming in Ten Years[/URL] by Peter Norvig . An excellent article to reply Sams | |
Re: >This would be the equivalent of doing something like...: No. In the first code, you declared a pointer which is pointing to a memory location. Hence, in this case you will be dealing with a pointer like interface. If the pointer was to object, you would refer to the member … | |
Re: So, what are your problems. Are we supposed to copy your code into our compilers, compile it and then check for errors. (By the way, I just did all this and found that your program ran smoothly giving no errors). >So,please any C/C++ expert please help me out from this … | |
Re: How are you giving the strings? If you are giving a complete python program in the string, you do a trick: Write all the string into a file and execute it with the interpreter by using a execv or system command. | |
Re: >IF UR PROG NEED SOME INPUT GIVE IT & PRESS ENTER AND USE "getch();" >(REQUIRES "conio.h") AT THE END OF UR PROG. Thanks for giving your ancestral trick. I promise I won't tell anyone. | |
Re: >Open an HTTP connection to your server, then do a "get" to retrieve some >information. You may use[URL="http://curl.haxx.se/"] cURL[/URL](if you are using C )[URL="http://sourceforge.net/projects/curlpp"]cURLpp[/URL](if you are using C++) as a library which implements HTTP/GET and HTTP/POST | |
Re: >now it's not just shutting down But where did you wrote the code to shut down the PC? You haven't. Your coding style is rusted. Have a look at this guide to improve. Especially read the 2.3 and 2.5 section of this guide. | |
Re: >Move file pointer to the end of file using seekg(); use tellg() to get the length of file. Not likely. While the file is opened in text mode, the seek and tell functions do not necessarily deal in pure byte offsets from the beginning of the file. Read this FAQ: … | |
Re: Okay. I had enough! It had been 11 posts in this thread and I cannot belive no one told OP to use code tags. To the OP, it doesn't mean you shouldn't be knowing about code-tags. You should be posting the code using code-tags. Information about code-tag is posted all … | |
Re: 1. Write the int isPalindromeHelper(char A[],int n) such that it takes a array of char [B]A [/B] of a size [B]n[/B] and returns 1 if it is a palindrome and 0 it it is not: isPalindromeHelper("LOLA",3) should return 1 and isPalindromeHelper("LOLA",4) should return 0 2.Then wrap this function with isPalindrome(char … | |
Re: Why not use stringstreams? [code=cpp]#include<iostream> #include<string> #include<sstream> int main() { std::string str; getline(std::cin,str); std::stringstream sstrm(str); int count=0; std::string temp; while(sstrm>>temp) count++; std::cout<<count<<std::enl; } [/code] output: [code] siddhant3s@Xion:~$ g++ tester.cpp -o tester.exe -ansi -pedantic && ./tester.exe Let me type something which also contains tabs 8 siddhant3s@Xion:~$ [/code] Edit: [siddhant3s wants to … | |
Re: >Please bear in mind that Daniweb is no remote compiler service or something What a good idea. I have started to think to write one :-) Bloody who will support the webhosting services :( | |
Re: You are correct in saying that you cannot actually delete a part of file. So here is what you usually do. Suppose you want to delete everything from the 57th byte to 64th byte: --You first copy the first 56th bytes to a temp file --Then you copy the 65th … | |
Re: Ball_1 is a vector object. A vector object do not have a .itsposition member. Try Ball_1[i].itsPosition or better: pass [B][I]Ball Ball_1[/I] [/B]as the argument of function Distance rather than [B][I]std::vector < Ball > Ball_1[/I][/B] | |
Re: It is officially clear that the code is best understandable by its author. About C++: It is (nearly) a perfect language with majority of imperfect programmers. Most of high school teach C++ with giving students proper programming background. These student, mis-interpret themselves as C++ programmers and write crap code. And … | |
Re: Okay, as you are here on C++ forum, you would get C++ as the favorite language here. If you are starting to program, the single most language that you should learn is Python. I have listed the major power of "Why Python for Beginners" on StackOverflow recently :[url]http://stackoverflow.com/questions/990157/what-is-a-good-programming-language-for-beginners/990246#990246[/url] have a … | |
Re: Did you tried this?? [code=python] >>>s="No one can be told how good Python is, you have to See it for your self" >>> for x in s.split(): ... if (x[0].isupper()): ... print x ... No Python See [/code] | |
Re: >What i said is just polymorphism No. What you said was overloading (function overloading to be exact). Read [url]http://www.cs.bu.edu/teaching/cpp/polymorphism/intro/[/url] point number 2.(What is polymorphism?). In short, while discussing in the domain of C++, polymorphism is the term used to describe the dynamic polymorphism (virtual classes and function and related...) while … | |
Re: Just to clarify what sridhar said, read this [url]http://www.wikihow.com/Convert-from-Decimal-to-Binary[/url] And please learn to use a search engine. | |
Re: >separated by '\n' or '\r\n', depending on the os Don't you know that C automatically translate '\n' into the native newline character when files are opened in text mode? Read [url]http://en.wikipedia.org/wiki/Newline#Newline_in_programming_languages[/url] 2nd point. Hence you never need to bother what is the newline character of underlying implementation, just use '\n' … | |
Re: Yes there is: Use constructors. I think you will learn about them a bit later: [code=cpp]struct CandyBar { string brandName; float weight; int calories; //no argument constructor CandyBar(){} //a argumented constructor CandyBar(string bn, float w, int cal): brandName(bn), weight(w), calories(c) {} }; //in main() CandyBar* cb= new[3]; cb[0]=CandyBar("snickers",2.2,147); cb[1]=CandyBar("nickers",4.22,1447); cb[2]=CandyBar("kers",7.22,447); … ![]() | |
Re: [code=python] >>> s="abc123abc" >>> t= "".join([x for x in s if x.isdigit()]+[x for x in s if not x.isdigit()]) >>> print t 123abcabc >>> [/code] This was the quickest I got in my mind. Try not to use regular expression. They are quite slow. | |
Re: So you have your home-made String class and want it to implicitly convert to C-string(a zero-terminated character array). You would have to overload the operator char*() Read [url]http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=24[/url] And always search the web before posting. | |
Re: A function defined inside a class is automatically request the compiler to make it inline: [code=cpp]class foo { int f1() { //the definition // This function is inline } int f2(); } int foo::f2() { //the definition goes here //function is not inline }[/code] In above example f1 is inline … | |
Re: Oh please. Micro-optimization is not cool. Adhere to the philosophy that "Developers time is far far more important than machine time" Small optimization won't make significant changes in the execution but will drastically increase your head ache. I find Salem post to be extremely right in this regard. Very well … | |
Re: As AD said, your program contains a lot of [URL="http://en.wikipedia.org/wiki/Magic_number_(programming)"]magic numbers[/URL] which is [URL="http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.11"]not a good thing[/URL] to do. [URL="http://www.gidnetwork.com/b-61.html"]Do not use system("pause")[/URL] it makes your program consume heavy resources. ( and it makes your program non-portable) Generally as a rule of thumb: you should always pass the size of … | |
Re: Excuse me but why use regex anyways: [code=python] >>> lines=['this ends with;','but this ends with:'] >>> print [ x for x in lines if x.endswith(';')] ['this ends with;'] >>> [/code] |
The End.