466 Posted Topics
Re: What are the errors? Also, [QListWidgettItem::setBackgroundColor()](http://developer.qt.nokia.com/doc/qt-4.8/qlistwidgetitem-obsolete.html#setBackgroundColor) is deprecated, you should probably use [QListWidgettItem::setBackground()](http://developer.qt.nokia.com/doc/qt-4.8/qlistwidgetitem.html#setBackground) instead | |
Re: I think line 26 should be [icode]reorder = a[y];[/icode] :) | |
Re: I think I'd go for overloading [icode]operator<<[/icode] for your matrix class. That way you can just do things like: [code] Matrix m; ... /* Write the matrix to the terminal */ std::cout << m << std::endl; /* Store the matrix in a file */ std::ofstream outFile( "my_file.txt" ); outFile << … | |
Re: [QUOTE=Jigs28;1760172]Overloading an operator is overhead.[/QUOTE] Only as much as any other function, not really a problem in general [QUOTE=Jigs28;1760172]Means in totality there is no actual use.[/QUOTE] I'd disagree with this. You are correct in the sense that, since and operator is basically a function, it would always be possible to … | |
Re: if you were so inclined, you don't actually need the [icode]if... else[/icode] structure in the inner-loop: [code] int rows = 5; for( int i = 0; i < rows; ++i ) { for( int j = 1; j <= i; ++j ) std::cout << " " << j % 2; … | |
Re: Do you have a simple example of the problem that you have? Post some of your code. It's hard to suggest anything when no-one can see how you're using things... | |
Re: The main thing that's giving you trouble is confusing [i]velocity[/i] and [i]acceleration[/i]. As Galileo famously showed, the acceleration of an object in free-fall is constant (since you're not accounting for air resistance here), so I think that pretty much everywhere where you have acceleration, you mean [i]velocity[/i]. The one place … | |
Re: Please use code-tags and format your code in a sensible way. Your problem is that you can't do this: ways( n, m ) = ways( n-1, m ) + ways( n, m-1 ); `ways()` is a function, returning an `int`, it makes no sense to try and assign a value … | |
Re: You could store a frequency count of all the letters in the word/scrambled word. Then, make a frequency count of the guess and subtract the guess frequency counts from the stored one. If any of the resulting subtractions is negative, then your guess cannot be a subset of the stored … | |
Re: [icode]name[/icode] is a pointer to a [icode]char[/icode], but you never allocate any memory for it. You probably want to do something like [code] char name[ MAX_NAME_LENGTH ]; [/code] Also, in future, please post code using code tags and take the time to format the code correctly in your posts :) | |
Re: Since we appear to be giving away code these days, you can do this in a single line using [icode]std::count_if[/icode]: [code] #include <iostream> #include <string> #include <algorithm> #include <cctype> int main() { /* Read the target sentence into a std::string */ std::string sentence; std::cout << "Enter a sentence:" << std::endl; … | |
Re: What your [icode]OpenFileDialog1->FileNames[/icode] call returns seems to be a handle to an array of [icode]System::String[/icode] handles, not just a single one, so you'd have to convert each string in the array individually. I think that you need to do some [i]marshalling[/i] to do that, see [URL="http://msdn.microsoft.com/en-us/library/1b4az623(v=vs.80).aspx"]here[/URL] | |
Re: When you want to type code in a post, please enclose that code in code-tags and use proper indenting! Even if it's only a couple of lines of code. For instance, your previous post should have looked like this: const int indexToDelete; const int sizeOfArray; // ... for( int i= … | |
Re: [QUOTE=ddm;1749513]This is my work but I believe I did it wrong[/QUOTE] It's definitely wrong, but is this your [i]whole[/i] program? If so, I would start again and have a really good think about the steps that you have to break your code down into [i]before[/i] you attempt to write any … | |
Re: There is an extra [icode];[/icode] on line 433. | |
Re: On line 69 you have used [icode]AcctList[/icode] instead of [icode]acctList[/icode] | |
Re: [icode]std::find()[/icode] doesn't return a [icode]bool[/icode], it returns an [i]iterator[/i] (kind of like a pointer) to the element that you're looking for in the find. If it doesn't find the thing that you're looking for, the iterator points to the element one-past-the-end of the container. So, you need something more like: … | |
Re: You have declared your [icode]chromosomelist[/icode] array as a stack variable so, depending on the size of a [icode]Chromosome[/icode] object, you could be getting a stack overflow for an array of 1000 objects. If I were you, I'd use a [icode]std::vector[/icode] to store your chromosomes in: [code] std::vector< Chromosome > vChromosomeList( … | |
Re: I think that the second constructor is almost certainly NOT what you want. I think that this constructor will cause the entire path from the node that you're trying to make right up to the root node to be duplicated in memory. Look at what it's doing: [list=1] [*][icode]Node[/icode] constructor … | |
Re: I don't know what it is you're trying to do, but if [icode]i[/icode] is less than 2 and "backspace" is pressed, you will try and access a negative index in the [icode]cuv[/icode] array. This will definitely cause you a problem at some point. | |
Re: Line 12 is this: [icode]ptr = new double[M][N];[/icode]. I don't think that you can do this. You probably want: [code] ptr = new double[M * N]; [/code] This will allocate you enough space, but means that you will also have to change lines 23 and 24, since you won't be … | |
Re: [QUOTE=subith86;1740420]I think a closing bracket is missing[/QUOTE] Yeah, that's one problem. There's a bracket missing on line 159. However, there are many other problems. [list=1] [*] You have several typos, where you have hit [icode]l[/icode] instead of [icode];[/icode] at the end of a line. [*] The global functions that you … | |
Re: Yeah, you have to consider how your algorithm scales: [tex]O(n^2)[/tex], in this case. This means that a number 10 times as big will take 100 times as long to process. So, if you enter 100000 and it takes 5 seconds, then for 1000000 you would expect to wait 500 seconds … | |
Re: You never call your [icode]display[/icode] function. On line 82 you have [icode] cout << mystack.size() << endl;[/icode], which is where your zero comes from. the for loop on the display function should probably be [icode]for(int i=0;i<tos;i++)[/icode] | |
Re: [QUOTE=Karkalash;1741994]I don't want to take the easy rout of just negating the velocity but is my first time trying to implement this equation (with little vector practice :( ) Perhaps I'm simply misunderstanding the formula.[/QUOTE] I'd say that you should think about how important it is for you to have … | |
Re: It's temping to use the stream extraction operator, [icode]>>[/icode], to read from files, but I almost never find it to be a good idea, for reasons like you're finding. The most robust way to read this kind of data is to use [icode]getline[/icode], see the example [URL="http://en.cppreference.com/w/cpp/string/basic_string/getline"]here[/URL]. This way you … | |
Re: [QUOTE=kbakersr;1741466]i need to separate the elements within the string. so if one line contains A13 B23 A93 B23 then after that line has been checked, one vector will contain 13, 93 and the other vector will contain 23, 23. Is there a way to do this without strings? I don't … | |
Re: Line 14 of matrix.cpp should be [icode]matrix = new double*[rows];[/icode] The way you have it at the moment is making a new local variable called [icode]matrix[/icode] and assigning the memory to that (which will definitely result in a memory leak) :) I'm not too sure about the syntax of your … | |
Re: You have done two main things wrong: [list=1] [*]As Zeroliken said, you're loops are not trying to access all the elements, so something like [code] for ( counter; counter < 50; counter++ ) { if( max < random[50] ); max=random[50]; } [/code] doesn't do what you want it to. You … | |
Re: [icode]std::ostream::open[/icode] takes a second argument that says what you want to do with the file you're opening. [icode]std::ios::app[/icode] opens the file in 'append' mode: [code] std::ofstream myFile; myFile.open( "filename.txt", std::ios::app ); [/code] You can also cause data to be written to the file by calling [icode]flush[/icode], without closing the file … | |
Re: To output a double in scientific notation: [Code] double x = 123.4567; cout << scientific << x << endl; [/code] | |
Re: you should check out the boost::filesystem library, it has lots of handy file-related functions. | |
Re: Pretty much everything is possible in C++, it's a question of the amount of effort that you want to put in. It's not entirely clear from you post what it is that you want to do, but it sounds like it could be quite a lot of work. Reading commands … | |
Re: I don't understand, -3 is the correct answer if [icode]RoD[/icode] is 0.5. Do you get -2.666... if you set [icode]RoD = 1.0[/icode]? | |
Re: If I could make a comment on the design of your class... I'd change the name of your class from [icode]Lottery[/icode] to [icode]LotteryResult[/icode], since this is what the object actually represents. It does not represent the concept of a lottery in general. I think a [icode]Lottery[/icode] class would generate [icode]LotteryResult[/icode] … | |
Re: Doesn't it depend on what the anticipated usage of your collection is? In the simplest case, you might find that the usage of the collection can be entirely satisfied by simply doing [icode]typedef std::set< Patch > PatchCollection[/icode]. This has the advantage of giving good STL compatibility and needs no duplication, … | |
Re: Rather than printing the primes out as you find them, store them in a [icode]std::vector[/icode] instead. So, instead of [code] if (primeNo == false) { cout << z << " "; } [/code] you'd have: [code] if ( primeNo == false ) { primes.push_back( z ); } [/code] Then, when … | |
Re: They are all IDEs, rather than compilers. They are a kind of front-end that makes the compiler more friendly to use. You write your code in the IDE and there is a "build" button somewhere that you push when you want to produce an executable from the code you've written. … | |
Re: What do you mean by "curve data"? Do you mean you want to change the lookup table for the image so that you have false colour in the final image? | |
Re: when you pass an argument to a function like this [code] #include <iostream> void init( int ); int main() { int per = 0; std::cout << per << std;:endl; init( per ); std::cout << per << std;:endl; return 0; } void init( int per ) { per = 10; } … | |
Re: It looks like it does something like counting all the nodes in a tree structure that have at two non-null child nodes. The return line is a relatively complex one, since it contains two recursive calls to [icode]ct2[/icode] and a ternary operator. Also, none of the variables declared on line … | |
Re: You don't need to try and sort the [icode]NAME[/icode] map by the [icode]name[/icode] string, it will already be sorted in this way. So, just delete lines 24 and 25 in UniversityDatabase.cpp | |
Re: I think I'd go for reading in a whole line at a time and then pass that line into the constructor of a [icode]CFilm[/icode] class: [code] std::vector< CFilm > vFilms; while( ! infile.fail() ){ std::string strLineFromFile; std::getline( infile, strLineFromFile ); /* add this film to the vector of films */ … | |
![]() | Re: You need to insert [icode]f3 << std::endl;[/icode] after line 46 and before line 47. ![]() |
Re: Your [icode]for[/icode] loop is just wrong. You want something like [code] int result = i; for ( int p = i - 1; p > 0; --p ) result *= p; std::cout << result << std::endl; [/code] Note how this is not modifying [icode]p[/icode] inside the loop. In your code … | |
Re: I think that this bit is the problem: [code] while( getline( input, students[0], ',' ) ) { input >> score[st_num][st_exam]; input.get(ch); st_exam++; st_num++; } [/code] It's going to be over-writing [icode]student[0][/icode] every time and the [icode]score[/icode] matrix is going to be filled in along its diagonal only (since you increment … | |
Re: Your code does what you said you wanted it to do for me, no problem displaying any of the grids. There are a number of improvements that you could make though. The number one thing that you should probably do is use a more modern compiler/development environment. I hear that … | |
Re: I had some STL-based fun try this task myself, so I thought I'd share it with you :) [code] #include <iostream> #include <fstream> #include <string> #include <vector> #include <algorithm> #include <iterator> typedef std::istream_iterator< std::string > word_reader; typedef std::ostream_iterator< std::string > word_writer; int main() { std::ifstream infile( "MyDictionaryFile.txt", std::ios::in ); if … | |
Re: You probably want something more like this: [code] #include <iostream> #include <fstream> #include <string> using namespace std; class one { private: int num; public: void hello(); } oneclass; int main() { oneclass.hello(); return 0; } void one::hello() { num++; cout << num; } [/code] I've moved the declaration of [icode]one[/icode] … | |
Re: It looks like you're trying to read in the data and calculate the means at the same time (which is possible, but not in the way that you're doing it). To me, your current code looks like this: [code] int main() { /* Open file and declare some arrays */ … |
The End.