1,608 Posted Topics
Suppose you have a node declared like this:[code] struct node { int data; node * next; };[/code] and a list class declared like this:[code] struct myList { node * head; node * tail; int numNodesInList; //member functions etc, but no other member variables. };[/code] Then what is the size of … | |
Re: I may be missing something here given the antihistamine I took an hour ago, but since I've never hesitated to sound foolish in the past I shan't be bashful at this point either. What size is a list and how would the compiler know how much memory to sequester for … | |
Re: for(int index = 0; index > 11; i++) Couple of things with this line: #1) Hopefully i++ is a typo for ++index or index++. #2) The line as written says starting with index equal to zero increment i(ndex) by 1 each time through the loop as long as index is … | |
Re: [code]void final_grade(grades& the_grades); { cout << "Enter the score of the first quiz: "; [/code] Try removing the ; at the end of the first line posted above. | |
Re: When you can, always try to figure out what to do and what happens using pencil and paper before you write the program. In this case I would create a table: For mailboxes with indexes 0-9 (10 mailboxes)all starting with value 0:[code] index 0123456789 interval = 2 0101010101 interval = … | |
Re: Are you sure it's an endless loop? Unforturnately, despite the name outputResult() I don't see where any output is coded in the function so it might look like it is just grinding away when in reality it isn't written to do anything we humans can appreciate. Renaming outputResult() something like … | |
Re: Note how the pseudocode written by dusktreader doesn't really "remove" duplicates from the array. Instead it manipulates the duplicates such that the "duplicates" can be ignored, or removed from consideration, eventhough they aren't physically removed. Indeed there is no way to remove the memory from an array once it has … | |
Re: The best of anything is generally a subjective rating. Find a book you feel comfortable with and go for it. All of the books listed in the sticky note have their supporters and detractors. This generally means going to the book store and browsing throught the options. If you don't … | |
Re: You could use a copy of the original string and break it up into substrings one at a time with a loop and strtok() using space and whatever else you want (punctuation characters, whatever) as a delimiter. Or, if you know the string won't have punctuation characters you could use … | |
Re: You don't HAVE to use an array to hold all the scores, as arrays are just groups of individual variables of like type stored in contiguous memory. However, it is certainly neater to use arrays. The grades are arranged by how many answers were done correctly out of the 10 … | |
Re: Writing an entire operating system to generate your own brand of windows would be possible with C++, but it would take extensive knowledge of both how operating systems work as well as how current gui's work, whether written with C, C++ or some other language. Creating your own text editor … | |
Re: Is there a reason you don't want to shuffle the cards in the deck to generate a random sequence of cards and then deal cards from the deck to each hand rather than assign random cards from a standardized deck sequence to a given player? The program flow could be … | |
Re: You are trying to use dynamic memory to create a multidimensional array (in this case 2 dimensional) but you have the syntax a bit off. Since you've asked for the number of rows, you should probably use them. [code] int ** table; //table is a pointer to pointer that will … | |
Re: >>I think I will have to use a formula that will divide the number of seconds into hours, seconds into minutes, and the remainder will be seconds. Yup, pretty close. You can use division, modulo, and/or subtraction in sequence to do what is needed. NumberOfHours is InputSeconds divided by NumberOfSecondsInHour. … | |
Re: If the text you are reading is from a file, then the code posted should work pretty good as the >> operator should successfully separate the text into individual words based on finding whitespace characters. However, if you want to read from interactive user input you have a bit of … | |
Re: If you use a char array then you can use a sequence of nested loops, wherein each char is associated with a loop, to change each place holder in the sequence in turn. Haven't used bitsets so can't say if similar manipulation possible with them. | |
Re: Suppose textstring an STL string object and the content of the string is "My 7th program". The goal is to calculate how many of each letter there is in the string by looking at each char in textstring one at a time:[code] int len = textsting.length(); //determine the length of … | |
Re: You don't need a nominee class if you don't want to. You can just give the Particular class a member variable of type bool of name nominee and if the member variable value is true, then the member is a nominee and if not, then they aren't. In addition you … | |
Re: Just look at one function at a time. Write, compile, and debug your code until it works. Then go on to the next function, etc. Don't look at the whole thing at once and panic. | |
Re: Why declare gpa as an int and then default it with a value that's either a float or a double? Why declare and define >> and << and then not use them? Why use read() and write() instead of >> and <<? Why are you trying to flush an input … | |
Re: _strdate is a function, so calling c_str() won't help any. This might work: ofstream out(_strdate(dateStr)); or maybe this will do: ofstream out(dateStr); Be sure that 09/12/11 is a valid file name though. I'm not sure that it is. | |
Re: I think of dynamic memory whenever I have to wait for user input to determine the size of an array. A table is usually a 2 dimensional array. A multiplication table is probably a 2 dimensional array of size x by x where x is both the number of rows … | |
Re: Don't push size number of tokens onto the stack all at once, push input onto the stack only if the information entered is an int. Swap lines 26 and 27 since top starts at zero, which is a valid index, and will be necessary if you want allow up to … | |
Re: Maybe it does, and maybe it doesn't. The first thing to do is to pause the program after the call to insertion sort and before the return line in main(). Calling cin.get()or cin >> x once or twice usually does the trick. If you can pause the program and there … | |
Re: Don't get overwhelmed. Break things down into smaller parts and develop them one at a time. For example, first review the process by which you declare a class and how to declare attributes (variables) and actions (methods) you need/wish the class objects to have. Then try to write out the … | |
Re: The stack class doesn't have to have a front or a back, it just has to have a top, which may be the first or last (or some other) element of a list or vector (or some other container). So it doesn't make sense to have an iterator or a … | |
Re: Since fread() is C style file reading instead of C++ style file reading you might do better to post this question in C forum. | |
Re: In your first program be careful with your variable names. Making them more descriptive might help. Also adding comments to indicate to yourself what each loop is doing should help you find some errors. In your second program, temp is a char array, and C style strings are char arrays, … | |
Re: >>I have a 2D array of 10x10 and I want to search the surrounding cells of only a 3x3 portion of it at a time I'd use the corners of the 3x3 section and then 4 loops to get the sum of cells surrounding the 3x3 section. Since this doesn't … | |
Re: Standard headers are routinely enclosed in angled brackets rather than double quotes. main() should have return type of int, not void. Using the void return type isn't standard and is one more keystroke than int to type. You need to declare all variables before they are used. You did so … | |
Re: Declare a user defined class containing two variables, an ID and a PIN and at least an overloaded equals operator Declare two objects of the above class, one called user and the other called target obtain user input for ID and PIN for user. Validate input if desired. associate the … | |
Re: What does int data[] have to do with anything? And why is value being declared as an int if it's a string you want to be looking for? If value is the string you want to search for in an array of strings then pass an array of strings and … | |
Re: Do you know the difference between C style strings and STL string objects? Do you know how to compare two C style strings? How about two STL string objects? Do you know how to declare an array? How about an array of ints? An arrary of C style strings? An … | |
Re: Since the format of the input is known in advance and it is a very structured input you could use a loop calling getline() nine times with comma as the delimiter followed by a single call to getline() using the new line char as the delimiting char to read each … | |
Re: What do you think it does? Write out what each line means and it should be easier to figure out. | |
Re: Are you sure it's the destructor that's the problem? How do you know? | |
Re: If you want to add to the end of the list you need to either keep track of the end of the list using a dedicated node called something like tail or end or whatever, or you have to find the end of the list by looping through the list … | |
Re: use getline(Students, name); instead of Students >> name; | |
Re: void main is wrong. main should always return an int as in: int main(). The constructor doesn't need to be initialized like that, but it is a good idea. It basically cause str to be an empty string instead of str being some junk value. Declare and define both a … | |
Re: You can do a char by char analysis of the string looking char one at a time using (usually somewhat convoluted) logic to determine what is legal to follow any given char, particularly if you want to handle something like "6 - (- 54 - (-61))". That space between the … | |
Re: This fairly screams for user defined types. I am thinking of 2 types: cell and ship. cell would keep track of where on the board the ship is placed and which cells in the board have been selected. Each cell would have an x and a y value in addition … | |
Re: [code]start x at 1 while x less than 4 display x start y at 0 while y less than 10 display result of x times y followed by a space increment y by one start a new line increment x by 1[/code] | |
Re: Describe in your own words what getD() is supposed to do. Here's the best I can do with what you've posted so far: 1) define method getD() for class TWQ which will have return type void and be passed a copy of an AnsiString object, an array of Node objects, … | |
Re: Create a container to keep all the selections in it. The container may have any number of items in it. If you have been advised that no order will have more than 7 items associated with it, so be it, but it could have 1 or 3 or 4 or … | |
Re: You can't. If you had 5 variables of type char with values of A through E, then you could sort them. | |
Re: You still haven't provided the definition of getInFile(), but from the behaviour you describe what is likely happening is that you are associating a file with an ifstream in getInFile and then returning that ifstream. The problem is that each time you call getInFile() from within the loop conditional you … | |
Re: You have several options. Here's one:[code] char ** strings; strings = new char* [501]; //display an array of 501 char pointers. for(int i = 0; i < 501; ++i) strings[i] = new char[41]; //each of the 501 char pointers will have the address of the first char in an array … | |
Re: A couple ways are: 1) include a flag within the data of each record indicating that this record is to be ignored and leave it within the file. Works nice if file storage isn't a concern 2) or keep track of which records have been "deleted" and can be overwritten. … | |
Re: Not literally. But to see what is available you can go to cpprefence.com and look up the methods in what they call C++ String . ![]() |
The End.