1,608 Posted Topics
Re: line 22 second program has out of bounds index used for S. If S has 4 elements, then the largest valid index is 3, as index values are zero based, meaning the first valid index is zero. S probably could be a 2 dimensional array, like this: double S[4][4]; rather … | |
Re: You may need more debugging statements. In general you need to post more descriptive narratives than "it doesn't work". When running the .exe version does the screen show at all? If the screen shows in exe version then what do you see when running in debug mode that you don't … | |
Re: Does it compile? Does it run? Does it perform and behave like you would expect? If so, good job! Your posting skills could be improved, though. Look at the anouncements or get a bright light to read the water marks in the message box used to post code. They talk … | |
Re: The best thing to do is get a reference book, preferably hardcopy, though there are some online resources as well. In general you use filestream objects to read and write to files as opposed to an istream object (cin) and on ostream object(cout) to write to the screen. Once you … | |
Re: >>I was guessing they need to be string and 4 ints data type. That would be a description of the member variables needed for a class such as you describe. | |
Re: First, don't use void as return type for main(), even if your compiler allows you to do it. The return type of main() should always be int. Second, if you're at index i and there are three letters in the word, what would be the next index after the third … | |
Re: To my knowledge you can't specify what to inherit and what not. You either inherit the whole shebang or you don't inherit anything. I always am receptive to being shown wrong, and thereby learn in the process, however. | |
Re: Declare a maze that will consist a 12 by 12 board represented internally by a 2D char array. The characters in the array will be # to indicate walls, space char to indicate available choices (unvisited cells) and * to indicate that we've been here before and can't go there … | |
Re: Post relevant trial input. You may just need to use an ostream manipulator to keep it displayed in the format you want. | |
Re: char * add[200]; The above declares an array of 200 char *'s. Drop the * from the above to get a variable that will hold a string with up to 199 char plus the null char. The call to getline would be: cin.getline(add, 199); Actually, I forget whether the second … | |
Re: Well, it should be y = day; but I've been guilty of that typo more than once. I would:[code] //declare these variables within the class static const int daysInMonth[12] = {31, 28, 31, 30, //etc static const string monthNames[12] = {"January", "February", //etc int y; string dayString; //within the constructor … | |
Re: Since this is your second post to the forum I will assume you have read the announcements at the top to the board which indicate that you aren't to expect we do homework for you. Post a specific question with relevant code, error messages, etc. | |
Re: Place lines 21 through 87 in a loop to allow for repetitive inputs. Use cin to pause the program to await for further input or for viewing. Is your board loaded correctly? Don't you need 8 unique pairs of numbers (1-8)? Your code just puts 16 numbers, each 1-8 in … | |
Re: Make the filename a variable and then allow the user to input some or all of the variables data. Then pass that variable to the open() method or the constructor of the pertinent file stream. Note that arguments for filestream variables need to be a C style string, not an … | |
Re: There is no need that I know of. There is an option, just like there is with any function, whether it is overloaded or not. I don't think that having one function with default parameter and one with same argument that isn't default will count as overloading as the compiler … | |
Re: Don't use the return value of eof() in controlling the loop. Sooner or later that syntax will result in creating a second copy of the last entry in the file. I haven't found a very readable explanation of why, so I don't post references. I recommend doing something like this:[code] … | |
Re: Please post your attempt with questions, pertinent error messages, etc. Start with a bare bones Hello World type program that has two variables and the ability to output the value of those variable. then accept user input into one of the variables and be able to output the input. Then … | |
Re: This: string arrcon[5][35]; is basically a table of words/strings composed of 5 lines and 35 words/strings per line. The size of each word/string is indefinite. arrcon[1] is the second line of 35 words/strings, not a single word/string or a pointer to a string. scon is a pointer to a single … | |
Re: Given an array called arr with n elements where x and y are indexes of individual elements in the array. Use a nested loop to compare elements of arr as follows:[code] outer loop controls x, x varies from zero to less than n -1 inner loop controls y, y varies … | |
Re: I've never seen sequential dot operators used like this: myClass a; a.enter().push(); but I like learning new things, so if someone can confirm line two above as valid syntax assuming enter() and push() are valid methods for a myClass object, I'll be wiser than I am now. | |
Re: >>I'd have to make functions or cases for each and every conversion like one for cm-m, cm-ft, etc. Is there any other way to do this? Sometimes the buttons can be used for different purposes depending on the state of the button or combination of buttons pushed or sequence of … | |
![]() | Re: In C++ there are multiple varieties of strings. C style strings are null terminated char arrays. dateStr and timeStr in post #4 are probably going to be used as null terminated char arrays. Null terminated char arrays cannot be concatenated using the + sign. They must be concatenated using strcat(), … |
Re: Declare and define functions before calling them. As your directions instruct don't even try wirting inviteOrNot() until you have the other 3 functions up and running. | |
Re: Restricting yourself to C++ using standard methods and standard libraries to maintain portability restricts graphics capability. Conversely, doing something with graphics in C++ beyond simple static "ASCII art" restricts portability. To my knowledge at least, you basically have to accept one or the other restrictions if you want to use … | |
Re: Some compilers permit nonstandard syntax when it comes to declaring main(), but that's not the same as saying int main() isn't the standard or that it's standard to use void main() or just plain main(). If you want your code to compile on as many compilers as possible then you … | |
Re: Go back to post #19. Add the lines in red to your original code and add another debugging line after this one: lCount = lCount - 1; that looks like this; cout << "lCount = " << lCount << endl; Recompile and run. Observe the power of debugging statements (if … | |
Re: Here's a rough protocol that will probably work: Accept input as a sequence of 6 digits in a string. Convert input string into a numerical value and save it. Separate input string into two separate strings based on given criteria. Convert each of the two strings into numerical values. Perform … | |
Re: What do you know about stacks? Do you have to write your own code for a useable stack or are you allowed to use prewritten code like the Standard Template Library version of stacks? Do you know how to write loops? Do you know how to obtain and assign data? … | |
Re: LNode<T>* ptr; The above line doesn't give ptr a value. Therefore it could be anything. It could be NULL. It could be Oxeff34. It could be 99. Who knows. The problem is you check to see if it is NULL in the very next line. if(ptr == NULL) Before you … | |
Re: Do you mean something like a functional "Hello World" project, a solution to a random Rubik's Cube using the fewest possible moves, or someplace in between those levels of difficulty? Without knowing what you can, or want to, do, it is almost impossible to recommend a "good" project. | |
Re: Assuming maxrand is an int, or something that equates to an int, then the number returned by rand % maxrand should be between zero and maxrand - 1, inclusive. It will never generate maxrand per se'. If you want between 1 and maxrand then add one to the above int. … | |
Re: Nobody here knows what you mean by higher-level C++ programming classes. If you have a pretty good grasp of basic C++ topics such as pointers, arrays, loops, functions, classes, inheritance, file handling, etc, and you feel reasonable comfortable with STL classes, then you have the luxury of deciding whether want … | |
Re: Google C++ RTTI to see if that's what you are thinking about or to give you some possible leads. Otherwise you might be able to embed class type information in a state variable of the base class so the type can be determined when using a base class pointer. | |
Re: Here's an algorhithm in C/C++. You can convert it into whatever you're using. [code] int sec = 0; int min = 0; int hour = 0; while(1) { sleep(1000); //delay in milliseconds ++sec; if(sec == 60) { sec = 0; ++min; if(min == 60) { min = 0; ++hour; if(hour … | |
Re: I've never seen structs/class objects initialized using the {} syntax. To my knowledge that only works with arrays, though someone may prove I'm wrong on that. You can, and should, use the initialization operator with an overloaded, non-default constructor to accomplish the same purpose. The last snippet in post 3 … | |
Re: You can use the stringstream to convert the string to any valid numerical type, as long as the variable you are reading into is in scope. As long as you know the makeup of the file you can use control statements/loops to determine how many in each line to convert … | |
Re: char *strcat( char *str1, const char *str2 ); That's the prototype for strcat() from the online reference I usually refer to. I always thought str1 needed to be a null terminated char array and str2 needed to be either a null terminated char array or a string literal. I am … | |
Re: As currently written you will be able to handle one customers account per run of the program. While that might be an appropriate initial step in the assignment, I presume that the final assignment will require that the user be able to enter more than one customer information per run … | |
| |
Re: What's wrong with the way you did it (other than it should be: while(oper != 'X');)? I think the flow of the program could be improved, but terminating without using exit() looks okay. You could use a bool variable if you want, but the concept remains basicly the same. | |
Re: Without listing the first few errors you receive it's not possible to say with surety what you have going. However, the object you have used called this is a pointer and rightOp is apparently a C styled string. As such you can't derefernce a C styled string. What you probable … | |
Re: How about using a sentinnel/flag? A little bit of a hassle to enter an additional keystroke, but it is completely portable, offers complete control without using magical combinations, etc.[code] bool moreInput = true; char temp; while(moreInput) { //get input cout << "enter y to keep going, anything else to stop" … | |
Re: The first one looks like a declaration of a vector of ints of size alpha, if alpha is an int---or something that acts like an int. The second parameter to the constructor has the default value. I have no idea what the second is attempting to do. Wild guesses might … | |
Re: First, please learn how to use code tags when posting to this board. See the announcements at the top to board to learn how to do this. Second, rand() in this line: if (guess != rand()) should be randNum. Third, I think it would be better with a while loop … | |
Re: >>I have no choice but to create the arrays in my class dynamically since he wants a destructor included. That's really two different conditions. This: Question::~Question() {} is a valid destructor implementation assuming no dynamic memory is allocated for object variables or someplace within an object method (that isn't deleted … | |
Re: I probably has to do with the functionality of cin.fail(). Change your loop to something different. Maybe something like this;[code] bool more = true; char flag; while(more) { cin >> n; //do dah cout << "do you want to enter another value. Enter y for yes and n for no" … | |
Re: You haven't indicated what feature you are going to sort on. Will it be the whole line or will you sort based on a given field within the line. That is will you sort by the firstName field or by the studentNumber or by one of the other fields? If … | |
Re: >>can we access text files randomly Short answer, no. Well, probably not. Depends on how the file is written. Er, I don't think so. Since each object in the file contains an array of possibly indeterminant/nonstandard length, then the number of bytes of memory required for each objects' information storage … | |
|
The End.