Question meaning

Construct the main program to allow the user to decide the number of each type of objects to be stored in the array.
Instantiate all the objects accordingly and demonstrate how each objects
behaves differently when the same instructions are given to them.

I'm not really get it what is allow user to decide the number of each type of object to be stored in array . what is this mean?
1. Ask user how many objects of type A to store.
2. Get number from user.
3. Make an array of number objects of type A.
1
2
3
4
5
6
7
8
9
10
11
int RFID_array; 
	cout << "Enter number of RFID container : ";
	cin  >> RFID_array;

	sc[RFID_array] = RFID_item;

	int ManualShipping_array;
	cout << "Enter number of Manual container : ";
	cin  >> ManualShipping_array;

	sc[ManualShipping_array] = Manual_item;


am i correct?
am i correct?

No.

Here is how to make an array of number objects of type someType.
someType* pointerToTheArray = new someType[number];


You might see some people doing this:
someType theArray[number];
This is incorrect C++, as C++ does not allow variable-sized arrays. Some compilers might let you do this. They really shouldn't.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const int TOTAL_CONTAINERS = 6; 
 	ShippingContainer *sc[TOTAL_CONTAINERS]; 
  
	int RFID_array; 
	cout << "Enter number of RFID container : ";
	cin  >> RFID_array;

	RFIDShippingContainer *RFID_item = new RFIDShippingContainer[RFID_array]; 

	int ManualShipping_array;
	cout << "Enter number of Manual container : ";
	cin  >> ManualShipping_array;

	ManualShippingContainer *Manual_item = new ManualShippingContainer[ManualShipping_array];


get it. here the changes i made, correct?
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
int main() { 
	//Declare an constant array of pointer to 6 Shipping Container Object
 	const int TOTAL_CONTAINERS = 6; 
 	ShippingContainer *sc[TOTAL_CONTAINERS]; 
	string theContent;
  
	int RFID_array; 
	cout << "Enter number of RFID container : ";
	cin  >> RFID_array;

	RFIDShippingContainer *RFID_item = new RFIDShippingContainer[RFID_array];

	for( int i = 0 ; i < RFID_array ; i ++ ){
		cout << "Enter Content of item : ";
		getline( cin, theContent );
		RFID_item[i].add( theContent );
	}

	int ManualShipping_array;
	cout << "Enter number of Manual container : ";
	cin  >> ManualShipping_array;

	ManualShippingContainer *Manual_item = new ManualShippingContainer[ManualShipping_array];
	for( int i = 0 ; i < ManualShipping_array ; i ++ ){
		cout << "Enter Content of item : ";
		getline( cin, theContent );
		Manual_item[i].setManifest( theContent );
	}



so how i display all the getManifest for ShippingContainer ?
sc[0] = RFID_item;
sc[1] = Manual_item; << not really know how to declare since my array is been insert by user

so how should i declare them?
here is my main implementation
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
#include	<iostream> 
#include	"ShippingContainer.h" 
#include	"ManualShippingContainer.h" 
#include	"RFIDShippingContainer.h" 
  
  
int main() { 
	//Declare an constant array of pointer to 6 Shipping Container Object
 	const int TOTAL_CONTAINERS = 6; 
 	ShippingContainer *sc[TOTAL_CONTAINERS]; 
	string theContent;
  
	int RFID_array; 
	cout << "Enter number of RFID container : ";
	cin  >> RFID_array;

	RFIDShippingContainer *RFID_item = new RFIDShippingContainer[RFID_array];

	for( int i = 0 ; i < RFID_array ; i ++ ){
		cout << "Enter Content of item : ";
		getline( cin, theContent );
		RFID_item[i].add( theContent );
	}

	int ManualShipping_array;
	cout << "Enter number of Manual container : ";
	cin  >> ManualShipping_array;

	ManualShippingContainer *Manual_item = new ManualShippingContainer[ManualShipping_array];
	for( int i = 0 ; i < ManualShipping_array ; i ++ ){
		cout << "Enter Content of item : ";
		getline( cin, theContent );
		Manual_item[i].setManifest( theContent );
	}


 	/*RFIDShippingContainer *RFID_item = new RFIDShippingContainer(); 
  
 	RFID_item->add( "crate of pears" ); 
 	RFID_item->add( "crate of apples" ); 
 	RFID_item->add( "crate of pears" );
	RFID_item->add( "crate of pears" );
  
 	sc[0] = RFID_item; 
  
 	ManualShippingContainer *Manual_item = new ManualShippingContainer(); 
  
 	Manual_item->setManifest( "5 crate of apples " );
  
 	sc[1] = Manual_item; 
  
 	for ( int i = 0; i < 2; i++ ) 
 	{ 
 		cout << sc[ i ]->getManifest() << endl; 
 	} */
  
  
 	delete RFID_item; //deallocate the memory for RFID containers
 	delete Manual_item; //deallocate the memory for Manual Shipping containers
  
	system( "pause" );//System pause
 	return 0; //Exit the program
 }
Topic archived. No new replies allowed.