Here's a simplified C program that simulates delivering a product to an address:
Product Delivery Program
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// Define structure for products
typedef struct {
int id;
char name[50];
float price;
} Product;
// Define structure for addresses
typedef struct {
char street[100];
char city[50];
char state[50];
int zip;
} Address;
// Define structure for deliveries
typedef struct {
Product product;
Address address;
time_t deliveryTime;
} Delivery;
// Function to create a new product
Product createProduct(int id, char *name, float price) {
Product product;
product.id = id;
strcpy(product.name, name);
product.price = price;
return product;
}
// Function to create a new address
Address createAddress(char *street, char *city, char *state, int zip) {
Address address;
strcpy(address.street, street);
strcpy(address.city, city);
strcpy(address.state, state);
address.zip = zip;
return address;
}
// Function to create a new delivery
Delivery createDelivery(Product product, Address address) {
Delivery delivery;
delivery.product = product;
delivery.address = address;
delivery.deliveryTime = time(NULL);
return delivery;
}
// Function to display delivery details
void displayDelivery(Delivery delivery) {
printf("Product ID: %d\n", delivery.product.id);
printf("Product Name: %s\n", delivery.product.name);
printf("Product Price: %.2f\n", delivery.product.price);
printf("Delivery Address: %s, %s, %s %d\n", delivery.address.street, delivery.address.city, delivery.address.state, delivery.address.zip);
printf("Delivery Time: %s", ctime(&delivery.deliveryTime));
}
int main() {
// Create products
Product product1 = createProduct(1, "Laptop", 999.99);
Product product2 = createProduct(2, "Smartphone", 799.99);
// Create addresses
Address address1 = createAddress("123 Main St", "Anytown", "CA", 12345);
Address address2 = createAddress("456 Elm St", "Othertown", "NY", 67890);
// Create deliveries
Delivery delivery1 = createDelivery(product1, address1);
Delivery delivery2 = createDelivery(product2, address2);
// Display delivery details
printf("Delivery 1:\n");
displayDelivery(delivery1);
printf("\nDelivery 2:\n");
displayDelivery(delivery2);
return 0;
}
This program demonstrates the following concepts:
1. *Product structure*: A structure to represent products with attributes like ID, name, and price.
2. *Address structure*: A structure to represent addresses with attributes like street, city, state, and zip.
3. *Delivery structure*: A structure to represent deliveries with attributes like product, address, and delivery time.
4. *Delivery creation*: Functions to create products, addresses, and deliveries.
5. *Delivery display*: A function to display delivery details.
Note that this program is a highly simplified example and does not cover real-world complexities like logistics, payment processing, and order management.