1,608 Posted Topics
Re: << Be careful: it was not an example of passing by reference! It's passing a pointer by value. I'll side with Mahlerfive on this one and see if debate follows or not. Passing an objcet by reference is different than passing a reference to an object. The concept of passing … | |
Re: The information embedded within the class method has to be stored in memory somewhere, but whether it's attributable the to size of the class or not I don't know. You can try the test yourself. Declare a class with a plain old data type and a second one with the … | |
Re: When you overload the () operator, it is called the conversion operator. It provides explicit instructions as to how to implicitly convert a class object into a built in plain old data type. At least that's how my reference explains it. | |
Re: Not quite. Your outer loop is going down and the inner loop is going down, both loops should go the same way. Your inner loop would be a good outer loop to control which element of the array do you start with on any given sequence of the inner loop … | |
Re: >>is there a conversion from "char" to "int"? If yes, how? Yes, you can either go from char to int or from string to int. One of the easiest way to get the numeric value of a char representing a digit is to substract the ASCII (or Unicode or whatever) … | |
Re: Welcome to DaniWeb. Please repost using code tags. Almost nobody ever does it the first time around, but it is nice when you do. A few quick observations. 1) main() should return type int, not void, even if your compiler allows the return type void syntax, if for no other … | |
Re: Assuming you downloaded an up to date version of Dev-C++ you might try something like this:[code] #include <iostream> using namespace std; int main () { cout<< "Hello World"; cin.get(); return 0; }[/code] If that works, and I think it will, then the problem is that the tutorial is out of … | |
Re: read each token from each line one at a time into a string. If the first char of the string is alphabetical, then it's a char and if not then it's numerical (assuming those are the only two options for stuff in the file). If it's numerical then convert it … | |
Re: >>can someone tell me how to make an asterisk frame using for loop statement in C++ Give it your best shot and post a specific question with code/error statements/etc as needed. This is a common task that any number of people could help you with, but most of us won't … | |
Re: Are you given the file that looks like this: intstring intstring intstring or are you creating that file? If that's what you are given then read an entire line into a stringstream and parse it using a technique similar to what Ancient Dragon previously posted. You need a different value … | |
Re: You might try the following untested logic:[code] declare mySentence() to: 1) have return type void 2) receive a reference to a stringstream 3) have a local string variable called token 4) if you can extract a string from the stringstream into token a) recursively call mySentence again passing it the … | |
Re: I'm assuming the third file posted is dna.h, the middle file posted is dna.cpp and the first file posted is the driver file. Now withing dna.h you declare a user defined type called ecoli. I suspect you want ecoli to have 1 data member, called dna, and 2 functions to … | |
Re: [quote]There has never been a time in human history where there was no government wherever more than 2 people live together. You can even consider the basic family as a government of sorts -- mom & dad are the dictators and the children are the governed. [/quote] Admittedly, I never … | |
Re: That's because there's something, probably a single new line char, left in the input stream buffer because you are mixing getline() and >> in the same program. Place a line like this just before the call to getline(). cin.ignore(1086); That should clear the input stream buffer. It isn't perfect, but … | |
Re: You have to know the exact arrangement of the file you are trying to read. For example, if the file consists of a series of data arranged by lines with each line consisting of a name and a numerical value separated by a space then you can call the >> … | |
Re: Please learn to use code tags when posting to this board. That will maintain the indentation I hope you use in your code. You can read about code tags in the anouncement section at the top of the board or by reading the watermarks in the Message box where you … | |
Re: I don't do much GUI programming but I do remember that the first thing you need to know is what API you are using as there is no way to do this in standard C/C++. It's all API/GUI dependent. The good news is that the process is similar in a … | |
Re: Be careful with the function declarations and function definitions. The return type, function name and function parameters must match. In post #12 line 13 declares fileHighScore like this: int fileHighScore(int,string); and line 227 starts the definition like this; int fileHighScore(int charaChoice,string uname) Those two lines match. However, in post #14 … | |
Re: It sounds like you are experiencing the joys of floating point math, where close enough is what counts. For example, how many threes behind the decimal point does it take to equal 1/3, etc? Similarly what value is 1 x 10^16? For all practical purposes it is zero, unless you … | |
Re: [code]land = new LandCondition[IMG_WIDTH]; for(int i = 0; i < IMG_WIDTH; ++i) land[i] = new LandContion[IMG_HEIGHT]; [/code] | |
Re: Post your enum declaration. I suspect you want something like this: enum Process(END, PRINT, UPDATE, NEW, DELETE); which would be the equivalent of END == 0; PRINT == 1; UPDATE == 2; NEW == 3; DELETE == 4; I'm not sure why you have an end program option since you … | |
Re: You can declare an array of type T using static memory like so: T myArray[constInt]; where constInt resolves to an int that is declared const, meaning its value must be known at compile time and cannot be changed at run time. If you don't know what value you want/need for … | |
Re: Salem was trying to teach you a better way to fish, not just toss you a fish. Sometimes you're going to get a direct answer to answer a given problem, and sometimes you're going to get a better way to solve the problem in the first place. I hope you … | |
Re: Every time you call move() to change one of the values within the array you call displayBoard() immediately afterward. Within displayBoard() you write over any changes made in move() putting the array back to the default values, which is why it looks like it isn't changed within move(). Move lines … | |
Re: I always hate it when someone changes a descriptive name like short, which is a small integer, to something like word, which to me should be a string of some sort rather than an alias for short. That being said, if you are truly trying to change a string, like … | |
Re: use getline() rather than >> to accept input into in. | |
Re: In some worlds everything might work everywhere. However, in this world frequently there are rules that must be followed. For example, in the non-computing world integers can have infinite size, but in C++, the int type, which has been designed integers within written code, has an upper limit of size. … | |
Re: Looks to me like you need a way to identify the start and end of a statement. Looks to me like a new statement is initiated within the examples provided by any of the following '(', &&, and ||. There may be other triggers to recognition of a new statement … | |
Re: Are you sure that's the class heiarchy you want? If it were me I'd declare Circle to have a member variable of type Point, since a Circle is not a Point like every Dog is an Animal and every Car is a Vehicle. | |
Re: mega[i] = draw_index; draw_index is a single int. mega[i] is an array of 6 int. you can't assign a single int to an array of int since they aren't the same type. Since you don't comment on the intent of display_draw() I can't help you correct the problem, only point … | |
Re: I'd suggest you break down the problem into smaller steps. The first step I would do is to develop an algorithm to generate the next highest number for n of a given, small value, say 3 or 4. Then I'd try to generalize that process. Given the unknown size of … | |
Re: Go to google.com. Search using the words: using STL set. I liked the sgi site but there are others to peruse as well. | |
Re: 1) It never pays to write more than one function/method at a time and then try to debug it. The only exception would be the need to write a default constructor and a method to display the variable members of the class if you don't use your debugger. 2) If … | |
Re: Not a bad start to the function. You might want to expand that for change up to 10 dollars rather than single dollar bills being the highest denomination of change available, but otherwise the concept is good. Now for a question rather than a request. | |
Re: >The problem actually is i dont get the corect no of spolit ballots...i get it as 4325678> between line 10 where you declare the variable called invalid and line 26 where you increment the variable called invalid by one you never initialize/assign the variable called invalid to any given value, … | |
Re: Why the cast to type char regarding the variable seating[]? Or in otherwords, seating is an array of what type? | |
Re: A switch statement is a common way to handle code with multiple options to choose from. However, it can be done with ifs and an else or with an if, else ifs, and an else, whichever you're most comfortable with. To use the original syntax it would be:[code] if (choice … | |
Re: You seem to have the big picture. Without knowing the specifics it appears that you are overwriting the boundaries of array called permutation. The values of i and j are to complicated to tell for sure. I'd suggest simplifying them. If permutations has N elements then the index of the … | |
Re: >>Can anyone help me? Probably. The help you'll get will most likely be in guidance rather than actual performance. You need to be as specific as possible with questions and show effort at trying to solve the problem yourself. If you end up posting code be sure to enclose it … | |
Re: >>so im asking you to do this Sorry, that's not the way it's supposed to work around here. >> i dont know where to start That's an attitude we can work with. I'd start with a similar but simpler task. In particular I'd start with this. Using pencil and paper … | |
Re: The >> will not work if the string within a given column has any whitespace in it. For example, column 1 is a combination of first name and last name separated by a space, column 2 is an address and column 3 is an ID number. If non of the … | |
Re: If you're not into STL yet you can even do it the old C way in C++. Here's one untested idea how that might be done[code] char * data = NULL; char * temp = NULL; char input[256]; int lenInput; int lenData; while(indata.getline(input, 256)) { if(!data) { lenInput = strlen(input); … | |
Re: You seem to be using dequeue() to empty a queue. Since queues are first on first off, how you empty the queue depends on how you add to it. If you always add at head then you will need to remove from the tail and visa versa. | |
Re: Say the box started out like this: 1 3 5 4 2 * where * is the cute little box. Then it would be sorted if the numbers were like this: 1 2 3 4 5 * To check if the numbers are sorted in ascending order then use a … | |
Re: Okay, here's a slight rework of your program. It does the bare bones initializing of the plane array and allows you to display the plane as many times as you want. Until you understand what's being done, and why, you shouldn't do one line more than this.[code] #include<iostream> using namespace … | |
Re: Look up srand(). | |
Re: The type long double can hold up to 19 digits. If that's not enough you could declare your own data type/class. Call the new class BigInt or HugeInt or whatever and use a string, as suggested, to hold char representations the individual digits. Overload the math operator *, and maybe … | |
Re: Lot's of things. My first tip, never write more than a few lines, and clearly never more than a single action, without compiling and testing. By doing that you would find that you are overwriting your array and getting junk. Be sure you can initialize all elements of the variable … | |
Re: I'd add a private data member consisting of an array of 10 doubles to represent the possible coefficients of a polynomial. Then I'd get at least one constructor working and the tostring() method working so I could review/monitor results as I started to work on each of the other member … | |
Re: Since you appear to be using STL vector objects you don't have to bother with memory allocation, it's done for you by the people who implement the vector class. So a vector sized to 10 objects of type T initially would be: vector<T> myVector(10); The need to get the vector … |
The End.