Hey guys so I'm working on a program that requires me to build 3 structs for 3 text files(shipments, customers, orders) containing information for each struct and we have to load in the info via arrays.
I have this so far, but I'm not sure how I'm supposed to print them out and also not sure if my functions are working. But i haven't gotten any errors and i was hoping if there was any way to show the output. I do have to do anyway since I'm supposed to give the user an option to print out records for any of the files, may it be the shipments, customers, or the orders. And when they are displayed, they should be formatted neatly.
How am i supposed to incorporate the formatting? but first of all, how do I print the arrays?
I was thinking of creating a function called
void PrintRecords();
but I'm not sure what to use as parameters and what to write inside to make this work.
No, it does not matter wherefrom you got the contents of the array.
In this case, pass the number of shipments that you have read from the file as the second parameter.
The error reads : 'no match of 'operator*' (operand type is 'orders')
'no match of 'operator*' (operand type is 'shipments')
'no match of 'operator*' (operand type is 'customers')
// ship_info: array (pointer to first element of array)
// n : number of elements in the array
void getShipments( shipments ship_info[], int n )
{
ifstream ShipmentInfo("Shipments.txt");
if( ShipmentInfo.is_open() )
{
for( int ship_count = 0; ship_count < n; ++ship_count )
{
ShipmentInfo >> ship_info[ship_count].FoodItem
>> ship_info[ship_count].ExpDate
>> ship_info[ship_count].BoxSize
>> ship_info[ship_count].BoxWeight
>> ship_info[ship_count].StorageMethod
>> ship_info[ship_count].DateReceived
>> ship_info[ship_count].ItemPrice;
}
}
// else failed to open file: report error??
}
To call the function:
1 2 3 4 5 6 7 8 9 10 11 12 13
void PrintAllRecords()
{
// ...
constint NUM_SHIPMENTS = 20 ;
shipments ship_info[NUM_SHIPMENTS] ;
// pass pointer to first element of array
// and the number of elements in the array
getShipments( ship_info, NUM_SHIPMENTS ) ;
// ...
}
I already declared the the array size of ship_info globally. Or was that wrong too?
and if i take out the asterisks (*ship_info[ship_count]. ..) , it gives me more errors saying that i cannot convert it properly ("cannot convert shipments to shipments**)
First snippet:
Line 1: Why are you passing in shipment_size? You don't use it. Besides, it is uninitialized in main().
Line 4: What's the point of this line? You don't use it. Remove it.
Second snippet:
Line 7: Why are you declaring a local array here? You want to use the array that was passed in. Delete this line.
Line 9: You're using the shipment info array that was passed in. That's not what you're printing.
Lines 25-31: You're printing the local array which is uninitialized. You want to print the array that was passed in.
You're calling getShipments() twice. Once in main() and again in PrintAllRecords(). You only want to call it once. Delete the call inside PrintAllRecords(). PrintAllRecords should do one thing. i.e. print. An input operation does not belong in a print function.