6,741 Posted Topics
Re: >how can i achieve to have the program to randomly choose a number from 0 - 27? [code=cplusplus] #include <cstdlib> #include <ctime> #include <iostream> int main() { std::srand ( (unsigned)std::time ( 0 ) ); int r = rand() % 28; std::cout<< r <<'\n'; } [/code] Further details can be found … | |
Re: Why not use an enum for the blood type instead? That way you don't have to validate a random string. | |
Re: >Can any pro fren show me the function to code it? I imagine it would be something like this: [code=cplusplus] void button_Click ( Object^, System::EventArgs^ ) { tabControl->TabPages->Add ( gcnew TabPage ( "Dynamic Tab" ) ); } [/code] | |
Re: When you need it, you'll have your answers. >But why not declare the variable we need to the appropriate type >during programming time rather than downcasting it at run time? Because that might not be practical. Consider an array of base class pointers with varying dynamic types down the hierarchy, … | |
Re: 1) You have several options. Here are a few: [LIST] [*]Create your own case insensitive traits class and apply that to your strings. [*]Convert all of your strings to one case before doing comparisons. [*]Forget about the string specific search member functions and use STL-based searching where you can provide … | |
Re: >I've been stuck here for a while now... So basically you don't know how to calculate a prime number? | |
Re: >How do i read the lines of an file into an vector? [code=cplusplus] #include <fstream> #include <iostream> #include <string> #include <vector> int main() { std::ifstream in ( "myfile" ); if ( in ) { std::vector<std::string> lines; std::string line; while ( std::getline ( in, line ) ) lines.push_back ( line ); … | |
Re: >I haven't been able to find much on the internet about it. It's really nothing more than a bucket sort where each bucket holds a count for each number on the range: [code=c] #include <stdlib.h> int pigeonhole_sort ( int a[], int n, /* Array and size of the array */ … | |
Re: >Does anyone know the size of an enum? [code=cplusplus] std::cout<< sizeof ( foo ) <<'\n'; [/code] >is that 1 byte, but if i had 10 enumerations would that be 2 bytes, and so on? The number of constants doesn't change the size of the enum. | |
Re: strtol offers more error handling capability and is safer. atol is easier to use, but is impossible to properly check for errors and exhibits undefined behavior for some erroneous input. The basic difference is that you should use strtol unless your string has already been carefully validated and you're 100% … | |
Re: >is there a way to build a website with C? You can write CGI in C, if you really want to. But it's not really worth it as CGI tends to focus on the very thing that C is poor at: string manipulation. | |
Re: This isn't a chat room, please at least try to use proper spelling, grammar, and punctuation. >1_o(n log n) >2-o(n) Both examples (assuming I'm reading your poorly indented and thought out pseudo code correctly) are O(N^2). | |
Re: >but i didnt write that it is an online project Hmm? It sure looks like you did: [quote=mostafa mahmoud] Please guide me how to make such an online project in C++. [/quote] | |
Re: >How do you exactly put the friend function into this program? What friend function? The syntax looks like this: [code=cplusplus] #include <iostream> class Test { int i; public: Test ( int init ) : i ( init ) {} friend void display ( const Test& test ); }; void display … | |
Re: You forgot to ask your question. Also, if you want us to be able to compile the code, you'll have to include the contents of node.h. | |
Re: Do some research on pipes. Your system likely has a function you can call from C (popen, or similar) for opening a pipe based stream. Or, if you don't need access to the output from B, you can use the equivalent command line piping with the system function: [code=c] system … | |
Re: So your compiler supports long long, but no way to format it into a string? I find that hard to believe, did you check your compiler's documentation? At the very least there should be a non-standard function or extension that supports what you want. | |
Re: >I came across a new site "<snipped link>" You "came across" it, huh? :icon_rolleyes: In my experience, that's a lie. It's much more likely that you're somehow affiliated with the site and are trying to advertise it without looking like a spammer. | |
Re: >If you can use the source below and guide me what I should do next. Basically you haven't done anything, but you seem to understand the problem well enough. What you need to do is figure out how to add a new node at the correct position (as far to … | |
Re: >Here you are Somehow I don't think that's the problem, Ramy. >I have a little problem with resizeing my program for different screen resolutions. Do you mean that when the resolution is changed, your UI looks like crap? If so, the easiest solution is to use anchoring and resizing of … | |
Re: >you could use rand in time.h rand is declared in stdlib.h, or for C++, cstdlib. >Where can I find examples of this used in the manner you are describing? [code=cplusplus] #include <cstdlib> #include <ctime> #include <iostream> // Trick for getting the number of // items in an array of T … | |
Re: The only way is to escape the backslash. C++ doesn't support verbatim strings like C#. | |
Re: 1) Functions don't nest (you can't define buildListForward inside main. 2) You can't use a type that doesn't exist (you haven't defined nodeType). 3) Check your spelling. C++ is case sensitive and very picky about syntax. 4) If you say you're going to return a value from a function, do … | |
Re: So far all of your posts consist of short, pointless, broad questions such as this. It suggests that you're spamming simply to advertise your signature and have no interest in the replies. I recommend you take a step back and think about how your threads look, or you'll end up … | |
Re: >I really hope that is a typo and you meant: "solveD it already".... As do I. It takes some big rocks to demand such a thing when you have three post and no discernible reputation in the community. Anyway, in either case, it would be useful to know the answer. … | |
Re: I started writing out all kinds of suggestions on the assumption that you hadn't done anything and weren't sure about how to begin. However, it struck me that you may have a lot of this already written and want help with the MySQL access and server upload. So what have … | |
Re: You never call the function, you just redeclare it. To call a function you use the name and replace parameters with actual values. For example, here's how you might call each of the functions: [code=cplusplus] func1(); func2 ( 1.0, 2.0 ); func3 ( V, R ); func4 ( I, R … | |
Re: 1) Only if you plan on giving users of the class the ability to change the boolean directly. 2) Parse error, please try again. | |
Re: >I need to understand the concept of inheritance in Oops. >Can any one explain with real life example the use of inheritence to enhance a super class. >It will be very helfull to me if you can explain me the use of inheritence to build a simple car. It's actually … | |
Re: Here's a method that definitely can't be turned in as homework: [code=cplusplus] #include <iostream> #include <locale> #include <string> template <typename CharT> class numfmt: public std::numpunct<CharT> { CharT _thousands_sep; int _grouping; public: numfmt ( CharT thousands_sep, int grouping ) : _thousands_sep ( thousands_sep ), _grouping ( grouping ) {} private: CharT … | |
Re: You'd probably find [URL="http://www.codeblocks.org/downloads/5"]Code::Blocks[/URL] to be the easiest trial. It comes with a Windows port of GCC. Downloading and installing GCC manually can be a chore if you're not used to such things. | |
Re: >how can i transfer the address of "gradeTemp" to "numGrades"? Return and assign: [code=cplusplus] Grade **AddGrade(Grade ** _numGrades,int& _students) { // ... return _numGrades; } //... numGrades = AddGrade ( _numGrades, students ); [/code] However, that still doesn't change the fact that as soon as you overwrite numGrades, you've created … | |
Re: A string is basically just an array, why can't you simply start an index at the end and count down? | |
Re: Just get a random number between 0 and the number of sides on the die: [ICODE]rand() % sides[/ICODE]. There's no complex logic involved. | |
Re: >but problem is this it is too lengthy It's not that long. But at a glance it looks like you have a lot of repeated code that can be moved to a function. Also, indent your code and put it in code tags. Seriously, what you posted is so difficult … | |
Re: >Can anyone give me a simple idea how to remove the duplicated letters in a text Can you be more specific? Should the two L's be removed in "SLOWLY"? If so, which L should be removed? Are the characters to be ordered in any special way? All of these play … | |
Re: Well clearly the flux capacitor is overloading the compiler, accelerating your CPU to 88 miles per hour and sending part of your line to 1955. Give it about two hours for the line to find its way back and you'll find that most of the bugs in your program are … | |
Re: >Is it possible to find the variablename from Numbers[0] wich is Number2 ? Not easily, no. The variable name is a symbol that's not available at runtime unless you store it as a string in memory. Perhaps I can give a more helpful answer if you explain what problem you're … | |
Re: More details please. What compiler and OS and is this a GUI program or command line? | |
Re: >How can I fix it so it outputs the date entered by the user when there is an error? You're printing the value of the date itself in your error message. At that point, the date has already been checked, errored, and set to the default. Unfortunately, I can't tell … | |
Re: When you say "strings of integers", what do you mean exactly? | |
Re: >Is this possible? Yes, but it's not the most brilliant of ideas. What exactly are you trying to do that prompted this question? | |
Re: >is there a built in function to deal with numbers similar to how the swap member function Yes, include <algorithm> and you can use the std::swap template function as AD has shown. | |
Re: >everytime it writes to my file it overwrites the previous data stored with in it It sounds like you keep closing and opening the file with the ios::out mode. In write mode, the newly opened file is truncated to zero length. You can avoid that by using ios::app (as you … | |
Re: >the segmentation fault is in the merge sort but i can tfind out how to fix it A segmentation fault means you accessed memory beyond your boundaries. If you're using a pointer it likely means the value of the pointer is incorrect. If you're using array indexing, it likely means … | |
Re: Once you open the stream, it's basically the same as working with stdin and stdout. What problems are you having with your code? | |
Re: >I want middle [Iterator type ] to be static And what are you expecting this kind of optimization to buy you? | |
Re: 1) You can close and re-open a file stream, but if you read the previously opened stream to end-of-file or there was an error, you need to clear the stream state: [code=cplusplus] #include <fstream> #include <iostream> void read_stream ( std::istream& in ) { char ch; while ( in.get ( ch … |
The End.