537 Posted Topics
Re: The string member [URL="http://www.cplusplus.com/reference/string/string/capacity/"]capacity()[/URL] is defined as: [quote] Return size of allocated storage Returns the size of the allocated storage space in the string object. Notice that the capacity is not necessarily equal to the number of characters that conform the content of the string (this can be obtained with … | |
Re: Since you are using c-strings (character arrays) you do not get the luxury of using the <string> class overloaded == equality test. But what you do get is a bunch of [URL="http://www.cplusplus.com/reference/clibrary/cstring/"]<cstring>[/URL] library functions that will allow you to handle your character arrays with great ease: [CODE] #include<cstring> //instead of … | |
Re: I do believe our good friend adrianxw can help you with your desired console graphics and/or mouse needs: [url]http://www.adrianxw.dk/index.html[/url] | |
Re: I am really not sure what is going on here. You are attempting to use a main() function like I've never seen it before. Therefore, this method you are using is more than likely unconventional. To me, it seems like you are declaring an 'int' type variable called main (which … | |
Re: 1. What specifically about the project is giving you problems? 2. Why did you take this course if you didn't want to make some sort of effort to learn the material..??! | |
Re: You pose quite the intruiging and insightful question: [URL="http://eternallyconfuzzled.com/index.html"]Binary Search Trees[/URL] [URL="http://eternallyconfuzzled.com/index.html"]Randomized Binary Search Trees[/URL] [URL="http://eternallyconfuzzled.com/index.html"]Balanced Binary Search Trees[/URL] | |
Re: Here you create function specific variables that will be destroyed as soon as the function ends: [CODE] void calculateTotal(double heads, double tails) { double win = heads * 2; double lose = tails * 1; double total = heads - tails; [/CODE] Therefore, you have no method of keeping record … | |
Re: [CODE] #include<cmath> height = (distance * tan(angle)) - (gravity * pow(distance, 2)) /2 * pow(speed * cos(angle), 2); [/CODE] | |
Re: [quote] can only use nested loops NO arrays or strings[/quote] I was kinda stumped at first until I came up with a linked-list of chars: [code] #include<iostream> #include<cctype> using namespace std; struct node { char letter; node *next; }; int main() { node *head_ptr = new node; node *list = … | |
| |
![]() | Re: Just do the opposite of what you are doing and it will rotate your 'cube' in the other direction. |
Re: [quote]Could someone please help me figure out what is wrong with my program?[/quote] Is there anything wrong with your program? I don't know. Does the program do something you don't want it to do? Do you have compilation errors? If so, what are they? You declare: float celsius and float … | |
Re: [quote] jst m not able to think how to exrtract data from string.. [/quote] We can use our standard string parsing algorithm. In this case, we can use [URL="http://www.cplusplus.com/reference/string/string/find_first_of/"]find_first_of()[/URL] since we will have multiple delimeters (+, -, *, and / for example) [code] string expression = "5+104-32/5"; string terms[20]; int … | |
Re: [quote]any suggestions?[/quote] Show us the code? | |
Re: Here is the pseudo-code for what you wish to accomplish: 1. create an array of integers that will be large enough to handle user input. This array will hold all of the 'n' rectangle data 2. using a loop, continuously prompt the user for coordinates until until such time user … | |
Re: This is a common mistake whilst performing tests using boolean logic; there is a distinct difference between the '=' assignment operator and the '==' equality test. (the '=' assignment operator should never be used to perform boolean tests) | |
Re: I am really unclear about what you are trying to accomplish... If you want to sort strings alphabetically, I can help you with some simple code. If you want to campare two strings, you could use the string class overloaded == equality test. If you are trying to compare two … | |
Re: [url]http://www.daniweb.com/forums/thread234979.html[/url] | |
Re: you could probably do something like this: [code] int total = 0; for(int counter=0; counter < i; counter++) { total += product[counter].price; } cout << "Total goods sold is: " << total;[/code] Good looking well coded program btw. The only critique I have is that I would probably use a … | |
Re: I just want to say that I love the title of this thread and I hope it stays at the top for awhile. | |
Re: you can easily perform a test on an entire range of values: [code] //If 'x' is greater than or equal to 1 AND 'x' is less than or equal to 380 if(x >= 1 && x <= 380) { //Do amazing things }[/code] | |
Re: If you were using an array of structs, I would simply just tell you to sort the array based on the desired struct attribute, and simply pick off the struct at the begging and at the end of the array. But since this is not the case, the best technique … | |
Re: Here is your insert node function: [code] void insertWord (ifstream& wordIn, wordRec *letters [], int& index, string& word, int& wrdIndex) { [COLOR="Red"]wordRec *head = NULL;[/COLOR] wordRec *newNode = NULL; [COLOR="Red"]if (head == NULL)[/COLOR] { newNode = new (nothrow) wordRec; newNode->newWord = word; newNode->previous = NULL; newNode->next = newNode; if (head … | |
Re: [code] for (x = 0; x<15; x++) { storage[x] = number; cout << storage[x] << " " << endl; [b][COLOR="Red"]break;[/COLOR][/b] }[/code] the rest of your code looks pretty good i have to say. | |
Re: I would study the <windows.h> library for your GUI needs. | |
Re: [code] #include<windows.h> #include<sstream> #include<string> using namespace std; /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); /* Make the class name into a global variable */ char szClassName[ ] = "calculator"; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; /* This … | |
Re: [quote]i am in need to change my char to int.[/quote] You are in luck.. char to int conversions are wicked easy.. (and so is any conversion among c++ standard primitive data types) Most people like to use the old c-style cast because it's quick and easy although technically it's not … | |
Re: [code] int counter=0; while(...) { ... ... ... counter++ } cout << "The while() loop executed " << counter << " times.";[/code] | |
Re: I would read from the text file and store the contents of the .txt file into some sort of a container; probably a <string> class object. Once you have your string container(s) populated, loop through the string(s) and keep two counter variables that will increment any time a string == … | |
Re: [url]http://www.daniweb.com/forums/thread234545.html[/url] | |
Re: I believe ye' problemo might be here: [code] [COLOR="Green"]//Here you declare 'int counter = -10'[/COLOR] int counter = [COLOR="Red"]-10[/COLOR]; [COLOR="Green"]//Here you delcare an array[10] (creates elements 0 thru 9)[/COLOR] int xyMax = 10; int xData[xyMax]; int yData[xyMax]; [COLOR="Green"]//Here you attempt to access array elements less than array[0][/COLOR] for (counter; counter … | |
Re: This is what should be running through your head: 1. create an ifstream object 2. attempt to open a .txt file 3. perform error checking to see if file actually opened (may not exist) 4. If open, read in .txt file into <string> class containers 5. close the ifstream object … | |
Re: 1. create an ifstream object 2. attempt to open a .txt file 3. perform error checking to see if file even exists 4. read in the entire file to an array of strings 5. close the ifstream object 6. using the <sstream> library create a ostringstream object 7. perform string-to-int … | |
Re: Let me offer this suggestion: Using the [URL="http://www.cplusplus.com/reference/algorithm/sort/"]sort()[/URL] function from [URL="http://www.cplusplus.com/reference/algorithm/"]<algorithm>[/URL] we find that there is an overloaded version of sort() that will allow us to supply our own custom-made 'test' function. Let's use this in order to specifically perform a test between two 'deques of structs'. We'll base our … | |
Re: [quote]finding and storing the relevant line number the string was located at on the file in the token objects.[/quote] If I understand you correctly, you seem to be in need of keeping track of what line you are at whilst reading from a .txt file. So, I will suggest a … | |
Re: What are you trying to do... your entire post doesn't make a lick of sense. | |
Re: Try this and see if it works for ye'... [code] std::string& write(); std::string& test::write() { std::string *name = "HELLO"; return name: }[/code] | |
Re: Good news.. the solution to your problem is wicked simple. May I recommend the [URL="http://www.cplusplus.com/reference/clibrary/cmath/ceil/"]ceil()[/URL] and [URL="http://www.cplusplus.com/reference/clibrary/cmath/floor/"]floor()[/URL] functions of the <cmath> library. | |
Re: Here is suggested pseudo code for what ye' want to accomplish: 1. create an ifstream object (for opening & reading from file) 2. create an ofstream object (to write to the file) 3. open the source .txt file 4. perform error checking (see if file opened properly & if it … | |
Re: In this block of code, you only make one call to 'infile' your data. You should consider infile'ing your data whilst inside of a loop to ensure you will read in data until you reach end of file: you have this: [code] else { //This code to read data only … | |
Re: in line #8, you no longer need to typedef a second time... just go ahead and create your object: [code] addr a; [/code] | |
Re: Here is a quick poor man's method: [code] int elements = sizeof(serviceinfo) / sizeof(serviceinfo[0]); [/code] | |
Re: [quote] so my question is how do i center the first line ?[/quote] From what I understand, you are wanting to center a line of text on the dos console screen. Assuming that the standard screen will support 80 characters, we can derive the following formula: 40 - (string length … | |
Re: [quote]The big thing I'm missing here is the correct way to parse a string and turn the values into... an array of variables? Or something more efficient I'm not even thinking of? [/quote] Very good observation, parsing your file-string into an array of substrings. Yes, there is also a way … | |
Re: Try this: [code] #include<iostream> #include<sstream> #include<string> using namespace std; int main() { ostringstream oss; double number = 0.0; string string_number; cout << "Enter number: "; cin >> number; oss << number; string_number = oss.str(); cout << "\n\nThe number you entered is: " << string_number; return 0; }[/code] The above example … | |
Re: ispunct() may not be specifically what you are looking for to split up the string into tokens.. but I would suggest [URL="http://www.cplusplus.com/reference/clibrary/cstring/strtok/"][b]strtok()[/b][/URL] [code] char * strtok ( char * str, const char * delimiters );[/code] as you can see, strtok() accepts 2 arguments, the first being a c-string (char array) … | |
Re: Looks like you are attempting to sendmessage() to your listbox upon reciept of WM_PAINT messages.... and the only time I think your program will get a WM_PAINT is when you invalidate_rect() inside of your WM_COMMAND... So my question is: what is going to trigger the appropriate WM_COMMAND? | |
| |
Re: This may or may not be part of the problem, but it needs to be adressed: [code] if(player_card2 == 10|11|12|13)[/code] I did the same thing when I was first learning boolean logic and performing tests, and it took me a long time to understand why things are the way they … |
The End.