Search this page:
http://en.wikipedia.org/wiki/C%2B%2B
In the future, there is really no need to start 3 threads for these things.
Search this page:
http://en.wikipedia.org/wiki/C%2B%2B
In the future, there is really no need to start 3 threads for these things.
Yes, you definitely need to install octave, as well as octave_devel. I just do a:
sudo yum install octave*
It won't be so easy on Windows :)
For some reason I always have to change in octave.h
extern OCTINTERP_API int octave_main (int argc, char **argv, int embedded);
to
extern int octave_main (int argc, char **argv, int embedded);
You then have to link your program to 'octave' and 'octinterp'. My CMakeLists.txt file looks like this:
cmake_minimum_required(VERSION 2.6)
PROJECT(OctaveTest)
INCLUDE_DIRECTORIES(/usr/include/
/usr/local/include/
/usr/include/octave-3.2.4/
)
LINK_DIRECTORIES(/usr/lib /usr/local/lib
#/usr/lib/octave-3.0.2/
#/usr/lib/octave-3.0.1/
/usr/lib/octave-3.2.4/
)
ADD_EXECUTABLE(OctaveTest OctaveTest.cpp)
TARGET_LINK_LIBRARIES(OctaveTest
octave octinterp
)
Good luck!
Dave
First, please use a descriptive title. "Help me" does not qualify!
Second, you posted this only 2 hours before. Did you really expect help in that short of time?
Most importantly, why would we do your assignment if you don't want to. It looks like you have simply copied and pasted what you're supposed to do. What have you tried so far? Are you stuck on a particular part? You need to show us that you have put some serious effort into it first before we help you.
Dave
It is not reasonable to translate a sentence into another language one word at a time. Assuming you want this "bad" translation (word by word), you should split the sentence at the spaces and store the words in a std::vector<std::string> and iterate through the vector to do the translation.
After you input the Fahrenheit temperature, you immediately call calcCelsius which contains a cin statement. If you type a second number and hit "enter" again it works. It doesn't really make sense to input the Celsius temperature though in calcCelcius, right?
Welcome to DaniWeb!
You won't likely get any help here unless you show us that you have given it a good try yourself first. Post some code that you have come up with and explain the input, current output, and expected output along with any compiler errors or crashes and we'll try to help you out.
Good luck,
Dave
Can you please clarify? You want to have a prompt such as :
"Enter the password: "
and then check if the password that is entered is correct? Depending on the security level needed, you could just hardcode the password in the code and do a string comparison. Another common feature would be to "mask" the password that is entered (with *'s perhaps), but I don't know how to go about that.
Dave
You could certainly do what firstPerson has suggested. Or you could just generate independent random numbers: http://programmingexamples.net/index.php?title=CPP/RandomNumbers
I think you could use the min histogram value from this function: http://opencv.willowgarage.com/documentation/python/histograms.html#getminmaxhistvalue ? That kind of seems silly, but I don't see any obvious easier "ImageMinValue" type of type of function that they provide.
The problem is that in this line:
TicTacToe game(char X, char E);
You cannot have the type again - it needs to be:
TicTacToe game(X, E);
However, now you will get a "X is not declared" error. You either need to make X public and use game.X or do something else.
Good luck,
Dave
'\' is typically called an "escape sequence". If you are actually trying to search for a '\', you need to use a '\\'. Can you explain an input that is giving you an incorrect behavior?
Please use code tags when you post code. Also, DaniWeb has a "Looking to Hire" forum that you should post something like this "willing to pay..." post in.
Dave
I'm not exactly sure what the problem is. Does it crash? Or what is the input, current output, and expected output?
Dave
Yikes that is a lot of code. Can you try to simplify it down to < 40 lines or so? Also can you explain exactly what is wrong? Is it crashing? Is it giving an incorrect result?
Dave
I couldn't get this to completely work right now, but here is what I came up with when I tried to do it a while back. It certainly needs some cleaning!
// need to
// export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/include/octave-3.2.4
// export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/octave-3.2.4
#include <octave/octave.h>
#include <octave/oct.h>
#include <octave/parse.h>
#include <iostream>
void Test1();
void Test2();
void OneParam();
void TestRand();
void Prob();
void SetDir();
int main(int argc, char **argv)
{
if (octave_main (argc, argv, 1))
{
TestRand();
OneParam();
Test2();
SetDir();
Prob();
}
else
{
error ("Octave interpreter initialization failed");
}
return 0;
}
void Test2()
{
octave_value_list f_arg, f_ret;
f_arg(0) = octave_value(2.5);
f_arg(1) = octave_value(2.6);
f_ret = feval("min",f_arg);
Matrix unis (f_ret(0).matrix_value ());
std::cout << unis;
}
void OneParam()
{
octave_value_list f_arg, f_ret;
f_arg(0) = octave_value(-1);
f_ret = feval("acos", f_arg);
Matrix unis (f_ret(0).matrix_value ());
std::cout << unis;
}
void TestRand()
{
ColumnVector NumRands (2);
//NumRands(0) = 9000;
NumRands(0) = 10;
NumRands(1) = 1;
octave_value_list f_arg;
f_arg(0) = octave_value (NumRands);
octave_value_list f_ret = feval ("rand", f_arg, 1);
if (f_ret.length () > 0)
{
Matrix unis (f_ret(0).matrix_value ());
std::cout << __FILE__ << ":" << __LINE__ << ":" << unis;
}
}
void Prob()
{
octave_value_list f_arg, f_ret;
double c = .01;
double m = .5;
for(double d = 0; d < 5; d++)
{
for(int l = 0; l < 5; l++)
{
f_arg(0) = octave_value(d);
f_arg(1) = octave_value(l);
f_arg(2) = octave_value(c);
f_arg(3) = octave_value(m);
f_ret = feval("ProbNumeric", f_arg);
//Matrix unis (f_ret(0).matrix_value ());
//std::cout << unis;
double P = f_ret(0).double_value();
std::cout << "P: " << P …
Please try to simplify your problem down to a < 20 line piece of code. Then also explain the problem in much more detail. You'll find that it is highly likely that no one will help you in the current form that you have posed your question.
Dave
AncientDragon - you are correct. However, once you have ubuntu installed, you are a
sudo yum install g++
away from having a compiler :)
Welcome to DaniWeb.
Please refrain from typing in all caps. You can install any linux distribution on any computer and you will have the g++ compiler to compile and test your code.
Dave
Dani and community,
I saw this thread:
http://www.daniweb.com/forums/thread296478.html
and it gave me an idea. With nearly 800,000 members, we should try to leverage the massive talent that has amassed on DaniWeb to collectively do some projects for some worthy causes. For example, the web design/programmers could work together to make a website for a non-profit organization. The programmers of DaniWeb could do something like the above link to help out someone in need of software but without the knowledge or resources to obtain/create it otherwise. This collection of software/websites/projects/products could be "branded" as DaniWeb Projects and cataloged as a proof of concept of how large communities working together than produce great results.
What do you guys think?
Dave
Is there any reason why it must be done in c++? I'm also assuming he is using Microsoft Windows?
Dave
Jothe,
Please use standard English. For example, "you" instead of "u" , "whatever" instead of "whateva", etc.
Dave
Welcome to DaniWeb!
Please use code tags when posting code. It makes it much more readable for us.
The first step would be to convert to lowercase. You can use this method:
http://programmingexamples.net/index.php?title=CPP/Strings/Case_Conversion
Then take a look at this example. It shows how to count the occurrences of a character:
http://programmingexamples.net/index.php?title=CPP/Strings/CountCharacters
You can store each count in a std::pair:
http://programmingexamples.net/index.php?title=CPP/STL/Pair
Then store the pairs in a std::vector - you're done!
Let us know if you have any problems once you give it a try.
Dave
Hi Coronax,
Welcome to DaniWeb!
Even though you are coding in c++, this is not really a c++ question. I would check with a math-y forum such as mathoverflow.net, the Mathworks forum, or physicsforum.com to see if you can get a good explanation.
Good luck!
Dave
Unless you are extremely experience I think you should leave this to the experts an use an existing virus scanning software.
Dave
Hi duude,
Welcome to DaniWeb!
It may be painful to install and get working the first time, but Boost has a timer:
http://programmingexamples.net/index.php?title=CPP/Boost/Timer
Good luck,
Dave
If the answer could be helpful to others, could you please explain it here?
This is still a crazy amount of code for us to go through. You should be able to get all of these classes (cpp and h files) down to only a few lines. (We don't need to the content, only the structure to get the compiler errors you are seeing).
Can you explain the problem that you are having? If you have a specific problem, if you could trim the code down to < 20 compliable lines that demonstrates the problem, that would me much easier for us to look at than just dumping 200 lines on us!
Dave
That is really a better a question for here:
http://sourceforge.net/projects/notepad-plus/forums
Dave
You should definitely use a std::vector<int> to store these things. You could also then define an enum to contain the name of the years to access the correct element of the vector
JANUARY = 0, etc
Good luck,
Dave
Did you read the previous post? StuXYZ spent a lot of time explaining it for you!
// Test to see if all possibilities for have been used. You don't need to test beyond sqrt(i).
Welcome to Daniweb!
First, please use code tags around your code, it makes it much easier for us to read. Second, I STRONGLY recommend that you use std::vector instead of c-style arrays. It will save you hours of headaches for sure.
Good luck,
Dave
dansnyderECE was right. I had to change std::string.npos
to std::string::npos
I am using g++ 4.4, it must be a compiler difference making it work for you and not for me.
Dave
NathanOliver,
Cool, I hadn't seen that function. I am getting a compiler error though:
http://programmingexamples.net/index.php?title=CPP/Strings/SingleCharacterTag
on this line
if ((firstPos = temp.find_first_of("<", firstPos)) != std::string.npos)
"Expected primary expression before '.' token".
Dave
This line if(!(i%j)) break;
says "if you can divide i by j evenly (with no remainder), i is not prime". It could be more clearly expressed as if(i%j == 0) break;
I'll leave the next line for someone else :)
Welcome to DaniWeb!
Please use code tags when posting code, it makes it much more readable for us.
This question seems to appear over and over again. Maybe someone can make example here: http://programmingexamples.net/index.php?title=CPP#I.2FO of "correctly" reading a file one character at a time as well as one line at a time. I think this would get heavily re-used.
To actually count the characters, you should use: http://programmingexamples.net/index.php?title=CPP/Strings/CountCharacters
Thanks,
Dave
Are these ItemGroup^
supposed to be ItemGroup*
? If so, then I bet you are storing and using a pointer somewhere where you think you are storing and using the actual value.
Dave
You should use getline() to get a line at a time as a string. Then you can use the [] operator to get each character and analyse it.
Alternatively, you could use the std::count function: http://programmingexamples.net/index.php?title=CPP/Strings/CountCharacters
on each vowel. You may want to convert the whole string to lowercase (there is a function for this: http://programmingexamples.net/index.php?title=CPP/Strings/Case_Conversion) so you only have to search each vowel once.
See how these examples work everyone! :)
Dave
You could look into the Boost RegEx package. Here is a short example http://programmingexamples.net/index.php?title=CPP/TR1/Regex_Tokenising (maybe someone could comment /explain this a bit more)?
Dave
I haven't used it myself, but you could check out: http://jocr.sourceforge.net/
I urge you not to start from scratch, as this is quite a hard problem.
Dave
With first one, it looks like you need to compare to 'largest' each time. That is,
if(num2 > largest)
largest = num2;
if(num3 > largest)
largest = num3;
if(num4 > largest)
largest = num4;
For the second one, I would suggest using more descriptive variable names so you can keep them clear. It looks like you are increasing 'num' each time, but I'd say you need to be increasing 'count' until it gets to 'num'.
Give those a shot and let us know if it works.
Dave
Haha perl always look so scary... thanks though, I'll give it a shot.
Dave
Welcome to DaniWeb!
First, please use code tags when you post code. It makes it much easier for us to read.
Second, PLEASE do not use global variables. The assignment even says that you should return the value by reference.
The actual error you are getting is because you have written
printGrade( int score );
instead of simply
printGrade( score );
Good luck,
Dave
tesuji is correct. You can only switch on int and char.
I have demonstrated the difference between char and string here:
http://programmingexamples.net/index.php?title=CPP/Switch#Switch.cpp
Dave
Hi all,
I have started a wiki that I hope to make the "unofficial Daniweb wiki". Its mission is to present short, compilable answers to many commonly asked questions here on the forum.
http://programmingexamples.net
I have seeded it with a handful of c++ examples, but I'm hoping that some of you DaniWeb-ers from other languages will use it too! Please feel free to edit, add to, and comment the existing examples. Also, add new examples if you feel they are commonly useful.
Happy exampling!
Dave
Yep, I messed up. I have already flagged the post as "bad" and am just awaiting a mod to move it.
Sorry!
Excuse me if I may play devil's advocate a little
No problem - any idea that only gets positive comments simply hasn't been though about enough!
What's the 'core purpose' of the wiki? is it a house for C++ examples/snippets? if so - make sure that this is clear to all users who might be thinking of using it for something else!
Yes. What else are you thinking someone would use it for?
It would help to state a list of "do" and "don't" guidelines. i.e. "do not treat the wiki as your own personal code dump" etc.
Agreed. I have started this, feel free to add to it.
What happens if two similar entries are created?
I will merge them. I can't (though I hope it does!) imagine that this takes any kind of crazy exponential growth curve. At small volumes I will manage it.
Most importantly: How will quality be maintained? i.e. what measures are inplace to ensure that only the best quality, idiomatic, standard-conforming C++ code will be allowed on the site?
I am trusting people on this one, but keeping a watchful eye. If the project starts to get very large then we can re-assess.
--------
I've "seeded" the rules (as I had done with the examples themselves. Please help me flush them out!
http://programmingexamples.net
Dave
I hear perl is the way to go for string parsing, so here is the test!
I have a file like this:
...
<li><a href="DSC_9866.JPG"> DSC_9866.JPG</a></li>
<li><a href="DSC_9867.JPG"> DSC_9867.JPG</a></li>
...
and I want to get a list of the file names. That is, the result I want is a list of strings
DSC_9866.JPG, DSC_9867.JPG, etc
How would I go about this?
Thanks,
Dave