Thread: Fill in the blanks

  1. #1
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897

    Fill in the blanks

    Let's call this a fun little game. An exercise in creativity, if you will.

    I've written a very simple program that does something arbitrary (converts between Euros and US Dollars, to be precise*), and I'll post the driver here. The goal is for everyone interested to sharpen their tools and their wits to fill in the blanks and produce a working program.

    The rules are simple. Don't change the driver, but come up with a program that compiles and runs.
    Code:
    int main() try
    {
        const int tries = 3;
    
        // TODO: Not hardcode requested password
        jsw::Password password ( "skip", tries );
    
        if ( password.Get ( "Please enter your password: " ) )
        {
            const std::string prompt[] = { "Euros: ", "Dollars: " };
            const std::string result[] = { "In Dollars: ", "In Euros: " };
            enum { euro_to_dollar = 1, dollar_to_euro };
    
            jsw::Selection menu; // Menu controller
            int selector;        // Menu selector
            double value;        // Value to convert
    
            // Set up and process menu
            menu.Add ( euro_to_dollar, "1) Euros to Dollars" );
            menu.Add ( dollar_to_euro, "2) Dollars to Euros" );
            selector = menu.Get ( "Selection: " );
    
            // Set up and process conversion
            std::cout<< prompt[selector - 1];
            value = jsw::Input::Get<double> ( std::cin );
            std::cout<< result[selector - 1];
    
            std::cout.setf ( std::ios::fixed, std::ios::floatfield );
            std::cout.precision ( 2 );
    
            if ( selector == euro_to_dollar )
                std::cout<< jsw::MonetaryConversion::EuroToDollar ( value ) <<'\n';
            else
                std::cout<< jsw::MonetaryConversion::DollarToEuro ( value ) <<'\n';
        }
        else
            std::cerr<<"Too many incorrect passwords. Closing...\n";
    }
    catch ( const std::exception& ex ) {
        std::cerr<< ex.what() <<'\n';
    }
    Have fun!

    * Grown from improving the code from a recent post
    My best code is written with the delete key.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Can you change the code via #defines or extra } braces? I can't see how you could get it to compile otherwise.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I think prelude is asking us to code what is left so that piece of code compiles and runs as expected. It's a fun little game actually

    I can see a namespace, a user-defined object, a templated member function... etc...
    It's the try-catch that beats me. I don't know how to work with that setup. But nothing like a good read to get there.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    The try-catch would be an easy fix if you could do this:
    Code:
    #define try try {
    // ... main() function here ...
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Can you change the code via #defines or extra } braces?
    You can add anything you want above or below, but what's there is what's there. Though you may be confusing the intention of the game. This isn't one of those stupid "make it work as is" projects where you have to do silly hacks, it's more of a project where you have a limited view of the code and need to reverse engineer it. Given the driver, it's possible to reproduce the complete program that I cut it from.

    >I can't see how you could get it to compile otherwise.
    You can add anything you want, just don't change what I posted (directly. If you want to you can use defines, but I'll say right now that the only preprocessor usage in the original program was #include). Clearly you'll need to include some headers and write the classes that are used.

    >It's the try-catch that beats me. I don't know how to work with that setup.
    With the exception of a handful of people on these boards, there should be some learning going on for anyone who cares to participate. This is partially a learning exercise.
    My best code is written with the delete key.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Okay, I'll try it. I might not finish it, but you never know. It'll be at least a few days because this computer doesn't have a compiler.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Being 3:42 am here... i'll leave it for later
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Long live Comeau Test! It's mildly risky because you can't run the result, but a clean compile on a conforming compiler is always a good thing...right?
    My best code is written with the delete key.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yeah, I don't want to risk trying it without a compiler.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    What I meant was that you can use this to compile, but you won't be able to do runtime tests.
    My best code is written with the delete key.

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I've never heard of that before . . . interesting.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Ok. I will definitely do this later. I can't for the life of me understand what to do about.

    std::cout<< prompt[selector - 1]

    nighty night
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Hey Prelude, here's another online compiler: http://dinkumware.com/exam/

    No registration required.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >No registration required.
    Nifty, I'll be taking advantage of that one too, though Comeau doesn't require registration either. I just type "asdf" in the required fields and have at it.
    My best code is written with the delete key.

  15. #15
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yeah, me too, but even "asdf" takes longer to type than nothing.

    Now all we need is an online code formatter . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fill the blanks in the program...
    By sreeramu in forum C Programming
    Replies: 19
    Last Post: 10-18-2007, 05:26 AM
  2. Question On how to Fill icmp_data
    By Antigloss in forum Linux Programming
    Replies: 3
    Last Post: 04-25-2007, 09:42 PM
  3. Question regarding the fill function.
    By ChristianTool in forum C++ Programming
    Replies: 2
    Last Post: 03-13-2005, 09:08 PM
  4. Replies: 3
    Last Post: 12-22-2004, 07:29 PM
  5. please help remove blanks from string
    By cjtotheg in forum C Programming
    Replies: 2
    Last Post: 10-24-2001, 12:21 PM