On-line: гостей 0. Всего: 0 [подробнее..]
Программисты всех стран, объединяйтесь!

АвторСообщение



ссылка на сообщение  Отправлено: 18.10.12 13:07. Заголовок: Just ask some question


@vlad

for the last time RFID container add()

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?

Спасибо: 0 
ПрофильЦитата Ответить
Ответов - 16 [только новые]





ссылка на сообщение  Отправлено: 18.10.12 13:39. Заголовок: int RFID_array; co..


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?

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 13:52. Заголовок: const int TOTAL_CONT..


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];


do some changes. isnt correct?

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 14:36. Заголовок: int main() { //Dec..


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.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.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?


Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 15:34. Заголовок: //Declare an constan..


//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;
cin.ignore();

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->add( theContent );
sc = RFID_item;
}

int ManualShipping_array;
cout << "Enter number of Manual container : ";
cin >> ManualShipping_array;
cin.ignore();

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->setManifest( theContent );
}
for ( int i = 0; i < 2; i++ )
{
cout << sc[ i ]->getManifest() << endl;
}


how should i declare in the loop ? according to print it .

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 16:35. Заголовок: I see two possibilit..


I see two possibilities. The first one is that you declare an array of type ShippingContainer * with fixed size and then you use function std::rand to determine how many containers will be of type RFIDShippingContainer or of type ManualShipping. Or you can ask a user to enter the number of for example RFIDShippingContainer containers.

Another approach is that you at first ask a user how many containers should be of type RFIDShippingContainer and of type ManualShipping and then you dynamically allocate an array with the size equal to the sum of the two numbers.

There is another (the third) idea. You have an array of fixed size. And before assigning an object of ShippingContainer to an array element you ask a user what kind of container he wants to have.

Also you can define a constant array of strings which will contain manifests and then you will be pick randomly a manifest to add it to a given RFIDShippingContainer container.

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 16:43. Заголовок: but maximum containe..


but maximum container is 6 only?

then how i called the ShippingContainer* out with fixed size?

because just now i tried to use looping to call it out, the result of output was repeating , and i'm not really know how to display it.

for third idea . u mean that i should do a switch( choice ) menu?
if choice = 1 mean go the RFID container that i want to have
if choice = 2 mean go the manual container that i want to have?

isn't this u mean ?

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 16:56. Заголовок: for the second choic..


for the second choice . even thought i did it like this way

int RFID_array;  
cout << "Enter number of RFID container : ";
cin >> RFID_array;
cin.ignore();

int ManualShipping_array;
cout << "Enter number of Manual container : ";
cin >> ManualShipping_array;
cin.ignore();
RFIDShippingContainer *RFID_item = new RFIDShippingContainer[RFID_array];
ManualShippingContainer *Manual_item = new ManualShippingContainer[ManualShipping_array];



then how should call the shippingcontainer* out? confuse with it

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 17:18. Заголовок: You have two choices..


You have two choices. Either you declare an array of fixed size as for example

ShippingContainer *sc[N];

where N - any constant integral expression.

Or you can allocate memory in the heap

ShippingContainer **sc = new ShippingContainer *[N];

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 17:21. Заголовок: i get it just an e..


i get it

just an example :
const int N = 6;
ShippingContainer *sc[N];


i just having problem at here
int RFID_array;  
cout << "Enter number of RFID container : ";
cin >> RFID_array;
cin.ignore();

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->add( theContent );
sc = RFID_item;
}

int ManualShipping_array;
cout << "Enter number of Manual container : ";
cin >> ManualShipping_array;
cin.ignore();

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->setManifest( theContent );
}
for ( int i = 0; i < 2; i++ )
{
cout << sc[ i ]->getManifest() << endl;
}


because i not really know how to cout the getManifest() out and maximum of
container RFID_array and ManualShipping_array when total up must less than or equal to 6

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 18:32. Заголовок: One more either you ..


One more either you declare an array of type ShippingContainer * of fixed size as for example

ShippingContainer * sc[N];,

or you allocate a memory in heap as

ShippingContainer ** sc = new ShippingContainer *[N];

In the both cases method getManifest is caleed as

sc[ i ]->getManifest();

where i - any acceptable index.

There is already an example in the previous thread how to fill the array. Investigate it.

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 18:47. Заголовок: i try to . but u sai..


i try to . but u said i - any acceptable index

string theContent; 
int RFID_array = 0;
int ManualShipping_array = 0;
int totalContainerArray = 0;
int counter = 0;

//that creates an array of pointers to 6 ShippingContainer objects
const int TOTAL_CONTAINERS = 6;
ShippingContainer *sc[TOTAL_CONTAINERS];


