C++ Advice for an 'Old Git'.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: C++ Advice for an 'Old Git'.

  1. #1
    Join Date
    Oct 2010
    Posts
    3

    C++ Advice for an 'Old Git'.

    Hello there to the younger generation,

    I am an 'Old Git',and have been looking at C++ for about a month.

    For a number of years back in the late 60's and early 70's I was a Systems Programmer. I used Assembler on IBM machines (360/370),also Octal and Fortran on Process Control Computers,but then I changed my job.The advice that I am looking for would and still is easy using Assembler.

    What I'm attempting to do is this:-

    1. I enter a series of numerical digits (as you would a number, eg 12345),the Minimum being 1
    number and the Maximum being 6.

    e.g.
    1
    20
    303
    4012
    62102
    122003

    If I do not enter anything then the routine is bypassed.

    2. I then need to find out how many digits there are entered.

    3. I then need to find out how many occurences of 1, 2 and 3 there are in the numbers entered.

    e.g. In 123456 there are 3.

    Once I have this info then I am able to allocate points to add to a basic number.

    e.g. 1 occurence from 1 = 10 points.

    2 occurences from 4 = 7 points.

    6 occurences from 6 = 10 points.

    I have looked on a few Websites,including this one,and in several books, but all I am able to find are articles dealing with Character Strings.

    I would appreciate any 'Advice' on how to go about what I am attempting to achieve.

    I would like to go about this as a 'Beginner' would (Because I am a Beginner), ie really basic stuff.

    As I said, I'm not looking for the Coding,but only for the best,simple way to go about what I'm attempting to achieve,

    Best Regards,

    Adrian.

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: C++ Advice for an 'Old Git'.

    Read into a std::string, then write a loop over it to verify all the characters in the strings are valid and complain if not.

    Either in the same loop or subsequently, maintain 3 counters which are incremented when you see a '1', '2', or a '3' (note these are the ASCII characters for those digits, not the numbers themselves).

    Compute a score based on the counters.

    In a more general context, you can counter character occurrences using a 256-element int array (initially all 0), and increment the index corresponding to the ASCII value of each character. If you want to go beyond ASCII to Unicode characters, then a std::map<int,int> will let you do the same job (using the UTF32 representation of each Unicode character).

  3. #3
    Join Date
    Oct 2010
    Posts
    3

    Re: C++ Advice for an 'Old Git'.

    Thanks for that Lindley.
    I think that I only need one counter.I should have explained myself better that I need the
    'TOTAL' of occurences 1,2 and 3 within the string of digits.
    If I've misunderstood then please let me know,
    Adrian.

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: C++ Advice for an 'Old Git'.

    I only specified separate counters because that seemed to be what you were indicating with the "points" system. I'm not quite sure what's going on there, so perhaps I've misunderstood.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,068

    Re: C++ Advice for an 'Old Git'.

    Quote Originally Posted by Lindley View Post
    I only specified separate counters because that seemed to be what you were indicating with the "points" system. I'm not quite sure what's going on there, so perhaps I've misunderstood.
    Looks like he's got some kind of weighted counter thing going on. He gets a total of the 1s, 2s, and 3s, and compares that total to the length of the string and assigns is some kind of value. The higher the occurrences to length ratio, the higher the value.

    So, converting the number to a string, iterating the string and adding to the counter when you get a 1, 2 or 3 seems to be the way to go.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center