daviddoria 334 Posting Virtuoso Featured Poster

namra_shahid, what you have done here is called "thread hijacking". Please start your own tread rather than post a question at the bottom of someone elses!

Thanks,

David

Fbody commented: Amen :) +3
daviddoria 334 Posting Virtuoso Featured Poster

1) Instead of

if (convert_code == "f")
    {
        c_f_fraction();
    }

you'd want to do:

main()
{
  if (convert_code == "f")
    {
    std::cout << "\nPlease input the numerator of the fraction you wish to convert.<#/help> ";
    std::cin >> numerator;
    std::cout << "\nPlease input the denominator of the fraction you wish to convert.<#/help> ";
    std::cin >> denominator;
        c_f_fraction(numerator, denominator);
    }
}

double c_f_fraction(double numerator, double denominator)
{
  // your logic here (something like return numerator/denominator;
}

See what I mean? This way the function is much more reusable (if you read numbers from a file, or generated them manually, you can still convert them (rather than relying on user input to happen in every instance).

3) The idea is "documentation by good code writing". The problem is that you have to assume programmers will not keep the documentation up to date (that is, they will change the code but forget to update the documentation). So,you have to train them to write the code in such a way that it is "self documenting". The use of intelligible variable names is a good start.

daviddoria 334 Posting Virtuoso Featured Poster

You have declared tokens as a pointer to a vector:

std::vector<char*>* tokens

But are then trying to access the size() function as if it is an object (with the '.' operator):

tokens.size()

You need to instead use the -> operator:

tokens->size()

You also have to use

(*tokens)[i]

instead of

tokens[i]

David

nirali7 commented: thnks a ton... :) +0
daviddoria 334 Posting Virtuoso Featured Poster

This is some fancy footwork with some STL stuff, but it does the trick:
http://programmingexamples.net/index.php?title=CPP/Strings/Split

Basically you are trying to separate the paragraph by the ' ' character (a space). Then you can store each word in a std::vector<std::string> and then use yourVector.size() to get a count of the words.

cpeepee commented: thank you very much! +0
daviddoria 334 Posting Virtuoso Featured Poster

VTK (vtk.org) and ITK (itk.org) also have a lot of tools that could be useful. VTK even has a huge set of examples :) http://www.vtk.org/Wiki/VTK/Examples/Cxx

Lusiphur commented: Useful links :) +1
daviddoria 334 Posting Virtuoso Featured Poster

Also, please use code tags when posting code.

daviddoria 334 Posting Virtuoso Featured Poster

I got really annoyed with the "low-level-ness" of OpenGL and GLUT. SDL provided what I thought was a much more reasonable level of an interface. It was also nice that you don't have to enter the "glut main loop" so you don't have to change your existing code so much if you want to add graphics.

daviddoria 334 Posting Virtuoso Featured Poster

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.

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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.

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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 …
daviddoria 334 Posting Virtuoso Featured Poster

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

pritaeas commented: commendable +0
Lusiphur commented: At worst it'd give me something productive to do :P +0
daviddoria 334 Posting Virtuoso Featured Poster

Jothe,

Please use standard English. For example, "you" instead of "u" , "whatever" instead of "whateva", etc.

Dave

happygeek commented: thanks, you beat me to it! +0
daviddoria 334 Posting Virtuoso Featured Poster

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

mrnutty commented: your website in action! +5
daviddoria 334 Posting Virtuoso Featured Poster

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

jonsca commented: Good suggestion providing hours of fun! +4
daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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

empror9 commented: thanks *_^ +1
daviddoria 334 Posting Virtuoso Featured Poster

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

Bench commented: Good stuff so far :-) +5
daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

You can see what the macro expands to with

g++ -E filename.cpp>testfile

but again, why not just write the function? Have you really noticed a speed difference?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

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

NathanOliver commented: Nice examples +2
mrnutty commented: This is a good Idea +5
nbaztec commented: :D +1
daviddoria 334 Posting Virtuoso Featured Poster

LevyDee, but don't forget, you can only use win32 API in Windows!

daviddoria 334 Posting Virtuoso Featured Poster

That line is the constructor. It says to use a default value of 1.0 if nothing is passed. If something is passed, the : radius(r) sets the member variable 'radius' to the value of 'r'. This is called an 'initializer list'.

Dave

nbaztec commented: Yep. :) +1
daviddoria 334 Posting Virtuoso Featured Poster

Hi Andrew,

Unfortunately I don't know the answer to your question. However, I urge you to make the titles of your threads as descriptive as possible. For example, I came to look at "A little problem", but quickly found out that it was related to the Windows API and I don't know anything about that. If you named it something like "Determine which key was pressed with WH_KEYBOARD hook", I would have known to leave it to the Windows guys :)

Good luck,

David

daviddoria 334 Posting Virtuoso Featured Poster

13 or not, please use real English works (e.g not "every1", "meh", "skript").

daviddoria 334 Posting Virtuoso Featured Poster

UncleLeroy,

This is certainly an assignment (I hope!). If I'm wrong, then DEFINITELY use std::list!

daviddoria 334 Posting Virtuoso Featured Poster

Here are a couple of things:

1) If you want to be a bit adventurous, I've heard of the concept of "labeling" threads (as gmail does) rather than putting them in subforums (folders, following the gmail vs traditional email example). I noticed your thread discussing how you re-arranged some subforums - with this style that would not be necessary.

2) On sites like (or based on) stackoverflow, there is the ability to mark a response as the "answer". This is very helpful.

