466 Posted Topics

Member Avatar for nine9hours

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

Member Avatar for nine9hours
0
996
Member Avatar for ChevyScience
Member Avatar for ravenous
0
171
Member Avatar for phorce

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 << …

Member Avatar for ravenous
0
118
Member Avatar for Jigs28

[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 …

Member Avatar for thines01
0
139
Member Avatar for CY0T3R

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; …

Member Avatar for ravenous
0
199
Member Avatar for C++ programmer

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...

Member Avatar for C++ programmer
0
192
Member Avatar for lxXTaCoXxl

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 …

Member Avatar for DeanMSands3
0
868
Member Avatar for sumanth232

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 …

Member Avatar for MandrewP
0
926
Member Avatar for znerihc

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 …

Member Avatar for ravenous
0
122
Member Avatar for engineern

[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 :)

Member Avatar for engineern
0
181
Member Avatar for jman2011

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; …

Member Avatar for WaltP
0
195
Member Avatar for jonnyboy12

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]

Member Avatar for ravenous
0
104
Member Avatar for christian03

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= …

Member Avatar for Lerner
0
229
Member Avatar for ddm

[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 …

Member Avatar for ddm
0
219
Member Avatar for Xenix-Hero
Member Avatar for needforkevin
Member Avatar for ravenous
0
174
Member Avatar for Commonman4012

[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: …

Member Avatar for ravenous
0
202
Member Avatar for mechstough

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( …

Member Avatar for ravenous
0
169
Member Avatar for mitrious

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 …

Member Avatar for mitrious
0
213
Member Avatar for KasmIR

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.

Member Avatar for KasmIR
0
81
Member Avatar for james6754

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 …

Member Avatar for james6754
0
145
Member Avatar for avenger123321

[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 …

Member Avatar for avenger123321
0
359
Member Avatar for rohan121212

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 …

Member Avatar for LRRR
0
142
Member Avatar for bobanderson93

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]

Member Avatar for richieking
0
136
Member Avatar for Karkalash

[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 …

Member Avatar for Karkalash
0
609
Member Avatar for bennetk2

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 …

Member Avatar for WaltP
0
186
Member Avatar for kbakersr

[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 …

Member Avatar for ravenous
0
152
Member Avatar for phorce

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 …

Member Avatar for phorce
0
1K
Member Avatar for Topherman

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 …

Member Avatar for raptr_dflo
0
1K
Member Avatar for Idestruction

[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 …

Member Avatar for L7Sqr
0
282
Member Avatar for lxXTaCoXxl

To output a double in scientific notation: [Code] double x = 123.4567; cout << scientific << x << endl; [/code]

Member Avatar for ravenous
0
161
Member Avatar for pilipino93

you should check out the boost::filesystem library, it has lots of handy file-related functions.

Member Avatar for pilipino93
0
1K
Member Avatar for triumphost

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 …

Member Avatar for triumphost
0
179
Member Avatar for the_kitoper

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]?

Member Avatar for LRRR
0
176
Member Avatar for Kunal0

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] …

Member Avatar for ravenous
0
288
Member Avatar for daviddoria

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, …

Member Avatar for ravenous
0
135
Member Avatar for bohling

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 …

Member Avatar for bohling
0
228
Member Avatar for Rdel

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. …

Member Avatar for PrimePackster
0
104
Member Avatar for mediachicken

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?

Member Avatar for radu_
0
326
Member Avatar for Jim887

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; } …

Member Avatar for Moschops
0
115
Member Avatar for NoUserNameHere

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 …

Member Avatar for NoUserNameHere
0
186
Member Avatar for rockerjhr

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

Member Avatar for ravenous
0
424
Member Avatar for Semeno

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 */ …

Member Avatar for NathanOliver
0
265
Member Avatar for pinkboom

You need to insert [icode]f3 << std::endl;[/icode] after line 46 and before line 47.

Member Avatar for pinkboom
0
152
Member Avatar for northrox

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 …

Member Avatar for Schol-R-LEA
0
98
Member Avatar for blackhawkss4

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 …

Member Avatar for ravenous
0
213
Member Avatar for ccooldude

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 …

Member Avatar for ravenous
0
212
Member Avatar for phorce

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 …

Member Avatar for thines01
0
135
Member Avatar for james6754

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] …

Member Avatar for ravenous
0
109
Member Avatar for ToweyLeake

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 */ …

Member Avatar for ToweyLeake
0
198

The End.