do{
cout << "Enter number of RFID container : ";
cin >> RFID_array;

cout << "Enter number of Manual container : ";
cin >> ManualShipping_array;
cin.ignore();

totalContainerArray = RFID_array + ManualShipping_array;

if( totalContainerArray > 6 || totalContainerArray < 1 )
cout << "Invalid Input ! Maximum 6 numbers of container ! " << endl << endl;
}while( totalContainerArray > 6 || totalContainerArray < 1 );

RFIDShippingContainer *RFID_item = new RFIDShippingContainer[RFID_array];

cout << endl;

for( int i = 0 ; i < RFID_array ; i ++ ){
cout << "Enter item for RFID container : ";
getline( cin, theContent );
RFID_item->add( theContent );
sc[counter++] = RFID_item;
}

cin.ignore();

ManualShippingContainer *Manual_item = new ManualShippingContainer[ManualShipping_array];
for( int i = 0 ; i < ManualShipping_array ; i ++ ){
cout << "\nEnter item for manual shipping container : ";
getline( cin, theContent );
Manual_item->setManifest( theContent );
sc[counter++] = Manual_item;
}

for ( int i = 0; i < counter; i++ )
{
cout << sc[ i ]->getManifest() << endl;
}


because the output is keep repeating
the output when i can getManifest it will be:

1 crate of apples , 2 crate of pears
1 crate of apples , 2 crate of pears
1 crate of apples , 2 crate of pears
5 crate of pears.

something like this. it's correct?

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 19:16. Заголовок: You shall ot allocat..


You shall ot allocate a whole array of ManualShippingContainer or RFIDShippingContainer containers. You already defined an array. Fill it. What is the problem?

Write for example in a loop

sc[ i ] = new ManualShippingContainer();

I do not understand why are you asking the questions when there is an example how to do that in the previous thread?



Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 19:54. Заголовок: i already tired of i..


i already tired of it , i keep try and keep try already . i know u already provided the example.

u mean i have to set 1 by 1?

using loop?

i have to using sc = new RFIDShippingContainer();
or sc = new RFIDShippingContainer();
where i is any index

isn't like this?

then how i see their different behaviour for the ShippingContainer ?

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 18.10.12 20:07. Заголовок: I do not understand ..


I do not understand what you mean. There is an example how to do that. use the example. You should allocate 6 (as you pointed out) objects of types RFIDShippingContainer and ManualShippingContainer. Each element of the array should be assigned a new object.


Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 19.10.12 03:28. Заголовок: i get it after i wak..


i get it after i wake up

isnt u mean this?
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;

RFID_item->add( "crate of mangoes" );
RFID_item->add( "crate of bananas" );
RFID_item->add( "crate of bananas" );

sc[1] = RFID_item;

RFID_item->add( "crate of bananas" );
RFID_item->add( "crate of bananas" );
RFID_item->add( "crate of pears" );
RFID_item->add( "crate of pears" );

sc[2] = RFID_item;


Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 19.10.12 13:40. Заголовок: I would do the follo..


I would do the following way

ShippingContainer *sc[TOTAL_CONTAINERS]; 
const char * manifets[] = {
"crate of pears",
"crate of apples",
"crate of mangoes",
"crate of bananas" };
const MANIFEST_NUM = sizeof( manifests ) / sizeof( *manifests );
const int MAX_MANIFEST = 10;


// Let assume that among TOTAL_CONTAINERS there are RFID_TOTAL RFIDShippingContainer containers

int i = 0;

for ( ; i < RFID_TOTAL; i++ )
{
sc[ i ] = new RFIDShippingContainer();

int total_manifests = std::rand() % MAX_MANIFEST;

for ( int j = 0; j < total_manifests; j++ )
{
sc[ i ]->add( manifests[ std::rand() % MANIFEST_NUM ] );
}
}

// something similar should be done for ManualShippingContainer

for ( ; i < TOTAL_CONTAINERS; i++ )
{
sc[ i ] = ManualShippingContainer();
// other stuff
}


I did not test the code. It can contain errors. But purpose of the code to demonstrate the idea.





Спасибо: 0 
ПрофильЦитата Ответить
Ответ:
1 2 3 4 5 6 7 8 9
большой шрифт малый шрифт надстрочный подстрочный заголовок большой заголовок видео с youtube.com картинка из интернета картинка с компьютера ссылка файл с компьютера русская клавиатура транслитератор  цитата  кавычки моноширинный шрифт моноширинный шрифт горизонтальная линия отступ точка LI бегущая строка оффтопик свернутый текст

показывать это сообщение только модераторам
не делать ссылки активными
Имя, пароль:      зарегистрироваться    
Тему читают:
- участник сейчас на форуме
- участник вне форума
Все даты в формате GMT  3 час. Хитов сегодня: 3
Права: смайлы да, картинки да, шрифты да, голосования нет
аватары да, автозамена ссылок вкл, премодерация откл, правка нет