518 Posted Topics
Re: >>Same for #include<stdlib.h> The standard file for the old stdlib.h is <cstdlib> | |
Re: >>now where exactly should I include these in my class? As these are the definitions of your class, it can either go right after where you defined the class: [code=cpp]class Rational { private: // private members declaration public: //public members declaration }; Rational Rational::addition(Rational a, Rational b){ Rational result = … | |
Re: There is no return statement in squared_digit_length. ![]() | |
Re: daviddoria, read this [url]http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5[/url] Perhaps this would convince you if John is not able to. | |
Re: I don't think the code is C++. [B]I request the MODerators to move the thread to C[/B]. I infer no reason for this thread not to be in C forum. It qualifies to be in C forums more than C++ forums >>as the code you posted is compiling with me … | |
Re: Comment on Orignal Post: When defiing an array in C++: A[n] , the subscript n can go from 0 to n-1 Both the OP and Ancient have not considered this. You have defined array as: A[3] but you are using n from 0 to 3 >>is it possible to put … | |
Re: >>please, if i could send you my code, is there anyway u would be able to help me. thanks for your response... What the ____? Narue has already given you the standard c++ code. What else you can expect as 'help'. >>what better protection than allowing a backspace as part … | |
Re: [code=cpp]for (int day = 1;day <= days;day++) { // I just declared a new var to avoid calling pow two times int current= pow(day-1,2.0)+1; total = total + current; cout << "Day: " << day << " Daily Salary " << current << " Total: " << total << endl; … | |
Re: >>You are missing a '{' between these lines. He is actually misplacing '{'. The defination of function in C++ is : [code]<return_type> <function_name>([parameteres]) { //codes }[/code] rather than[COLOR="Red"] [code=NOT_CPP] { <return_type> <function_name>([parameteres]) //codes }[/code] [/COLOR] So make your definition as: [code=cpp] double taxAmount(double taxRate, int perExempt, int numberofPeople, double taxRate) … | |
Re: >>Here is where I am at with the code: It would be better for you to follow the instruction strictly: [QUOTE]If the name is in the lastname, firstname format, then it needs to be changed to the firstname lastname format. To do this: * Copy the firstname to a temporary … | |
Re: Someone said that a program is algorithm+data structures. Ancient has given you the algorithm. I would like to recommend a data structure:[B][URL="http://www.cplusplus.com/reference/stl/map/"]map[/URL][/B] to store the number of occurrence of each vowel. | |
Re: >>i just wanted to know the basics of what to do in this problem. RTFM. To be polite, here is are the steps you must take: [code] 1. Construct an Array 2. Ask user how much quantity of data is to be inputed 3. Input all those elements from the … | |
Re: >>firtly you divide the number by 10 . and then myltiply the number by 10. It is lot better to use the modulus operator. [code=cpp] int N=85; int Ones,Tens; Ones=N%10; Tens=N/10; [/code] | |
Re: Do you mean search records in a array of a struct? It can be quite tough for us to help without knowing what your struct look like. Post the code of your struct or anything what you have tried. Searching a struct involves searching value of a key member of … | |
Re: Rather than [icode]cin>>*x[index];[/icode] You should perhaps try: [icode]cin>>(*x)[index];[/icode] Precedence of [B][ ][/B] is higher than [B]*[/B] [url]http://ocw.kfupm.edu.sa/user/ICS43153/Reference/C-Reference/C-Prog/section3_16.html[/url] The the statement you wrote in the first post will be interpreted like this: [COLOR="Red"]*(*(x+index))[/COLOR] As you can see, this has got no meaning. Rather the code I just gave would be interpreted … | |
Re: Didn't your professor told you about 2dim arrays? [code=cpp] const int MAX_LEN=20;//maximum length of eachname char names[10][MAX_LEN];//create a 2D array to hold 10 names of length 20 int N=10;// for( int i=0;i<10;i++){ cin.getline(names[i],MAX_LEN); } [/code] Reference to the function used in above code: LIne 2:[url]http://www.cplusplus.com/doc/tutorial/ntcs/[/url] Line 5.[url]http://www.cplusplus.com/reference/iostream/istream/getline/[/url] As I know … | |
Re: Use the replace member function of the std::string. Some reference may be found on the link below. [url]http://www.cplusplus.com/reference/string/string/replace/[/url] | |
Re: In this case(where you need to initialize a structure to a arbitrary value), you need to write a constructor for that. Constructors are part of Classes. But in C++, even structures can have constructors,destructor member function etc.. Loosely speaking, structure is as same as a class except that the members … | |
Re: Please. Please Don't use void main. [url]http://cppdb.blogspot.com/2009/02/should-i-use-void-main-or-int-main-or.html[/url] And yes, you are adding the squares of the integer rather than the square root. To find the square root, you need to #include <cmath> and use the pow() function.[url]http://www.cppreference.com/wiki/c/math/pow[/url] | |
Re: Well, I guess the kid is ready to slash the mountain. You basically want to write your own language. There is a Bible for Compiler writing which called Dragon Book. [url]http://en.wikipedia.org/wiki/21st_Century_Compilers[/url] It is a vast book. If you are dedicated to write a language, you should pay a price, i.e. … | |
Re: >>Like I was saying, why does it seem like some of the posts here are an ego-contest? What is the harm? Dani-web has a good ranking in various search engines. So its not only the member of Daniweb which are using it but some guests too. The "Vets" which you … | |
Re: >>22/7 is a poor approximation of pi. Very right. PI=3.14159265 22/7 =3.14285714 Your program is not doing good. What I meant to say is the aim of the program is not clear. Moreover, you are using old headers, using void main. Never use void main [url]http://cppdb.blogspot.com/2009/02/should-i-use-void-main-or-int-main-or.html[/url] I agree with Tux4life … | |
Re: >>head is a pointer to a list of pointers. Wrong. [I]head[/I] is a reference to pointer to CharNode. To understand this(that why it is been passed by reference), just remember the basic pass by reference, i.e. pass by reference allows you to change the value of the parameter passed. In … | |
Re: >>[ICODE]int main(void)[/ICODE] old syntax. Preferred is[ICODE] int main()[/ICODE] >[ICODE]quadraticFormula(a, b ,c, &x[0]);[/ICODE] the last argument passed is same as passing x only. Since a name of array is pointer to first element. Hence use:[ICODE] quadraticFormula(a, b ,c, x);[/ICODE] >>void quadraticFormula(double a, double b, double c, double *totalResults) I suggest you … | |
Re: Did anyone forgot: The Art of Computer Programing by Donald Knuth? | |
Re: It is a input statement from the standard input device(the keyboard). the Equivalent c++ code could be: [code=cpp]std::cin>>tside;[/code] Or if you want a converter which shall convert C to C++ check this [url]http://www.scriptol.com/scripts/ctocpp.php[/url] even this [url]http://www.softforall.com/SoftwareDev/ToolsEditors/C_to_C___Converter08110221.htm[/url] | |
Re: I would use a map from STL. Actually, map is a better data structure to be used in this case. To the OP: It is still not clear if you want to convert a Roman letter (like 'V' 'I' 'L' 'M') or a whole roman number( like 'IV' 'VII' ). … | |
Re: Where are the Data members? I appreciate that you have modified complex number class to work here. This is a good example of code re-usability. But a Private inheritance in this matter would have been more eye-catching. Well, The program has several typographical and syntactical errors. Correct it!!. | |
Re: This code won't compile. You cannot use namespace with old c++ library (iostream.h). Drop the second line of your code or use iostream instead of iostream.h | |
Re: >>You just use it like the sin function ... Caution!! the Domain of arcsine function is from [-1.1]. I suppose the OP would be aware of this since he is dealing with it. Also, return value is the principal value: -pi/2 to +pi/2 PS: I know all this must be … | |
Re: [QUOTE=Learner]Passing by reference means the value of the parameter passed in may be changed during the function and that value will be reflected back in the calling function as well.[/QUOTE] Well you are right. But there is often the case when passing-by-reference-to-const comes handy. It is usually the BEST method … | |
Re: To the OP: Read the vmanes post. It is the most relevant here. Technically, you are correct in defining printGrade as [I]void[/I]. But as other pointed, the defination should have been also of a [I]void[/I] return type as you function names suggests that it should PRINT a value rather than … | |
Re: [QUOTE]I need the full code of how to do it[/QUOTE] You would never get full code here. Google is your friend. Here is a nice article here on Daniweb about generating Random Numbers:[url]http://www.daniweb.com/forums/thread1769.html[/url] Off-Topic "Laughter Laughter, Laughing at my cries" | |
Re: what are [I]lyrics[/I] and [I]artists[/I]? are they functions? if yes, you should call them by [I]lyrics()[/I] and [I]artists()[/I] [code=cplusplus] switch (user_choice) { case 'A': lyrics() break; case 'B': artists() break; } [/code] | |
Re: >>I have a namespace in my header file and a variable declared in it. Is this a .h header file? If yes then you may be perhaps compiling it separately which is not required. say I have a header file [B]my.h[/B]: [code=cpp] namespace my { int a; } [/code] and … ![]() | |
Re: There are a lot of GUI libraries available. wxWidget is a cross-platform free open-source library for developing native GUI Another is GTK+(with the gtkmm port for C++), which I use is best if your platform uses GNOME as its desktop environment. Though, GTK is also cross-platform free open-source. If you … | |
Re: >>int co; // variable count occurences AKA co you have not initialize it to zero. So it now contains some junk values. When you increment it will increment the junk values so the output won't be proper. Write : [icode]int co=0; // variable count occurences AKA co[/icode] Also, the question … | |
Re: Ancient hits the bulls eye. Here is a excepts from Stroustrup's homepage: [url]http://www.research.att.com/~bs/bs_faq2.html#null[/url] [QUOTE=Bjarne Stroustrup]Should I use NULL or 0? In C++, the definition of NULL is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0. Another problem with NULL is that … | |
Re: [TEX]n=mt[/TEX] is the other way of writing that [TEX]\frac{n}{m}=t [/TEX] where [TEX]t[/TEX] is a integer it means that if you divide n by m, the division should leave no remainder. >>we have to use if in these statement (m!=0)(m%n==0)(m<n) right?? yes >>and we don't need to use loop, right?? No … | |
Re: I am surprised that the OP is not even participating in the discussion! Anyway, if the OP bothers to see this thread, here is somewhat explanation from my side: There are three loops in C,C++ namely while, do-while and for. Let this be clear in your mind that each loop, … | |
Re: >Don't stop C++ programs with exit() function (except on severy run-time errors). I fully agree with ArkM. exit(0) is evil I would extend ArkM's advice that you should not use exit(0) even in case of runtime errors. You should use exception handling mechanism. Ideally, All functions, sub routines should end … | |
Re: If you drop Point #2, Python can be your wand. It is a language which will support easy transformation of your ideas to codes. If you drop Point #4, C++ satisfies all the above points. Perl is an interpreted language. I still would go with python since it is really … | |
Re: There is a website I remember which helped me when I ran into the same problem. It is called Google.com You just have to type "File Handling in C++" as the search query and you will get more than your thought. Please try it | |
Re: All your header files are non-standard use <iostream> <cmath> <string> instead of what you are using.What compiler are you using? Palindrome problem is not new here. Remember, you should search the forum first before starting a new thread. Here are few thread I found by simply using the search option … | |
Re: >>[code]writer.write(&img_pix[i].rgbb[0],1);[/code] I don't know what is the type of img_pix but if it is not char, you better use a cast to char [code]writer.write(reinterpret_cast<char*>(&img_pix[i].rgbb[0]) ,sizeof(&img_pix[i].rgbb[0] );[/code] | |
Re: You can of course return pointer to any object via function. The syntax is pretty much intuitive: [code=c++] returnType* myFunc(argType1 arg1, argTyp2 arg2.......) //example int* someFunct(int a, int b){} char* someFunct(char* A, int Len) [/code] Now, stand up dude, do some Google search and you will find much more than … | |
Well, first of all I will speak much so that you guys can target my problem better. Hello, I am a poster from the C++ forum. Hence, I am a well established C++ programmer. Now I want to learn Python. First of all, should I? I mean, keeping in mind … | |
Re: Your problem is just like (actually same as) Project Euler problem 18 & 67 [url]http://projecteuler.net/index.php?section=problems&id=18[/url] I cracked the problem. I used down to up approach. Well I am feeling a lot lazy to type down my algorithm. But never mind. When we answer at Project Euler, we get access to … | |
Re: >>or as a reference Good Point. Its mostly better to pass arguments by-reference-to-const rather than by-value. | |
Re: Hmmm, I have seen the exact question before on this forum. Anyways, first of all I am glad that you have used code tags on your first post. >>BUT i don't know how I should set the Mem pointer In the constructor, you should use [B]new[/B] operator to assign required … |
The End.