PPP2 Chapter 16 Exercise 8 - Help Needed

You can find the code on the PPP Google Group, here: https://groups.google.com/forum/#!topic/ppp-public/2_B1w8V0DKw . I've attached the .cpp file and also the .txt file I'm using to my posts there. The latest updated one is on the most recent post. I made multiple posts due to the lack of an "edit" button.

There's probably no need to say what I need help with since I've already said it on that thread. But I'll also quote it here just in case:


I wrote the code, but when I tested it out, I found that I was weird values in the output textbox.  I ran it in the debugger and found that maybe my fill_map function isn't being called.

Could someone please tell me what the problem might be and how I should fix it?  How do I make sure fill_map() is called before the callbacks are called?  Should I put the map in a separate class so that it's independent of Currency_converter_window objects?  Since right now I can only call after an object of the class has been initialized and at that point it's already too late (since a callback has already been called). 

and:

Okay, another update. 

I made some more changes, but I still can't get the std::map to be filled.  What am I doing wrong here?  Please help.  With the single callback that should check for the label on the buttons as well.  Thanks in advance.


The reason I didn't post the code here and instead just linked the Google Group like that is because this post would get too long if I posted the code here. So please forgive me (if anyone on here doesn't like that I linked it here instead of just posting the code here).

If possible, I also want some help on the "one-for-all-buttons" callback I wrote. Preferably from someone who's familiar with Dr. Stroustrup's GUI interface library for the book (PPP2). The reason I ask is because I had a funny result when I tried to use it.

Edit:
I did the map-filling function like this:
1
2
3
4
5
6
7
8
9
void conversion_rate_mapping::fill_map(std::istream &is, std::map<std::string, double> &map)
{
	std::string rate_id;
	double rate;
	while (is >> rate_id >> rate)
	{
		map[rate_id] = rate;
	}
}

And it finally filled the map successfully.

But now I ran across another problem: The output is shown as an integer with the fractional part truncated. How do I fix that?

Edit: Okay, I've fixed everything except for the "all-purpose callback". And I also need to know if there's a way to reset the program after catching an exception in main(). Right now I throw a runtime_error exception if the user either doesn't enter an amount to convert from or enters something that has anything other than a number in it. I want to recover from the exception after I catch it. What should I do?
Last edited on
Topic archived. No new replies allowed.