Disabled: CONTROL_WEIGHT, ORDER_DELIVERY_QUEUE and CONTROL_FRAGILE_PRODUCT
( p.[i].productName )
when the dispatchedProduct( )
function on line 34 is executed?//#define CONTROL_WEIGHT
//#define ORDER_DELIVERY_QUEUE
//#define CONTROL_FRAGILE_PRODUCT
using namespace std;
struct Product {
char productName[50];
char purchaseDate[9];
bool dispatched;
#ifdef CONTROL_WEIGHT
float weight;
#endif
#ifdef CONTROL_FRAGILE_PRODUCT
bool fragileProduct;
#endif
} p[4] ={ {"Shower", "03/03/21", false},
{"Glasses", "04/04/21", false},
{"Lamp", "01/01/21", false},
{"Cement", "02/02/21", false} };
#ifdef ORDER_DELIVERY_QUEUE
void orderDeliveryQueue() {
// This algorithm sorts the p product array considering the purchase date.
// At the end of the algorithm, the product with the oldest purchase date becomes the first element of the array
// and the product with the most recent purchase date becomes the last element of the array.
}
#endif
void dispatchedProduct() {
#ifdef ORDER_DELIVERY_QUEUE
orderDeliveryQueue();
#endif
#ifdef CONTROL_WEIGHT
float limitWeightDelivery = 300;
#endif
#ifdef CONTROL_FRAGILE_PRODUCT
int fragileProductTotal = 0;
#endif
int i, n = 4;
for ( i = 0; i < n; i ++ ) {
if ( !p[i].dispatched ) {
#ifdef CONTROL_FRAGILE_PRODUCT
if ( !p[i].fragileProduct ) {
#endif
#ifdef CONTROL_WEIGHT
if ( p[i].weight < limitWeightDelivery ) {
#endif
printf( "\n Product name: %s", p[i].productName );
printf( "\n Product purchase date : %s", p[i].purchaseDate );
#ifdef CONTROL_WEIGHT
printf("\n Weight: %.2f", p[i].weight);
#endif
#ifdef CONTROL_FRAGILE_PRODUCT
if ( !p[i].fragileProduct ) {
printf("\n fragile product: No");
}
#endif
p[i].dispatched = true;
break;
#ifdef CONTROL_WEIGHT
} else
printf("\n Overweight delivery product! The customer must come to pick the product!");
#endif
#ifdef CONTROL_FRAGILE_PRODUCT
} else
printf("\n Fragile product! The customer must come to pick the product!");
fragileProductTotal++;
#endif
}
if ( i == n - 1 )
printf("\n There are no products to be dispatched!!!");
}
}
int main(){
dispatchedProduct();
return 0;
}