1,608 Posted Topics
Re: Taking advantage of the [] operator is certainly one way to do this. For example, assuming the initial string is always of the same length and always has the same groupings and that you are using the STL string library to create string objects for the initial input as well … | |
Re: I'm sure Nathan Oliver meant to suggest you could overload the equals operator, ==, for the class rather than the assignment operator, =, that he typed. To detect duplicates you don't have to sort the points if you don't want to. If you were to sort the points, and it … | |
Re: A few adjustments to merge() might get you over the hump. WARNING: following snippet not tested. Use at own risk and understand what comments are saying before using.[code] while(inxa < 10 && inxb < 10)//while not used either all of a or all of b. You don't want a[10] and … | |
Re: You've entered the year, but not the day or the month. You'll need that information, too. That means you'll need 6 variables to do the calculation. They can all be independent variables, or you can declare a date class with each date object having a day, month and year as … | |
Re: With STL string objects checking for duplicates is as simple as using the equals operator to compare the current string with a string stored someplace else in the program, say a container holding unique strings that have been read in so far. | |
Re: Can you give a specific example of the task or better explain the problem narratively? The word table when used in the context of C++ frequently refers to a 2 dimensional array of values and your code implements an algorhithm to accumulate value in variable called sum by adding the … | |
Re: 1) Welcome to Daniweb. One of the first things you need to know about this board is that when you post code the boad will gobble up your indenting and other formatting and make your code very difficult to read unless you enclose it in code tags. The use of … | |
Re: Are both the posted code and the posted error message copy/paste from the code compiled? Cause I don't seen any function protocols listed int Bible::getName(); | |
Re: 1) Create an array of prime numbers less than or equal to the given number. 2) If the given number is prime, you're done. 3) If not find the smallest prime number that is a factor of the given number and then find the other factor associated with that prime … | |
Re: A stack is often built around a list where insertions and deletions occur only at the tail. So pop removes the last node of the list and push places a new node on the list. In this case the Alley class is also a pseudonym for a list masqueratding as … | |
Re: 1) Check to see if the file opened before you try to use it. 2)This: char ARRAY[NUM_ROWS][NUM_COLS]; could be used to hold individual characters or null terminated char arrays, ie C style strings. And this: ifile >> ARRAY[ROWS][COLS]; reads a single char at a time into ARRAY at whatever ROWS … | |
Re: It would be best to post as a thread instead of a snippet. Hopefully a moderator can change your post type for you this time. In addition, the code as posted looks pretty much C rather than classic C++, and may best be posted to the C board. It's been … | |
Re: Here's a similar request: Can you help me mow the grass? There are multiple options with such a project, but without knowing what tools you have available (are allowed to use), it is difficult to provide much guidance. Do you know about user defined types like structs/classes? Do you know … | |
Re: Use pencil and paper, then keyboard and reference book. People here are very reluctant to offer fully completed projects, but some of us are softies when you show some effort by posting code and asking questions about the algorithm, code, error messages, etc. ![]() | |
Re: Not a bad start. Now move on to implementing the class methods one at a time, and creating a driver program to test the implementations. You might want to add some setX() stuff so you can change the values of the coordinates after you have constructed a Point without having … | |
Re: void *create(int nRows, int nCols) // constructor Not. At least not by the routine connotation of the word constructor used in the context of C++. | |
Re: >>char names[10][20]; for practical purposes this means names is an array that can hold up to 10 names. Each name can have up to 19 visible char and a terminal null char to make it a null terminated char array instead of just a char array. | |
Re: A matrix is routinely defined as a 2 dimensional structure, like a table of data. There's not reason it can't be defined otherwise, but that would be like overloading the - operator to do addition. Please, post a declaration of your matrix class so we can see how it relates … | |
Re: And if you don't know how to use the debugger, don't want to know how to use the debugger, or just prefer to do it yourself, then you can always through in debugging code that will be removed in the release version. If you don't see any output at all … | |
Re: Since the array is user defined you must be declaring the array using dynamic memory and storing the user input as variables. Try passing the array as type int** in addition to the variables containing the user's input. | |
Re: For one you're using an array of int rather than an array of doubles. Other that that it looks pretty good. What isn't happening that you expect to happen? Why is sum = sum + etc commented out.? The basic steps done so far seem reasonable asid from those concerns. … | |
Re: Things happen so fast inside the computer these days that the difference between isthere and current_time may be effectively zero making the update to posx and posy essentially zero as well. | |
Re: Don't you want something like this:[code] class Rational { int num; int denom; etc }; class Polynomial { Rational coefficients*; };[/code] Your version creates a rational number using 2 polynomials, which is legal, but it isn't creating polynomials with rational coefficients. I think you want to be able to do … | |
Re: Why are you mixing C and C++ style I/O? As a general rule that is not routinely recommended. Use a conditional statement to print the middle name. If the middle name is empty then don't print it. Option 1: If the middle name is declared as an object of STL … | |
Re: activities[0].action is a char activities[0] is a client_activity activities is an array of type client_activity The function activity is declared like this: void activity(client_activity activites[]); Which of the above three could be passed to activity()? If you don't want that type of object forwarded to activity() what do you need … | |
Re: Look up use of code tags in the announcement section of this board and then repost your code. Also clarify what this: Similarly,when a  user logs off a station means. | |
Re: >>i wrote all this from examples i found here and there and adjusted the codes for my program That's one approach I guess, but I sure hope you understood the code you found or you're likely to be in over your head pretty fast. >>whenether i add a new album...i … | |
Re: Please explain yourself better. Maybe post an example. To my knowledge & can be used as the address opereator, when declaring a reference variable and as a bit operator. I suspect you are trying to ask why are parameters sometimes passed to functions as references, but who knows. | |
Re: 1) get user input for number of rows, number of columns and number of mines 2) declare a 2d array of char called board using dynamic memory and the user provided values for number of rows and number of columns 3) set all the cells of board to '0' 3) … | |
Re: Creating a user defined type to represent a Card, a Deck and a Hand makes sense. You can either declare and define each user defined class within the cpp file containing main(), before main(), or, each user defined type could be declared in it's own header file and the methods … | |
Re: What does "it doesn't work" mean? Or you could try this: if it compiles in VC++, then run it through the debugger in VC++ or manually debug it by adding ouput statements after each action within the program to see where it fails. | |
Re: 1. Am I on the right track so far? It almost seems schizophrenic. You have many good features and then you don't bother to read the instructions where it clearly says the math operators return a Fraction, not int. 2. To get the fractions should I put a cin in … | |
Re: Example #1: number of lines in pyramid = 3 line number 1 has 2 prefix spaces followed by 1 * line number 2 has 1 prefix spaces followed by 3 * line number 3 has 0 prefix spaces followed by 5 * Example #2: number of lines in pyramid = … | |
Re: The declaration of the * operator is a bit off. * is presumably being overloaded as the multiplication operator which takes two parameters, one on the right hand side and one on the left hand side operator and frequently returns a result (else why bother to do the process in … | |
Re: While you're at it could you give me the recipe to my favorite drink, too? It's just about as easy for us to help you as it is for you to help me. Be more specific, and post pertinent information. ![]() | |
Re: >>i even dontknow what are the tools to use develop c++ aplications Then you are going to have a hard time creating a linked list and understanding what you are doing. The tools you are going to need have nothing to do with C# or Java, they are alternative languages … | |
Re: You have posted a pretty typical prototype for overloading the >> operator for class storage, whatever that is. This allows you to read a storage object from a file using the >> operator rather than writing code to read the member variables one at a time, using any istream object, … | |
Re: In many of the functions you want for each division check each quarter, but for some functions you will want to flip that to for each quarter check each division. That's certainly the case for highestQrtlyDiv(). Also, if you are going to check all four quarters in the same function, … | |
Re: [quote] plz tell me what is wrong in program [/quote] Dave Sinula gave you the short answer. In addition I'd list these. 1) Because you aren't sure where the problem is I suspect you may well have written the entire program and then compiled it/ran it. Instead write, compile, test … | |
Re: That should work. Are there other ways?----there always seems to be, maybe memcpy() or something, but I always use loops. | |
Re: >> If I wanted to add 3 more cars how would I do this! Depends. If the data from a previous run of the program had been run is to be added to, then you need to read the data back from file and run an insert function three times … | |
Re: As I understand it, the instructions mean the advice you type can't have blank lines, because if a blank line is entered (two enters in a row creates a blank line), then input should stop. Maybe something like this would work: 1) declare three STL string objects---fileData, firstLine and nextLine … | |
Re: you do a single read of binaryFile.dat using the read() method called on the fstream called dataFile. Whether the data read in is actually the size of coach or not may be a problem. Whether the read actually found, or better yet tried to read beyond, EOF or not may … | |
Re: What's the question? You're more likely to get a meaningful response if you don't wait for somebody to download your program and try to compile/run it. A quick look at insert() suggests that you aren't screening item to be sure it has more than 2 letters in it and I … | |
Re: Read the whole file to the program. Find the line you want to change and change it. Read the data back to the original file overwriting what was there before. Technically, that involves no changing or deleting of the other lines. There may other possible ways, depending on the exact … | |
Re: I don't understand what lines 75-81 are supposed to do. wordstar has already been loaded with '*''s. Why do it again? Where do you define howManyChars()? Where do you replace the '*' in wordStar with guess if guess is in word? I believe the body of the if statement staring … | |
Re: for(int col=0; col<19; col++) { for(int row=0; row<19; row++) the above essentially is a 19 by 19 grid with cols and rows ranging from 0-18. Below likewise only uses numbers from 0-18. lifeBoard[rand()%19][rand()%19] = 'x'; And this only uses numbers 0-2. direction = rand()%3; The following uses the assignment operator, … | |
Re: This is frequently a bug waiting to happen: while(!infile.eof()) because unless you are very sensitive to how you use it sooner or later you are going to end up with duplicate input of the last item in the file you are reading. It's because eof() doesn't return true until after … | |
Re: use a loop to compare each letter in the word to guess to the character acting as the current guess. If the guessed char is in the word to guess then replace the X by the appropriate letter in the appropriate spot of the display array, just like on Wheel … | |
Re: vijayan121 demonstrates full use of STL. Here's a version that's not quite so sophisticated and may be a little easier for a beginner to understand. Key concepts: 1) The insert() method of lists inserts to the left of (that is, before) the iterator. This allows it to work for a … |
The End.