CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Help Needed...

  1. #1
    Join Date
    Aug 2002
    Posts
    16

    Help Needed...

    Hi all,
    At the moment I have been experimenting with writing C++ classes, objects and other behaviours.

    I have currently written a limited Binary counter class, which when the user enters in two Binary numbers, they are presented with a menu that asks the user what operation they wish to perform. It sort of acts like a binary calculator....It adds, subtracts, multiplies, divides, increments and decrements the two binary numbers, depending on which menu option the user chooses.

    I know want to be able to change the program around, so that it takes in two Hexadecimal values instead of two Binary values. I still want all the functionality to be the same, but it outputs the answer in Hexadecimal values.

    Below is the Binary code:
    Instead of it working with Binary numbers I want the program to work with Hexadecimal numbers.

    Instead I have attached the files...

    The main ".cpp" file and the ".h" file

    Any help would be greatly appreciated...
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2002
    Posts
    16

    No Header file needed..

    Hi again,
    Just letting you know that there was no header file needed. The class exists in the binary.cpp file that was attached in the first posting...

    Regards

  3. #3
    Join Date
    Aug 2002
    Posts
    16

    Any luck?

    Hi again,
    Just seeing if anyone had a chance to have a look at the code that I posted late last week. I have been sick the last few days and hadn't had a chance to look at the code myself. Again any help would be appreciated...

    Regards Barbes

  4. #4
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    1. Personally, I ignore any posts without a good subject line. I just happen to be bored at the moment. I'm sure many others ignore such posts also. A better title would be something like "reading and writing hex values".

    2. I tend to ignore any posts that sound like homework. In general, this forum is pretty good at not answering such questions.

    3. This isn't a specific question. You'll have better luck if you ask a specific question, such as "how do you read in a hex value?"

    4. Once it's narrowed down, post the code that corresponds inline. It's great that you've provided compilable code. That helps a lot. Not everybody reading your post knows if they can help without looking at the code. It's more work to download the attached file just to determine "Nope, I have nothing to add to that." I want to help, but I'm lazy.

    Jeff

  5. #5
    Join Date
    May 2002
    Location
    Texas
    Posts
    222
    Most of the time when I see vague subject lines, they are ignored.

    From the type of question presented, I usually assume the person will eventually figure it out. As pointed out, there was no specific question.

  6. #6
    Join Date
    Sep 2002
    Posts
    1,747

    some simple suggestions

    Make a base "numbers" class with basic functions to do the math operations and virtual display routines. Usually, the internal representation of a hex would be the same as the internal representation of a binary number (say a long), so the math routines would probably be the same, and if you have classes for representing binary and hex numbers, templates can probably be used. The idea here is that we don't want to repeat all the work we did on one type of data for another if at all possible. Display is a different matter. Then derive from it and implement the display routines for each type (in fact this is not necessary if you want to just use an optional parameter to your display routine for formatting, but I think you want to explore class hierarchies here...). Since each type of data is displayed differently then we want to separate these routines for each number base type. At this point, you should begin to see what you will want to do reading the data in as well (will it go in the base class or in a derived? why?). This is the general path you should take in approaching class hierarchies: what is general to all classes in the derivation tree and what is specific?

    And as far as this sounding like a homework assignment, yes it does. That doesn't mean help shouldn't be offered, it means it should be the same type of help you would offer your own students if you were teaching. In other words, clear explanations of concepts and not rote code that can be copied. Come on guys, this is not some secret society we're in, snobbishly looking down on those who want in. These forums ARE for help, even on understanding what a homework assignment's goals are... Just don't take away the part that deals with understanding.

    Oh yes, and DO make your topics more descriptive. This is a common problem with people just starting out on this site, and as the comments above point out, it really takes away from the number of people who may help you.
    Last edited by galathaea; October 13th, 2002 at 11:02 PM.

  7. #7
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    this is not some secret society we're in, snobbishly looking down on those who want in
    Oh I know and I hope I didn't come across as such, and I never turn away a direct question, homework related or not.

    As for a solution, I believe both printf/scanf and istream/ostream have mechanisms for handling hex numbers.

    Jeff

  8. #8
    Join Date
    Sep 2002
    Posts
    1,747

    jfaust, you are the man!

    Hey, jfaust. You are ALWAYS helping people out, so I hope I didn't sound too harsh. Your points were good too (except that I might disagree with number two). I bow to your buddha nature.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured