Vector issues

My book is missing syntax for classes with vectors.
Please advise how to convert my code from array to vector.


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
#include <string>
#include <array>
#include <vector>

class Hugeinteger
{
public:

static const size_t arraySize = 40; 


Hugeinteger( std::vector< int, arraySize > &digitsArray );


void Input   () ;
void Output  () ;
void Chooser () ;
void Compare () ;
void Add     () ;

void isLessThanOrEqualTo () ;
void isGreaterThanOrEqualTo () ;
void isLessThan () ;
void isNotEqualTo() ;
void isEqualTo() ;
void isZero  ();


private:

std::vector< int, arraySize > digits; 
}; 


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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <iostream>
#include <iomanip>
#include "Hugeinteger.h" 
#include <vector>
	
using namespace std;
int key1,key2,key;

	static int counterX;
	Hugeinteger::Hugeinteger( vector< int, arraySize > &digitsArray )
	: digits( digitsArray )
	{
	} 

	void Hugeinteger::Input () 

	{

	
	cout << "Entering Input" << endl;
	cin >> key;
	digits[counterX] = key;

	counterX++;
	
	}

	void Hugeinteger::Output () 

	{

	cout << "Entering Output" << endl;
	for (size_t i = 0; i < arraySize; i++)
	cout << digits[i] << " ";

	}
	
	
	void Hugeinteger::Compare () 

	{
	int min,max;
	

	cout << "enter compare\n\n" << endl;
	cout << "choose operation\n\n" << endl;
	cout << "[1] to isEqualTo" << endl;
	cout << "[2] to isNotEqualTo" << endl;
	cout << "[3] to isGreaterThan" << endl;
	cout << "[4] to isLessThan" << endl;
	
	
	cin >> key;
	switch(key)
	{
	case 1:
	isEqualTo();
	break;
	case 2:
	
	break;
	case 3:
	
	break;
	case 4:
	
	break;
	
	}

	
	
	}
	
	void Hugeinteger::Add () 

	{
	
	cout << "enter add\n\n" << endl;
	cout << "choose units to add\n\n" << endl;
	cin >> key1;
	cin >> key2;
	
	cout << digits[key1-1] << " " << digits[key2-1] << endl;
	cout << "Sum = " << digits[key1-1]+digits[key2-1] << endl;
	}
	
	
	void Hugeinteger::isEqualTo ()  
	{
	cout << "isEqualTo\n\n" << endl;
	cout << "choose units to compare\n\n" << endl;
	cin >> key1;
	cin >> key2;
	
	if (digits[key1-1] == digits[key2-1])
	cout << "True" << endl;
	else
	cout << "False" << endl;
	}
	
	

	void Hugeinteger::Chooser () 
     {
	int key;
	while (key !=-1)
	{
	cout << "counterX = \n" << counterX << endl;
	cout << "Choose Operation\n" << endl;
	cout << "[1] to input data" << endl;
	cout << "[2] to output data" << endl;
	cout << "[3] to compare data" << endl;
	cout << "[4] to add data" << endl;
	
	cin >> key;
	switch(key)
	{
	case 1:
	Input();
	break;
	case 2:
	Output();
	break;
	case 3:
	Compare();
	break;
	case 4:
	Add();
	break;
	
	}

	}
     }


/*
9.14 ( HugeInteger Class) Create a class HugeInteger that uses a 40-element array of digits to
store integers as large as 40 digits each. Provide member functions input , output , add and subtract .
For comparing HugeInteger objects, provide functions isEqualTo , isNotEqualTo , isGreaterThan ,
isLessThan , isGreaterThanOrEqualTo and isLessThanOrEqualTo —each of these is a “predicate”
function that simply returns true if the relationship holds between the two HugeInteger s and re-
turns false if the relationship does not hold. Also, provide a predicate function isZero . If you feel
ambitious, provide member functions multiply , divide and modulus .
*/





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <array>
#include "Hugeinteger.h" 
#include <vector>

using namespace std;

int main()
 
 {

 vector< int, Hugeinteger::arraySize > digits =
 
 {4, 8, 15, 16, 23, 42, 85, 91, 76, 87,33,22,12,44,2,2,2,2,2,2,21,3,4,3,2,2,4,2,3,2,42,6,3,4,5,2,1,77,213,34};

 Hugeinteger obj1(digits);
 obj1.Chooser();


 } // end main 
Last edited on
My book is missing syntax for classes with vectors.


See http://www.cplusplus.com/reference/vector/vector/
Thanks!
Solved
Last edited on
Topic archived. No new replies allowed.