Member Avatar for Arshad Syabrin

Given a positive decimal number, we can convert the equivalent numbers in
binary; in octal and in hexadecimal. Due to the hexadecimal numbers, it is
better to use character arrays to store the various conversions. We propose
the following structure to store the information of a number:

Working on a computer system, the compiler uses a fixed size to represent
an integer of various formats. For example, our system uses 4 bytes to
represent an integer in binary.
For the ease of this lab exercise, we assume that the compiler use 3 bytes (24
bits) to represent a positive number. Therefore, it can represent 24 / 3 = 8
octal digits and 24 / 4 = 6 hexadecimal digits.
In this lab exercise, you first construct an array of No with size randomly
generated in your program, and initialize the respective char to 0 and
display the following table:
You then convert each of the decimal numbers to various formats and
display the following table:
2
All storages used in your program should be dynamically created and all
access to the array elements should be via the pointers and their arithmetic.
In the whole design, you should not use the notation x [ i ] or
( x + i) to
access to the ith element of x.
Since all the storages are dynamically created, when you exit from the
program, you should help the compiler to do some garbage collections. For
example, the following table should be displayed:
A few important functions to be designed and use them in your program:
// This function returns the corresponding char value of an integer digit, for
// example, give any integer from 0 to 15, its returns a character from ‘0’
// to ‘9’ or from ‘A’ to ‘F’
char mapping (int);
// This function initialize all character to ‘0’
void initialize (char *, int);

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;

const int MAX = 10;

struct No
{
 int decimal;
 char *binary;
 char *octal;
 char *hexadecimal;
}; 

// This function returns the corresponding char value of an integer digit, for
// example, give any integer from 0 to 15, its returns a character from ‘0’
// to ‘9’ or from ‘A’ to ‘F’
char mapping (int);
// This function initialize all character to ‘0’
void initialize (char *, int); 
// This function construct the array of No and initialize the binary, octal and
// hexadecimal numbers to 0 and the decimal numbers are randomly
// generated
void constructArray (No*, int);
// This function performs all conversions stored in the array
void processArray (No*, int);
// This function prints out the array, a tabular form as shown in this lab
void printArray (No*, int);
// This function performs the conversion of a positive integer
// with certain base and with certain size (i.e. no of bits) and
// stores the results in the character array
void convert (char*, int, int, int);
// This function performs the garbage collections.
void garbageCollection (No *, int); 

int main ()
{
    No n [MAX];

    srand (time (NULL));

    printArray ( n, MAX);
}

char mapping (int num)
{
    const char hexa [17] = "0123456789ABCDEF";

}

void initialize (char *zero, int size)
{

}

void constructArray (No *n, int size)
{
    No *p = &n [MAX];

    for (int i = 0; i < size; i++)
    {

        (*p).decimal = rand () % 29999;
        while ((*p).decimal > 0)
        {

            (*p).decimal % 2;
            (*p).decimal /= 2;

            (*p).decimal % 8;
            (*p).decimal /= 8;

            *p -> hexadecimal = 4;

            ++p;
        }

    }
}

void processArray (No*, int)
{

}

void printArray (No* n, int size)
{
    No *p = &n [MAX];

    cout << left << setw (8) << "Decimal"
         << left << setw (35) << "Binary"
         << left << setw (16) << "Octal"
         << left << setw (15) << "Hexadecimal"
         << endl;

    for (int i = 0; i < size; i++)
    {
        cout << p -> decimal 
             << p -> binary 
             << p -> octal 
             << p -> hexadecimal
             << endl;

        ++p;
    }
}

void convert (char*, int, int, int)
{

}

void garbageCollection (No *, int)
{

}

Honestly I'm not sure at all where to start

We don't do your homework for you. You need to analyze the problem and provided code and then decide upon an approach. Until you do, and make the code enhancements needed to fulfill the assignment, don't ask us to help. Once you do, and post your errors (compiler or runtime) here along with your code, then we can help point you in the right direction.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.