Dynamic Array assignment question

Alright so I've got another question on this program I'm writing. The assignment we were give was...

"An array can be used to store large integers one digit at a time. For example, the integer 1234 could be stored in the array a by setting a[0] to 1, a[1] to 2, a[2] to 3, and a[3] to 4. However, for this assignment, you may find it easier to store the digits backward, that is, place 4 in a[0], place 3 in a[1], place 2 in a[2], and place 1 in a[3]. Design, implement and test a class in which each object is a large integer with each digit stored in a separate element of an array. You will also need a private member variable to keep track of the sign of the integer (perhaps a boolean variable). The number of digits may grow as the program runs, so the class must use a dynamic array. "

I can honestly say I am stumped as to how to make this work. Here is my code. thanks in advance for any help.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
using namespace std;


class largenum
{
      public:
             void enternum(int numdigits);
             void enterdigits(int x, int numdigits, int digit[]);
             void displargenum(int x, int digit []);
             
             };




int main()
{

          largenum newnum;
          int numdigits, x, digit[x];
        
                newnum.enternum(numdigits);
                newnum.enterdigits(x, numdigits, digit[x]);
                newnum.displargenum(x, digit [x]);

                system("pause");
                
                return 0;


     }

//functions

void largenum::enternum(int numdigits)
{

     cout << "Enter the number of digits in your number: ";
     cin >> numdigits;

     int *digit = new int[numdigits];
     
     }

void largenum::enterdigits(int x, int numdigits, int digit[x])
{
     for(x = 0; x < numdigits; x++)
     {
          cout << "Enter a digit: ";
          cin digit[x];
          }
          
          }
          
void largenum::displargenum(int x, int digit [])
{
     cout << "Your number is " << digit[x];
     
     delete []digit;
     
     }
Last edited on
Topic archived. No new replies allowed.