Thread: Contest Sign-Up Thread: Rewrite Mid() from VB

  1. #16
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I'm in.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  2. #17
    Contest_Master
    Guest
    Vasanth and Sebastiani added.
    I'm sorry, I had to go through and remove posts which gave hints towards the contest. Just so everyone knows where their posts went

  3. #18
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Do comments count? I don't comment. The code is pretty straight forward. Should I add them in? Will I not get as high is I don't comment?

  4. #19
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Meh, if you don't think your code needs them...
    If you think I can understand the code without comments then I don't see a reason to.
    Some light commenting would be nice though.

  5. #20
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    is this valid, and if so, what should be printed...

    string s1 = "abcdefg";
    cout << (Mid(s1, 3, 0) = "123") << endl;
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  6. #21
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    >is this valid, and if so, what should be printed...
    string s1 = "abcdefg";
    cout << (Mid(s1, 3, 0) = "123") << endl;<

    abc123defg

    i think

    what Mid(string, int, int) = Mid(string, int, int) does, i think, is this...

    Code:
    std::string str1 = "abcdefg";
    std::String str2 = "tuvwxyv";
    
    Mid(str1, 3, 2) = Mid(str2, 3, 2);
    //grab the substring from str1 ("abc[de]fg")
    //replace it with the substring from str2 ("abc[wx]fg")
    //the end result, held in str1, is "abcwxfg"
    one question... should str2 be altered in this process?
    If I had a world of my own, everything would be nonsense. Nothing would be what it is, because everything would be what it isn't. And contrariwise, what it is, it wouldn't be, and what it wouldn't be, it would. You see?

  7. #22
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Originally posted by *ClownPimp*
    is this valid, and if so, what should be printed...

    string s1 = "abcdefg";
    cout << (Mid(s1, 3, 0) = "123") << endl;
    Well if you want to implement assignment to const char* then yeah, that's legal.
    "abc123defg" would be printed.

    one question... should str2 be altered in this process?
    No

  8. #23
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by Eibro
    Well if you want to implement assignment to const char* then yeah, that's legal.
    "abc123defg" would be printed.

    No
    Hmmm really? I interpretted it as meaning that it would just leave it as abcdefg because the substring was of length 0.

    What should happen when you do this?

    std::string a = "abc";
    Mid( a, 3, 0 ) = "def";

    or how about

    std::string b = "abc";
    Mid( b, 4, 0 ) = "def";

  9. #24
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Originally posted by Polymorphic OOP
    Hmmm really? I interpretted it as meaning that it would just leave it as abcdefg because the substring was of length 0.

    What should happen when you do this?

    std::string a = "abc";
    Mid( a, 3, 0 ) = "def";

    or how about

    std::string b = "abc";
    Mid( b, 4, 0 ) = "def";
    Hm, yeah, you're right. It's 3AM, what was I thinking?

  10. #25
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    so... it will only replace, at max, the length given in the first Mid call thingie? i thought it was like..

    take substring from left mid, regardless of length, and put in it's place substring from right mid, regardless of length.
    so...
    Code:
    string str1 = "abc";
    string str2 = "123";
    Mid(str1, 1, 1) = Mid(str2, 0);
    produces a string holding "a123c"
    If I had a world of my own, everything would be nonsense. Nothing would be what it is, because everything would be what it isn't. And contrariwise, what it is, it wouldn't be, and what it wouldn't be, it would. You see?

  11. #26
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    I am REALLY confused now, ha.

  12. #27
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    Code:
    string str1 = "abc";
    string str2 = "123";
    Mid(str1, 1, 1) = Mid(str2, 0);
    take the substring from str1 (starting at index 1, 'b' (index 0 being 'a') and holding 1 character, just the 'b') and replace it with a box

    "a[ ]c"

    place in that box the substring from str2 (starting at index 0, '1', and holding 3 characters, '123')

    "a[123]c"

    does that make any sense...? maybe this isn't how it should be done... maybe the "box" should only be able to hold how many characters it held before, meaning it only places the '1' in the "box"... BAH!
    If I had a world of my own, everything would be nonsense. Nothing would be what it is, because everything would be what it isn't. And contrariwise, what it is, it wouldn't be, and what it wouldn't be, it would. You see?

  13. #28
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    The strings should grow and shrink depending on what indicies you pass.
    Think of it like this, the lvalue Mid() determines what characters in the lvalue string are replaced. The rvalue Mid() determines what the characters are replaced with in the lvalue Mid().

    So YES, I was right the first time.
    string s1 = "abcdefg";
    cout << (Mid(s1, 3, 0) = "123") << endl;
    That should print "abc123defg". Because we're replacing 0 characters at position 3 in s1. If we did something like:
    string s1 = "abcdefg";
    string s2 = "123";
    cout << (Mid(s1, 3, s2.size()) = s2) << endl;
    Then "abc123g" would be printed.

  14. #29
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    count me in... (doesn't mean I'll ever get around to it )

  15. #30
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072

    Re: Contest Sign-Up Thread: Rewrite Mid() from VB

    Originally posted by Eibro

    Judges - 1
    Eibro
    [2 Slots availible - (I'm not doing this all myself!)]
    I'd like to judge this contest.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ANN: The Fourth Contest: Alarm Clock, sign up here
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 59
    Last Post: 08-10-2002, 12:24 AM
  2. Sign Up!: The Third Round, both contests
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 54
    Last Post: 07-20-2002, 05:46 PM
  3. Sign Up -- The Next Contest
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 49
    Last Post: 06-26-2002, 06:09 PM
  4. Sign up -- Contest Thread
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 70
    Last Post: 05-27-2002, 06:46 PM
  5. Multi-Thread Programming
    By drdroid in forum C++ Programming
    Replies: 6
    Last Post: 04-04-2002, 02:53 PM