Help decimalHexOctalBinary

Discussion in 'Programmer's Corner' started by Hk3008, Apr 26, 2012.

  1. Hk3008

    Thread Starter New Member

    Apr 26, 2012
    1
    0
    I am being asked this
    "Write a class called decimalHexOctalBinary that has four properties mainly decimalUnsignedInt (base 10), hexadecimalUnsignedInt ( base 16), octal UnsignedInt (base 8), and binaryUnsigned Int (base 2). Use gets and sets such that if anyone changes any of these four properties, the other three are altered to have corresponding values. You will need a number of additional private methods (e.g., functions) to implement this class.

    Place code within main() to demonstrate that the class works correctly.

    Include the UML notion appropriate for this class."

    this is what I have ..... I am lost and do not know where to go from here I really dont even know this much but I had a book help me and it wasnt very informative either am I going in the right direction and if so where to go from here?
    Code ( (Unknown Language)):
    1. #include <iostream>
    2. using namespace std;
    3. class HexOctBinClass
    4. {
    5. public:
    6.     //
    7.     // default constructor
    8.     HexOctBinClass()    {
    9.         n = 0;
    10.     }
    11.     //
    12.     // overloaded constructor that sets n
    13.     //note parameter needs different name
    14.     HexOctBinClass(int nn) {
    15.         setN(nn);
    16.     }
    17.     //
    18.     // used to set the value of N. Only positive Ns are allowed.
    19.     void setN(int nn)   {
    20.         if(nn <0) nn = nn *-1;
    21.         n = nn;
    22.     }
    23.     // returns the value of N.
    24.     int getN() {
    25.         return n;
    26.     }
    27.     // displays the value of N as Hex.
    28.     void printHexN() {
    29.         cout << "Hex N is: " << hex << n << endl;
    30.     }
    31.     private:
    32.     int n;  // class level variable
    33. };
    34. int main()
    35. {
    36.     HexOctBinClass foo(10);
    37.  
    38.     foo.printHexN();
    39.     cout << "Dec N is: " << dec << foo.getN() << endl;
    40.     return 0;
    41. }
     
Loading...