518 Posted Topics
Re: In some books I read: Elevator Simulation:: The program will simulate elevators. The user pushes a button ( by pressing a number key on the keyboard. Number indicates the floor on which he is) and then the elevator decides its path so that it could fill up requests of most … | |
Re: >>I believe this is how I would input the data but i'm not totally sure on that either... Run the damn code and tell us if it worked fine or gave error. If error, what error? | |
Re: [URL="http://www.innosetup.com/isinfo.php"]Inno Setup[/URL] is a free installer for Windows programs. I used it my several projects wherein I needed to port my Linux Application to Windows user ( windows user really like this setup.exe) You will be amazed by its simplicity and power. | |
Re: You perhaps should enable the "View Hidden files" option from the folder option of the windows explorer. | |
Re: Try this: [code=cpp] class Bike { public: Bike (const int, const string, string, double); private: const int w; const string b; string c; double ws; }; Bike::Bike(const int wheel, const string brand, string color, double wheelsize): w(wheel), b(brand), c(color), ws(wheelsize) {}[/code] It is generally better to write constructor using member … | |
Re: [COLOR="Green"]&p[2][/COLOR] is same as [COLOR="Green"]&(*(p+2))[/COLOR] which is same as [COLOR="Green"]p+2[/COLOR] So cout<<p+2 will print the array which has the the first element as the 3rd element of p. Hence the output is "ndon" p[11] means *(p+11) that means "tell me the value of the 11th location from p" (remember p … | |
Re: You could create a array called [B]count[/B] and store the number of occurrence of each of the element of test[] in that. Then simply find the largest element of count[]. Suppose then the largest element of count[] is the k-th element, then the mode will be test[k]. | |
Re: >>in php we can append string, how could I do this in C++: You could if you were using strings in C++. But the very fact is that you are not using strings but c-strings here. [code=cpp] #include<iostream> #include<string> int main() { std::string arr="Foo Bar"; std::cout<<arr; //prints Foo Bar arr+="X"; … | |
Re: There are several option when you write functions that return multiple values: 1. Using references: You could have few parameters that will be passed as references and use them to store the output [code=cpp] void split_decimal(double input, int& integer_part, double& fraction_part) { integer_part=static_cast<int>(input);//convert input to integer // and store in … | |
Re: Boost's Asio is a good one if you want it platform independent: [url]http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio.html[/url] I have seen more of platform specific libraries which could suit you. There is an excelent Beej's Tutorial on Sockets with C, but it works with C++ too. You will need to code like a C programmer … | |
Re: What is the error message? [code=cpp] chg = RATE606; else if loc = (zip.find("605", 0)); (loc >= 0); [/code] else if requires a condition. The proper code would have been [code=cpp]void calcShippingCharge(string zip, int RATE605, int RATE606, int &chg) { //search zip code for proper prefix if (zip.find("606", 0) != … | |
Re: You could also do something like this [code=cpp] for (int i =0,curr_pic=3; i < 52; i++) { Card[i].Num = i%13;// Num will only get value from 0-12 Card[i].Pic = curr_pic; if( i%13==0) //after every 13 cards increment the value of cur_pic cur_pic++; } [/code] | |
Hey, I saw some textual reputation here on Dani for short period some minutes ago. "siddhant3s is a jewel in roghsiddhant3s is a jewel in roghsiddhant3s is a jewel in rogh" Yeah, it was repeated many times. Then I checked that some text reputation was assigned to everyone!! Whats that. … | |
Re: >>Why didn't the C++ standard also have the delete operator reset ptr to NULL? First of all you are simply **NO ONE** to ask question like this. C++ standards have been made by the most proficient and experienced programmers of this language. If you think there should be a feature … | |
Re: Read: [url]http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.2[/url] And then look at Narue post | |
Re: Just make the parameter of function of type istream and pass by reference. Maybe an example would help: [code=cpp] int print_the_istream(std::istream& the_stream) { if (! the_stream) return 0;// error, return false std::string buff; while (!the_stream.eof()) { the_stream>>buff; std::cout<<buff; } return 1;// return true.Everything is fine } //usage: int main () … | |
Re: He perhaps, meant that he wants to customize the uranary * operator ( the dereferencing operator) for is custom class. I don't know why would you like to do that but here is what I got: Overload dereference operator like this: [code=cpp]T& operator*() const //this will return some value of … | |
Re: void main is a crime. Always use int main. [url]http://cppdb.blogspot.com/2009/02/should-i-use-void-main-or-int-main-or.html[/url] if( day=0) will always be true. Use if(day == 0) instead. There is a difference between = and ==. The former is an assignment operator. The later is a logical operator, it evaluates whether the LHS and RHS are equal … | |
Re: Checked your program, it is running just fine. You are asked to show that the exception handler which takes the Base class(runtime_error) as its argument can handle exception where the derived class(DevideByZeroExeption) is thrown. This is perhaps what your instructor wants from you: [code=cpp] try { result = quotient( number1, … | |
Re: You have to first create a data structure. An array or vector of int should be the most correct data structure. Then ask the user how may value you need to input. Run a loop and accept all those value in a vector ( or array,) from the user. ( … | |
Re: This is from [url]http://www.cplusplus.com/reference/string/string/data/[/url] about string::data: Get string data Returns a pointer to an array of characters with the same content as the string. Notice that no terminating null character is appended (see member c_str for such a functionality). So modify your code something like this: [code=cpp]cout << "Enter the … | |
Re: You have to prefix std:: before ofstream, as in [code]std::ofstream myfile;[/code] >>f:\sp\vctools\icrt_bld\self_x86\crt\src\open.c Is this your source file? This is a .C file. Make it .CPP This may fix your problem. Some implementation (particularly on windows) wants your source file of C++ to end with .cpp | |
Re: You don't have to do this. It will be a very nice thing if your compiler will point out the error for you. In this case it will. Just tell the user of your class that you can only templatize those classes which have the CompareTo function. This way, if … | |
Re: Gtk+ can be a real pain on Windows. I got it to work after several attempts. There is a GTK+ installer for windows available on the website. The main problem arises, when you need to compile your GTK+ code. My team used Code::Block IDE on windows. But we were not … | |
Re: >>There are several free compilers, such as Code::Blocks, Dev-C++, and VC++ 2008 Express. ( Note to OP: I am talking to Ancient Dragon, this has got nothing to do with you) I never knew Code::Blocks and Dev-C++ are compilers!! I thought they were IDEs ;) Or am I sensing it … | |
Re: A general swap algorithm is : [code]//say you want to swap var1 and var2 temp= var1; var1=var2; var2=temp; [/code] In c++ you can use the ready made function [URL="http://www.cplusplus.com/reference/algorithm/swap/"]std::swap()[/URL] defined in <algorithm> header file which can do this job for you. [code=cpp] // swaps the content of m-th element of … | |
Re: >>Edited the code, try again, Sorry, OP is right. x[100]={1,2,3,0,3,5,4,1}; will print 2 elements To the OP: You cannot !. Yes you cannot. However surprise it may bring to you, the truth is you really you cannot. Thats why most of functions dealing with int array often asks you to … | |
Re: >>char* userData = "\0"; Seeing this? This tels the compiler to allocate 2bytes to userData, So if your user enter text more than one character, you're doomed. Better change to this: [code=cpp]const int MAX=20; char userData[MAX];[/code] I am smelling that you are using an old compiler. If not, why not … | |
Re: >>I think you should send the argument "word" as a reference and not copies of the argument. He is passing a pointer actually. >>the encryption function is working fine, but I'm having troubles with the decryption. Even Encryption is not good. Here is the output: [code]siddhant3s@Xion:~/Documents$ ./testofcallbyreference Enter the word … | |
Re: RAND_MAX is a constant defined by your implementation ( i.e. it is defined by what compiler are you using on what platform) is a large number but it is at least 32767(it may be greater depending on your implementation) rand() function generates a random integer between 0 and RAND_MAX For … | |
Re: To generalize: :: stands for scope resolution operator( I know you know this) which has two operand : the scope[1] and the object/function. When you don't write the scope explicitly ( like ::gcd() ) it means you are referring to the global scope. [1] Scope can be a Class or … | |
Re: >>initialize static member function >>initializing a function These two things doesn't mean anything in C++. You don't initialize a function. You initialize an object ( or a variable, whatever you call them). Things you can do with functions are: Declare them Define them Call them Overload them Templatize them May … | |
Re: >>I initialize the matrix as following and when then I cout, the program crashes.. Look at the [B]<endl[/B] it should be [B]<<endl[/B] Are i and j defined? Try running this code on your compiler; [code=cpp]int matrix[512][512]; for(int i=0;i<512;i++){ for(int j=0;j<512;j++){ matrix[i][j]=-1; } } cout<<matrix[100][100]<<endl;[/code] | |
Re: I have not seen your code thoroghly but the immediate thing I would like to point out it this: [icode]if (a = months+12){[/icode] as you may see you have used a = rather than ==. In c++( and even in C) = will always evaluate true. To test for a … | |
Re: To the OP: As it has been said: Programming is an Art. Some have god gifted talent in programming. Others develop their talent by practicing more problems. It is simply not possible for us to solve this problem (of having non-logic mind in programming.) | |
Re: Your solution is posted as the announcement of DaniWeb :[URL="http://www.daniweb.com/forums/announcement8-2.html"] We only give homework help to those who show effort[/URL] This is what it reads: [QUOTE=Administrator of DaniWeb]This forum is meant for discussing programming languages in addition to exchanging code and algorithms. However, it has become a problem where too … | |
Re: [QUOTE=Argo]so the problem is, I don't know how to fill it with data. I've seen that you could use myMap.insert<pair<some stuff... but i dont know how or if you can use that on maps of maps. [/QUOTE] I don't know why you created maps of maps. maps of [URL="http://www.cplusplus.com/reference/std/utility/pair/"]pair[/URL] would … | |
Re: show the code of extract_key | |
Re: >>do I have to define the structure globally? No just declare it globaly. Like this [code=cpp]struct ROPES; int fillStruct (ifstream& fin, ROPES ropes[], int n); int main() { struct ROPES { members }; return0; } int fillStructs (ifstream& fin, ROPES ropes[], int n) {} [/code] | |
Re: Read the prototype of [URL="http://www.cplusplus.com/reference/iostream/istream/getline/"]getline[/URL] The first argument should be a char array ( a cstring). Tell us what is the structure of student. | |
Re: You are not using the peek properly: The code should be like this [code=cpp]int main() { int num1, num2; char chr; cout<<"Enter an integer to start: "; while (cin.peek()!='|') { cin>>num1>>num2; cout<<num1<<' '<<num2; //do things with num1 or num2 } cout<<"Bye!\n"; }[/code] | |
Re: >>[icode]cout << (dynamic_cast <Person*>(p))->getAverage();[/icode] Look what are you doing. You are casting a Person pointer with Person only. What is the effect? change it to [icode]cout << (dynamic_cast <Student*>(p))->getAverage();[/icode] | |
Re: Read: [url]http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/[/url] >>Can someone tell me what happens to checkSum with this sprintf method checkSum is a c-string( array of chars) its value is set by Total's hex value converted to c-string. In short, after this command, Total will be converted into its hex and in form of a string … | |
Re: >>// With the "(" and ")" added i guess it should copy value like pointers do Even if you didn't it would still be same. To the OP: The "Test" of you professor is perhaps not good. The interface given by him is already implemented as [URL="http://www.cplusplus.com/reference/string/string/swap/"]std::swap[/URL] What sky diploma … | |
Re: This is what I always say: Use the standard library for the standard jobs. If I assume you are familiar with std::vectors, std::maps, std::sort, there is no reason not to use them. 1.Create a std::map of <string,double> 2.Transverse the file and store the GPA of the particular name in the … | |
Re: >>Start learning C, then you can go into the object oriented parts of C++ Bad advice. Will turn into the "I-write-c++-code-but-am-actually-a-C-programmer". If you want to learn C++. Learn C++. Don't learn C. Rather it can perhaps spoil your C++. C++ and C are two different languages. Read the following thread:[url]http://www.daniweb.com/forums/post818590.html#post818590[/url] … | |
Re: > Making p a shadow of an int p sneaks the error past the compiler in your example. // typename // Compiles with logic error if commented out` > end quote. If you uncomment the typename, you are intentionally telling compiler that `T::Baz` is a type which is, off course … | |
Re: [QUOTE=Clockowl]>>I really enjoy GTK+/gtkmm. Lots of demos and documentation. [/QUOTE] True. I too use GTK+ as for the same reason that it has loads of documentation. But warn you, GTK+ don't go so 'native' on windows. Anyways, If I got to choose form wxWidget or QT I will choose wxWidget … | |
Re: Considering that you have already have defined LinkedList::getPoly(int n) Your operator[] should look like this. [code=cpp]Polynomial& Database::operator[] (int n) { return getPoly(n); }[/code] |
The End.