1,608 Posted Topics
Re: The throw/catch stuff is nice, and eventually you should learn how to use it, but for now I'd concentrate on the use of stacks and use of classes/structs (the only difference between classes and structs in C++ is that struct members have public access by default whereas class members have … | |
Re: The portion of the input file posted contains the data for two piano players, one with number 6010 and one with number 6012. The data is delimited by player with a -1. In this example each player has proficiency of 1 but one has weight factor 1.2 and the other … | |
Re: Often the flow would go like this: use startp to keep track of where to start use temp to search list use newNode to hold data to be inserted into list use stream to read from file use a loop to read all records from file to determine if there … | |
Re: If you aren't allowed to use struct/classes to this as suggested by Ancient Dragon, then it can be done by using parallel arrays. This type of problem seems to be commonly assigned by instructors as a mechanism to get you working with arrays and as a mechanism to get you … | |
Re: There's a learning curve in terms of how to effectively use error messages to your advantage. >>interpreter.cpp(16) : error C2065: 'Code_table' : undeclared identifier means that you used a variable called Code_table in the cpp file called interpreter that wasn't declared before you tried to use it. Misspelling the variable … | |
Re: One way would be to: accept input as a string. convert string into an int convert int into a char (or cast int into a char if all you want to do is display it) ![]() | |
Re: look at the second post down from the top for some suggestions of books. | |
Re: Here's a version using two files rather than holding the file contents in memory. Mirror the original file contents to a temporary file. Find the spot you want to change. Write the correction to the temporary file. write the rest of the original file to the temporary file. rename the … | |
Re: In each call to the function i starts at 0, given the declaration int i = 0; Therefore you never check beyond the first elements of the array no matter how many times the function calls itself. The function will stop calling if the first elements of each string are … | |
Re: Inputting material into the string will stop at whitespace characters such as space if you use the << operator to assign the information, but the string can have whitespace char if you initialize the string or if you use something like getline(). Once the string variable has a information that … | |
Re: Seeing as knowing how to write code requires you to know how to at least set up the algorhythm on paper here is site that reviews three ways to get an inverse matrix. None of them look fun. Maybe there's another way, too. [url]http://www.mathwords.com/i/inverse_of_a_matrix.htm[/url] ![]() | |
Re: cstdlib is the up to date version of stdlib. The older C header files like stdlib and stdio have been replace with versions prefixing the older version with a c, so stdlib became cstdlib and stdio became cstdio. If the compiler you are using won't accept cstdlib then try stdlib. … | |
Re: use code tags anytime you are posting code to the board (or even text that you want to preserve indentation on as the board will eat it up otherwise) | |
Re: atoi() converts a null terminated char array into an integer value (strtox() functions may be a better choice for this) rather than convert an integer value into a null terminated char array. The three options I'm aware of to turn integers into null terminated char array include: 1) sprintf(), as … | |
Re: >>I can't think of a way to take individual numbers from a character array and store it into an integer array In general this often works for characters that are digits: int integerValue = array[i] - '0'; where '0' is the char representing zero and integerValue will be the integer … | |
Re: >>The class contains two public data fields suspect you should drop the word public from that phrase and then proceed without the contradiction. | |
Re: This is a declaration. Rectangle(double x=1, double y=1, double Height=10, double Width=10); The constructor still needs to be defined, just like any other method/function does. I would put the defaults in an initialization list and define it inline within the body of the declaration given the body of the constructor … | |
I have two structs: [code] struct Vertex { int row; int col; friend istream & operator >>(istream & is, Vertex & v) { char t[3]; is >> t; v.col = t[0] - 'A'; v.row = t[1] - '0'; return is; } }; struct Move { Vertex orig; Vertex dest; }; … | |
Re: The good news is that you can write your class much cleaner like this: [code] class MyStorage { public: MyStorage() { } string MyString; double MyDecimal; int MyInt; }; [/code] All member variables of the MyStorage class still have public access. The :: operator should be used if you define … | |
Re: >>is there a specific function to push and pop No. It depends on the implementation. If you are going to implement your own stack then you get to decide how do set things up. If you are using a third party implementation then you use the functions provided without worrying … | |
Re: I think you are correct, the function determines the sum of the values in the array passed to it. In C/C++ the function whatIsThis() is called a recursive function. Recursive functions can be very useful. | |
Re: What you have posted looks like an ill fated attempt at a bubble sort. It bears some relation to the problem assigned, but not a whole heck of a lot. The relation to your assignment and the code you posted is that the body of the function you are supposed … | |
Re: I think your idea of selection sort is off. To me, selection sort means taking an existing container and then sorting it, rather than sorting it while you add items to it---which sounds like insertion sort to me, and appears to be what you are doing with your code. To … | |
Re: Or is it more when you consider the default methods added by the compiler, since the author didn't specify them explicitly? | |
Re: Pass thisCount, theCount and isCount to count() by reference rather than by value. HINT(use references or a pointers as parameters) Initialize all values in letterCount[] to zero rather than a 26 digit value of zero. (I think a single zero in the parenthesis will do it, but it's easy enough … | |
Re: Welcome. A couple things to help you out. First, as you can tell by looking at your post, posting code to bulletin boards frequently destroys the indenting used to make your code more readable. Most boards offer a fix for this, as does this board. You can read about it … | |
Re: A singly linked list can be used to create a stack, but so could a doubly linked. It depends what you are most comfortable with. A queue and a deque are different containers. A queue removes the first item pushed on the queue, whereas a deque can remove either the … | |
Re: >>• Implement string concatenation and assigning one string to another string. • Implement multiple string and c-string class functions. I suspect you are to create your own string class and implement functions to perform concatenation and assignment. the STL string class already has concatenation, assignment, and a large variety of … | |
Re: It's not a good idea to use return value of eof() as a loop conditional as it commonly causes process body of loop one too many times. You would be better checking return value of attempting to read in the piano players number as the conditional. When the stream gets … | |
Re: You will probably get more help if you are more specific in what your question is and show effort of having worked on the problem yourself. | |
Re: A table of strings with more than one string per row would be a three dimensional array of char. Say the table contained one string for the name and one string for the address per row of the table: Name Address John Milwaukee Jane Miami Depending on your needs, such … | |
Re: Do you mean something like this: [code] struct Time { int minutes; int seconds; friend ostream & operator<<(ostream & os, const Time & t) { os << t.minutes << " minutes and " << t.seconds << " seconds" << endl; } } Time timeUsed; Time timeRemaining; timeUsed.minutes = 46; timeUsed.seconds … | |
Re: [quote]As a creative alternative, you could write a penetration tool that tests the security of a network by trying to break in from the outside rather than works to ensure it from the inside. [/quote] Is intent all there is between viruses/worms/trojan horses and "penetration tools"? | |
Re: I can think of no "good" way to do this. Some options I can think of include: 1) If records.txt isn't "too" big, read it all into a container in your program, search the container for the desired location, change what you will, and write the containers content back to … | |
Re: This is going to involve a lot of shifting of values stored in the array. You will end up shifting to the left when deleting any element other than the last one, and shifting to right when you add at any element but the last one. To shift to the … | |
Re: Assuming your input file is in the form of a whitespace separated 10x10 table of ints then reading it in could be as straightforward as : [code] for(n=0; n<10; n++)// col. number { for(m=0; m<10; m++)// rows number { inClientFile >> array[m][n]; } } [/code] in your version: [code] for(n=0; … | |
Re: A couple things: I think you meant --InvDeqiter instead of --DeqIter otherwise the for loop will likely be never ending as the stop conditional relates to InvDeqIter not DeqIter. To read a deque or a double ended list backward using a reverse_iterator you increment the reverse iterator, not decrement it. … | |
Re: With regard to maintaining arrays, set it up so when you do something to index x in array1 you also do the something to index x in array2. To find quartiles, I'd sort the array. Determine the total number of items in the array. Divide the total number by 4. … | |
Re: should this : x_initial * time be this: vel_i * time and try putting this: vel_i = vel_i - (G * DELTA_T); // estimate new velocity for the next DELTA_T. after this: // Compute new velocity. cout << "The velocity of the cannonball is: " << vel_i << " m/s\n" … | |
Re: Thanks for trying to use code tags. Replace C++ within the brackets with the word code and it should work better next time. From the point of view of the C++ language, things look pretty good. You don't need a return statement if a method/function has return type void. From … ![]() | |
Re: First: Please ask (a) specific question(s). Second: Where's the version of average with two arguments instead of three? Third: at least the two argument version of average() is supposed to return a double, not a T. Fourth: To me the instructions for the three argument version of average() are vague. … | |
Re: 500000000 is 500 million or 5 x 10^9. 3*5 x 10^9 = 15 x 10^9 floats 8 bytes/float * 15 * 10^9 floats = 120 x 10^9 1gigabyte = 10^9 bytes Therefore you would need over 120 GB of memory (if I've done my math right) to do this all … | |
Re: Here's my understanding of copy constructors. Copy constructors create a new object of the type of the class it is in from an already existing object of that type. Routinely, the data in the object passed is used to populate the data members in the new object so the new … | |
Re: [code] Person::Person(const Person& copyName) : { cout << "Copy constructor called...\n"; m_name= copyName.GetName(); m_pNext = 0; //or m_pNext = copyName.m_pNext; if you want both copies to have the same address in their pointers. } [/code] | |
Re: If the current protocol is satisfactory for you, so be it. You might also be able to accomplish essentially the same thing by processing each number as you read it in, rather than read in all the numbers at once and parse the whole file/string. To do that, I'd use … | |
Re: There is more than one way to do most tasks. You can probably accomplish this task by using index values and an an array of strings. Develop a 2d array of strings to represent each word available. The first column could represent the scrambled word and the second the correct … | |
Re: move the cin >> change inside the while statement. Add a case -1 to the switch statement. If switch conditional switch conditionals must be a positive integer then check the value of change outside the switch statement in an if statement such that if change == -1 don't check the … | |
Re: I think you need to write out the design of your program in your native language before you try to write up the program to do what you want to do. Expanding on this may work: A library is a collection of books. The information regarding each book is contained … | |
Re: Depending on your needs and knowledge something along these lines might work. This is only a rough outline of one possible way to proceed. If it looks like something that might suffice, it's up to you to fill in the details. [code] template <T> //use templated class for a general … | |
Re: dynamic memory in C uses malloc(), or a similar function, to allocate dynamic memory and free() to delete dynamic memory. In C++ it's new() and delete. In either case, if you want memory for an array of items then you add the [] operator, as appropriate. //allocate an array of … |
The End.