1,608 Posted Topics
Re: I assume food and calories are parallel arrays meaning that food[x] has calories[x] calories and you want to keep the food matched with the correct calories and you are trying to alphabetize the food array. If that is the case then swap calories[x] and calories[x + 1} in the body … | |
Re: Between line 42 and 43 put a check statement to confirm appropriate read from file. Maybe something like: cout << "file read is: " << sentence << endl; In isPalindrome() strip the punctuation and spaces from temp before testing. Don't just advance indexes. Use i to be the letter in … | |
Re: Here's one version you can try: void pop(int** s, int n) | |
Re: The best solution would be store the input in an STL string object. If you aren't familiar with them, then you could use a null terminated char array to store the same information. string stlString; //include the string header file to do this type const int MAXSIZE = 1086; char … | |
Re: Um, have you had practice dealing with user defined types such as classes or structs. If so, I suspect he wants to de declare a type called Fractions and do whatever you have to do be able to add two objects of type Fraction together using a function with the … | |
Re: use separate loops to calculate the numerator and denominator. | |
Re: To my knowledge the memory requirements for an object of the class requires memory for the member variables plus memory for a pointer (the this pointer). No memory is required for member functions or friend functions, etc of an object. Member functions are kept in the class declaration/definition. Ideally the … | |
Re: C++ knows nothing about color. You will need graphics program of some sort in addition to the C++ code to change the color. You can probably do this through Windows API using Console functions, but you could surely do it with a full fledged graphics program. If you aren't learning … | |
Re: First: welcome to the board. Second: when posting code use code tags. Instructions on how to use them are embedded in the watermark of the Message box used to post your thread as well as in the announcement section at the top of the board. Third:The easier you make it … | |
Re: given valid object x of type X: X x; if prototype is void foo(X&); and function call is foo(x); //compiler automatically converts x from type X to X& if prototype is void bar(X*); and function call is bar(x); //no automatic conversion of x from type X to type X* by … | |
Re: Please clarify. If list starts with 1->10 and you want to add 5 to the list do you want to end up with 1->5->10 or 1->10->5? If 5 already exists in the list do want to allow a second 5 in the list or ignore it if it comes up … | |
Re: The most obvious possibility, but maybe the least likely, is that the prototype withdraw() post #3 line 1 and function call to withdraw, post #4 line 54 do not match with regard to number of parameters. I suspect however that this is a "posting/typo" error and probably not what the … | |
Re: When mixing getline() and >> in the same program you have to account for the fact that >> leaves the terminating whitespace (new line char usually) in the input buffer. Then when getline() comes around after a call to >> it finds the terminating char to the previous >>, newline, … | |
Re: You might want to look into Run-Time Type Identification (RTTI). I got some pretty good hits searching RTTI on Google. A good reference book is hard to beat though. You might be able to get by with embedding the type of the object within the object so that you can … | |
Re: Fucntion calls should not be preceded by the return type. So, from line 99 to 131 remove all the return type designations. Learning when to use semi-colons takes a little practice. You should put a semicolon after the closing parenthesis of function calls unless there is a good reason not … | |
Re: A stack sounds like a good idea and your explanation is rational. To make it a little easier to understand start with a simpler maze. Consider a simple maze that has just 3 cells in the shape of an L with the start at the top of the L and … | |
Re: Debug it by throwing a bunch of output statements in the code to see where it deviates from what you expect or use the debugger that probably came with your compiler to monitor variable values as you step through the code. | |
Re: When input methods like getline() or >> fail the return value equates to false which then prevents the loop from proceeding. Finding the end of file (EOF) is one of the conditions that causes the streams to go into a failed state, so the input will stop. (Note: If you … | |
Re: This polynomial: 3x^2 + 5x + 1 could also be written like this: 3x^2 + 5x^1 + 1x^0. This suggests that the polynomial could written as a series of terms with 3x^2, 5x^1, and 1x^0 each being one term. Each term would have a coefficient, a variable (which must the … | |
Re: It looks as though you are using the node * called head to be the first node in the list. Once there is an actual node associated with the pointer you don't want to change it, unless you want to make a new head node. The reason to point this … | |
Re: Just embed the switch statement to activate the menu choice within a do/while loop as indicated in the instruction [code] do { //display menu switch(choice) { case 1: //use for loop break case 2: //use while loop break case 3: //use do/while loop break case 6: //exit default //output information … | |
Re: Are you wedded to using strtok()? If not, use the '`' char as the delimeter of the parsing phase, whether the parsing is done initially or after first line read. [code] while(read in first line) { parse first token of first line if(first token == some arbitrary token) parse rest … | |
Re: Not a traversal function. You want to be able to traverse without needing to write to file each time you do a traverse. A separate save function is probably best. That gives you more control. In addition it allows you to save the entire tree or any subtree of the … | |
Re: In the example shown I'd probably use the appropriate version of getline() for the type of string I'm going to use with the comma char as the delimiting char. This could be generalized to using any valid char as a delimiting char, not just the comma char. However, if the … | |
Re: To store that type of information in an array I would use a 2D array of char. I would read in one char at a time, using a nested for loop where the outer loop controlled which row I was in and the inner loop controlled which column I was … | |
Re: You use the STL string class later in your program so why not use it here, too: string Dictionary[12][2] ={ {"God", "osalobua"}, etc and here: string word; Line 35 could then be: for(i = 0; i < 12; ++i) and Line 36 is simply if(word == Dictionary[i][0]) with line 41 … | |
Re: purposely over commented code for beginner to understand process[code] //declare a flag variable bool invalidInput; //outer loop controls number of digits input while(k < MAX_DIGITS) { //reset flag each time through outer loop invalidInput = true; //inner loop while(invalidInput) { //gets char input cin.get(ch); //validates char input if(!isalpha(ch)) //could use … | |
Re: Do you know how many items or a maximum number of items there are in the file? If not an array probably isn't the best container to hold the data, unless that it is the container type you are required to use. Do you know about classes and structs, because … | |
Re: I'd do it something like this: [code] oper = '@'; cout << " enter first operand: " << '\n'; cin >> op1; while (op != '~') { cout << "\nEnter operator: " ; cout << "enter the tilde sign ('~') to stop" << '\n'; cin >> oper; if(oper != '~') … | |
Re: "Content-length: " That is a string and this: BUFFER.length() equates to an int. So when you use the + operator between the two are you trying to concatenate an int onto the string or are you trying to add an int to a string or are what are you trying … | |
Re: Pointers are useful for a variety of reasons. For, example, let's say I want to pass the value of my salary from one function to another. The value of my salary will be changed in the function it is passed to and I want to use that new value in … | |
Re: The microwave is nothing but an oversized paperweight unless you have a series of what to tell the microwave what you want it to do? I'd consider these things "Top-Level Objects" since nothing gets done without them, but then I'm not in your class so I don't know how your … | |
Re: If you know the first key then maybe something like this will work. Encrypt: while there are letters to encrypt generate random letters until current key is generated place a letter of message generate random letter to act as next key repeat Decrypt---need to know first key while no further … | |
Re: Be more descriptive of the problem and you are more likely to get an answer. Not everyone is going to download, compile, run, analyze and then post a response. After quickly reading through posted code in getData() i would change this:[code] while(!openFile.eof()) { openFile >> temp;[/code] to this:[code] while(openFile>>temp) {[/code] … | |
Re: No need for AssignValue to be a friend function unless it is a requirement of the assignment. How will AssignValue know how many digits to place before and after the decimal point? 123.456 0.123456 and 123456.0 are all valid float/doubles variables. Passing both values to the function would be one … | |
Re: There is no way to do this in standard C++. There are non-standard ways to get the job done, some of which are in common use, though. Knowing at least some of the information asked by Duoas will be necessary to try to help inform you of which non-standard methods … | |
Re: Focus your code posting to just the pertinent part. sometimes it's hard to know where that is, but in your case it shouldn't be. Sounds like a do/while loop using something like isdigit() might work if the numerical input is from 0-9. Otherwise you could check the state of the … | |
Re: To my knowledge you can't initialize just a portion of the elements in an array, it's all or none. You can use a loop to assign a desired value to a portion of an array. That's what I would encourage you to do. | |
Re: If you want lines 45-48 to run only in association with the last else if, then they should be enclosed in a code block using curly brackets. Probably a better thing, however, would be to output statement to user that the selection entered is invalid and they should try again. … | |
Re: Where do you give num and num1 a value before you pass it to either the recursive or the iterative process? Shouldn't line 22 and 23 be between line 28 and 29? Expand line 46 to three lines: double temp = fnum * wk7recur(fnum,inum -1); cout << temp << endl; … | |
Re: Please learn how to use code tags when posting code to this board. It is a bit of a hassle, but given it preserves the spacing you (should be) use in writing the code it is well worth it. There are multiple locations on the board where you can learn … | |
Re: Don't use postfix both hold the expression and act as a stack to evaluate the expression. I would suggest declaring an array of type double called myStack to use in evaluating the expression. The elements of postfix are all type char. Since the compiler recognizes type char by the integer … | |
Re: I recommend you think twice about simple copying of head and tail pointers to copy one list to another. This is called shallow copy and works okay in simple programs but it can quickly cause problems if you aren't aware of what is happening. In particular, under this scenario if … | |
Re: In this specific case you could use two loops. One to get the number of elements indicated by length %2 and the other to however many groups of length/2 elements there are. | |
Re: have you tried syntax similar to this: MyObject.bvec[n]; It should work as long as n is less than the size of bvec, which in the code provided would anything 0-9 inclusive. | |
Re: Either: 1) change line 49 to: std::vector<GameObject*> myGameObjects; if you want an array of pointers to GameObjects so you can use newGO as declared on line 50. OR 2) add a public mutator function to set the id member of a GameObject calling something cute like setID(). change line 50 … | |
Re: If you've ever been to an old fashioned library you know that they have the books all filed on shelfs according to some plan. If you just walk into the library and start looking for the actual book it is very tedious. Howevr, if you search the card catalog, where … | |
Re: To my knowledge: If you want to add an entirely new set of customer data to end of current data stored in file without overwriting current data, then you can open the file in app mode to append the data to the end of the current file. If you want … | |
Re: I would insert each term in terms in ascending order based on the exponent so that the exp term with exponent 0 has index 0 in terms, etc. I would expand terms if the exponent of a term to be added to terms is above value of nterms. The default … ![]() | |
Re: try moving line 19 to line 17 so you don't assign tempPtr->data to tempValue each time through the loop. You only want to do that if the value of the conditional in the if statement is true. |
The End.