3) Let me re-suggest using uservoice (http://www.daniweb.com/forums/thread289892.html) to catalog this type of thing (i.e. to replace this thread!)

4) Let me re-suggest cataloging problem solutions as examples on a wiki (http://www.daniweb.com/forums/thread284749.html)

Let me know if you want any further explanation or clarification of these ideas!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I use linux and QT. It is annoying to figure out for the first time, but it is really nice once you get used to it.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

shuma -

Welcome to DaniWeb!

Here are a couple of tips to get you the answers you are looking for:
- Though we understand not everyone is fluent in English, please use proper English words. E.g. "plz" and "plzzzz" are not English words.

- Please do not "hijack" threads. That is, epicasian asked a question, and then you asked your own question as a reply to his question! You should start a new thread if you have a new question.

- Typically no one is going to help you without showing them what you have tried first. You'll have much more success here if you post some code saying "I tried to do this - but here is the problem I am having".

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I've seen a couple of "short lists" posted - are you guys aware of http://uservoice.com/ ? Here is a live site if you want to poke around: http://paraview.uservoice.com/

It is a really nice way to (openly) keep a list like this and collect in an extremely organized fashion users wants and needs. And unless they changed it, it is free if you get less than 100 comments or something like that per month (if you get more than that, it would probably be worth paying for!)

Just a thought!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I'm assuming you mean you have created some kind of table in c++? I would write it out as a CSV (comma separated value) file and the import it into excel using the CSV reader.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Is the only way to get to the "advanced search" page by searching for a blank string? Should there be an "advanced search" link under the "Search" button?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You can access each digit using a std::string

std::string number = "NAB";
    for(int i = 0; i < number.size(); i++)
      std::cout << number[i] << std::endl;

Dave

Ketsuekiame commented: Simple, yet effective. +1
daviddoria 334 Posting Virtuoso Featured Poster

.size() tells you how many elements are in the vector.

God Coder123 commented: Thanks Dave really appreciate the help :) +1
daviddoria 334 Posting Virtuoso Featured Poster

Please try to make your titles and questions as abstract as possible. This way the "next guy" can search and find something usable. If you ask "How do I randomly select an element of an array?" that is much more reusable than "How do I make a horse finish first?".

Dave

daviddoria 334 Posting Virtuoso Featured Poster

jwenting - Clearly we would omit those and only use "good" questions and answers.

bandtank - Sounds good to me. I volunteer to be this "reviewer" if that's all it takes to give this a try.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Looks like you have some extra braces scattered throughout. Also, to pass by reference you have to do:

void readThreeNumbers(float &number1,float &number2,float &number3);

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Please try to get the problem to occur not in 350 lines, but instead something manageable like 20 lines.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You had me confused for a minute, but you have a classic mistake! Remove the semicolon at the end of the for statement:

i.e. change this

for (int count =0; count <= numberGrades; count++);

to this:

for (int count =0; count <= numberGrades; count++)

Dave

daviddoria 334 Posting Virtuoso Featured Poster

abdulsaboor30 - please use code tags and do not do peoples assignments for them!

daviddoria 334 Posting Virtuoso Featured Poster

Please try to replicate the problem in as few lines as possible - I'm guessing you can start paring down the code and get it to < 20 lines to produce the same problem. This process will probably magically point out the problem! If it doesn't, then we'd be happy to help.

Dave

Fbody commented: That's for sure :) +1
daviddoria 334 Posting Virtuoso Featured Poster

1) Please use code tags
2) Please use a reasonable indention scheme for your braces (maybe not using code tags affected this?)
3) Try to narrow down your question to the smallest piece of code possible. Maybe make a 10 line example that fills a vector and then ask "how do I output all the values in the vector?" or something like that. Abstracting the problem really helps people help you, because many people won't want to read about all these classes (student, course, etc), but they may take 2 seconds to read that you want to output items in a vector. See what I mean?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You should post the reply here - so if someone has a similar question they can also find the answer :)

daviddoria 334 Posting Virtuoso Featured Poster

You're right, compilers do ignore white space, but they do not ignore symbols - I think it interprets >> as the instream operator.

vector<pair<double,double>> *point; //points = x,y respectivly

produces

error: '>>' should be '> >' within a nested template argument list

on g++4.4.1.

Just because it works on your compiler doesn't mean it is right.

Dave

jonsca commented: Some rep back http://www.comeaucomputing.com/techtalk/templates/#shiftshift +4
daviddoria 334 Posting Virtuoso Featured Poster

Is this what you're looking for?

#include <iostream>
#include <map>


int main(int argc, char *argv[])
{
	
	std::multimap <int, double> MyMap;
	
	//create a mapping from "testone" to 111
	MyMap.insert(std::pair<int, double>(1, 1.2));
	
	//create an iterator
	std::map<int, double>::iterator iter;

	iter = MyMap.find(1);
	
    if(iter == MyMap.end())
    {
      std::cout << "Not found." << std::endl;
    }
    else
    {
	std::cout << "Found: " << iter->second << std::endl;	
    }
    
	return 0;
}

Dave

sciwizeh commented: Just the info I needed +2
daviddoria 334 Posting Virtuoso Featured Poster

It works fine for me:

std::string MyString = "hello,world123";
  std::cout << "Original: " << MyString << std::endl;
      
  //Remove all punctuation
  MyString.erase(
  std::remove_if(MyString.begin(), MyString.end(), &ispunct), 
  MyString.end());
  
  std::cout << "Punctuation removed: " << MyString << std::endl;

  //Remove all numbers
  MyString.erase(
  std::remove_if(MyString.begin(), MyString.end(), &isdigit), 
  MyString.end());

  std::cout << "Numbers removed: " << MyString << std::endl;

the end result is simply

helloworld

Dave

daviddoria 334 Posting Virtuoso Featured Poster

People are not going to do your homework for you. Please figure out a concise statement of a problem you are having and you'll get a lot more help here.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

This doesn't really seem like a c++ question to me.

Dave