A big-food company located in Norfolk, VA tries to run its main storehouse perfe
ID: 3885171 • Letter: A
Question
A big-food company located in Norfolk, VA tries to run its main storehouse perfectly. The company receives new shipments every day at the storehouse. The company redistributes the shipment to a set of customers (small businesses) located in the Tidewater area (Norfolk, Chesapeake, Suffolk, Portsmouth, Va. Beach, and Hampton). The data at the storehouse are saved into records in three text files. The first line of each file shows the number of records in the file. A Record contains many fields, where fields are separated by a comma, as follow:
Shipments.txt:
Name of food item
Expiration Date (month:day:year)
Size of the Box (length:width:height) in inches
Weight of the box in pounds
Best Storage Method (refrigerate “R”, freeze “F”, do not refrigerate “D”)
Date Shipment Received (month:day:year)
Price of the Item (dollar.cent)
Customers.txt:
Name of customer (small business)
Location (city name) of business
Distance from the Storehouse in miles
Orders.txt:
Name of customer (small business)
Name of item needed
Number of boxes
Total cost (dollar.cent)
Date (month:day:year) order is placed
Task: Your task for this assignment is to write a C++ program to help the company run its warehouse. Use struct to represent the elements of the arrays. Name the arrays shipments, customers, orders. As a result, the data will be read into arrays of structs. The size of each array cannot be fixed; instead, the size should be read from the corresponding data file except for shipments for which it is 20. All elements of an array are records read from a single file.
The main() function of your program should be very simple. The main function should be a collection of variables declaration and functions call. You will need to use three different functions to read the data from the three files. You can add more functions if you want. You must provide the user with a capability of printing the data of any record (shipment, customer, and orders) on the computer monitor. You must also provide a function to search for a specific item in the shipments array. The search should be done by the item name and from the computer monitor.
Do not use global variables except for the shipments struct array of size 20. Apart from this you can use at most one global variable
Files:
Shipments.txt
15
Apples 01:30:2015 10:11:12 20 R 01:21:2015 12.00
Bananas 10:25:2015 12:11:19 25 R 01:21:2015 15.00
Apples 02:25:2015 50:41:62 20 D 01:25:2015 40.00
PineApple 02:02:2015 05:04:60 40 R 01:02:2015 55.00
Grapes 03:03:2015 25:25:25 55 D 01:20:2014 64.00
Tomato 04:04:2015 30:30:30 18 D 01:20:2015 44.00
Potato 05:06:2015 25:25:25 66 D 01:25:2014 34.00
Lays 10:01:2016 10:90:60 25 D 10:22:2013 12.00
EggPlant 04:25:2015 55:49:60 76 R 01:25:2015 11.00
Oranges 07:01:2015 50:41:62 55 R 12:20:2014 16.00
Kiwi 02:02:2015 05:41:06 88 D 12:15:2014 14.00
Chicken 09:25:2016 05:04:06 99 F 10:10:2014 80.00
Pears 02:25:2015 26:41:36 64 R 01:23:2015 21.00
Carrot 12:02:2015 26:36:26 54 D 01:20:2015 32.00
Plum 12:02:2015 05:04:06 55 D 01:29:2015 20.00
Customers.txt
15
Andrew Norfolk 20
Anne Suffolk 30
Bruce Chesapeake 36
Charlie Hampton 40
Charry Norfolk 15
Finn VaBeach 24
Gracy Hampton 39
Ben Suffolk 25
Vijay Chesapeake 37
Jay Suffolk 28
Sajan Hampton 48
Rishi Chesapeake 39
John Suffolk 28
Smith Hampton 49
Pepp Chesapeake 32
Orders.txt
15
Andrew Apples 3 23.00 01:25:2015
Bruce Bananas 5 32.20 02:20:2015
Finn PineApple 8 55.55 10:02:2014
Gracy Grapes 9 47.74 12:20:2014
Smith Apples 2 80.00 11:02:2014
Pepp Bananas 5 10.10 01:12:2015
Smith PineApple 7 50.20 01:23:2015
Jay Carrot 8 90.09 01:29:2015
Charlie Apples 7 20.85 01:23:2015
Rishi Potato 2 29.99 10:12:2014
John Plum 9 55.98 01:02:2015
Ben PineApple 10 55.99 09:13:2014
Andrew Apples 11 89.55 12:18:2013
Pepp Chicken 15 99.22 11:20:2014
Anne Bananas 5 87.00 01:13:2015
Example Output
Shipments Food ItemExp Date Box Size Weight Storage Received date Price 12.00 15.00 40.00 55.00 64.00 44.00 34.00 12.00 11.00 16.00 14.00 80.00 21.00 32.00 20.00 Apples Bananas Apples 101:30:2015 10:11:12 20 10:25:2015 12:11:1925 02 :25:2015 50:41:62 20 ineApple 02:02:2015 05:04:60 40 03:03:2015 25:25:25 55 104:04:2015 30:30:30 18 05 06:2015 25:25:25 66 10:01:2016 10:90:625 04:25 2015 55:49:6 76 07:01:201550:41:6255 02:02:2015 05:41:06 88 09:25:2016 05:04:06 99 02 :25 2015 26:41:36 64 12:02 2015 26:36:26 54 12:02:2015 05:04:06 55 1 21:2015 01 21:2015 01 25:2015 01 02 2015 01 20 2014 01:20:2015 01 25:2014 10:22 2013 01:25:2015 12:20 2014 12:15:2014 10:10:2014 01 23:2015 01 20:2015 1:29:2015 Grapes omato Potato Lays EggPlant Oranges Kivi Chicken Pears Carrot Customers Customer Name City Distance Norfolk Suffolk Chesapeake Hampton Norfolk UaBeach Hampton Suffolk Chesapeake Suffolk Hampton Andrew Anne Bruce Charlie Charry 20 30 Gracy Ben 28 48 Sajan Rishi i Chesapeake 28 Suffolk Hampton Chesapeake SmithExplanation / Answer
package com.graphhopper.jsprit.core.problem.job;
import java.util.Collection;
import com.graphhopper.jsprit.core.problem.AbstractJob;
import com.graphhopper.jsprit.core.problem.Capacity;
import com.graphhopper.jsprit.core.problem.Location;
import com.graphhopper.jsprit.core.problem.Skills;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindowsImpl;
public class Shipment extends AbstractJob {
public static class Builder {
private String id;
private double pickupServiceTime = 0.0;
private double deliveryServiceTime = 0.0;
private TimeWindow deliveryTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);
private TimeWindow pickupTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);
private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance();
private Capacity capacity;
private Skills.Builder skillBuilder = Skills.Builder.newInstance();
private Skills skills;
private String name = "no-name";
private Location pickupLocation_;
private Location deliveryLocation_;
protected TimeWindowsImpl deliveryTimeWindows;
private boolean deliveryTimeWindowAdded = false;
private boolean pickupTimeWindowAdded = false;
private TimeWindowsImpl pickupTimeWindows;
private int priority = 2;
public Object userData;
public double maxTimeInVehicle = Double.MAX_VALUE;
/**
* Returns new instance of this builder.
*
* @param id the id of the shipment which must be a unique identifier among all jobs
* @return the builder
*/
public static Builder newInstance(String id) {
return new Builder(id);
}
Builder(String id) {
if (id == null) throw new IllegalArgumentException("id must not be null");
this.id = id;
pickupTimeWindows = new TimeWindowsImpl();
pickupTimeWindows.add(pickupTimeWindow);
deliveryTimeWindows = new TimeWindowsImpl();
deliveryTimeWindows.add(deliveryTimeWindow);
}
/**
* Sets user specific domain data associated with the object.
*
* <p>
* The user data is a black box for the framework, it only stores it,
* but never interacts with it in any way.
* </p>
*
* @param userData
* any object holding the domain specific user data
* associated with the object.
* @return builder
*/
public Builder setUserData(Object userData) {
this.userData = userData;
return this;
}
/**
* Sets pickup location.
*
* @param pickupLocation
* pickup location
* @return builder
*/
public Builder setPickupLocation(Location pickupLocation) {
this.pickupLocation_ = pickupLocation;
return this;
}
/**
* Sets pickupServiceTime.
* <p>
* <p>ServiceTime is intended to be the time the implied activity takes at the pickup-location.
*
* @param serviceTime the service time / duration the pickup of the associated shipment takes
* @return builder
* @throws IllegalArgumentException if servicTime < 0.0
*/
public Builder setPickupServiceTime(double serviceTime) {
if (serviceTime < 0.0) throw new IllegalArgumentException("serviceTime must not be < 0.0");
this.pickupServiceTime = serviceTime;
return this;
}
/**
* Sets the timeWindow for the pickup, i.e. the time-period in which a pickup operation is
* allowed to START.
* <p>
* <p>By default timeWindow is [0.0, Double.MAX_VALUE}
*
* @param timeWindow the time window within the pickup operation/activity can START
* @return builder
* @throws IllegalArgumentException if timeWindow is null
*/
public Builder setPickupTimeWindow(TimeWindow timeWindow) {
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
this.pickupTimeWindow = timeWindow;
this.pickupTimeWindows = new TimeWindowsImpl();
this.pickupTimeWindows.add(timeWindow);
return this;
}
/**
* Sets delivery location.
*
* @param deliveryLocation delivery location
* @return builder
*/
public Builder setDeliveryLocation(Location deliveryLocation) {
this.deliveryLocation_ = deliveryLocation;
return this;
}
/**
* Sets the delivery service-time.
* <p>
* <p>ServiceTime is intended to be the time the implied activity takes at the delivery-location.
*
* @param deliveryServiceTime the service time / duration of shipment's delivery
* @return builder
* @throws IllegalArgumentException if serviceTime < 0.0
*/
public Builder setDeliveryServiceTime(double deliveryServiceTime) {
if (deliveryServiceTime < 0.0) throw new IllegalArgumentException("deliveryServiceTime must not be < 0.0");
this.deliveryServiceTime = deliveryServiceTime;
return this;
}
/**
* Sets the timeWindow for the delivery, i.e. the time-period in which a delivery operation is
* allowed to start.
* <p>
* <p>By default timeWindow is [0.0, Double.MAX_VALUE}
*
* @param timeWindow the time window within the associated delivery is allowed to START
* @return builder
* @throws IllegalArgumentException if timeWindow is null
*/
public Builder setDeliveryTimeWindow(TimeWindow timeWindow) {
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
this.deliveryTimeWindow = timeWindow;
this.deliveryTimeWindows = new TimeWindowsImpl();
this.deliveryTimeWindows.add(timeWindow);
return this;
}
/**
* Adds capacity dimension.
*
* @param dimensionIndex the dimension index of the corresponding capacity value
* @param dimensionValue the capacity value
* @return builder
* @throws IllegalArgumentException if dimVal < 0
*/
public Builder addSizeDimension(int dimensionIndex, int dimensionValue) {
if (dimensionValue < 0) throw new IllegalArgumentException("capacity value cannot be negative");
capacityBuilder.addDimension(dimensionIndex, dimensionValue);
return this;
}
/**
* Builds the shipment.
*
* @return shipment
* @throws IllegalArgumentException if neither pickup-location nor pickup-coord is set or if neither delivery-location nor delivery-coord
* is set
*/
public Shipment build() {
if (pickupLocation_ == null) throw new IllegalArgumentException("pickup location is missing");
if (deliveryLocation_ == null) throw new IllegalArgumentException("delivery location is missing");
capacity = capacityBuilder.build();
skills = skillBuilder.build();
return new Shipment(this);
}
public Builder addRequiredSkill(String skill) {
skillBuilder.addSkill(skill);
return this;
}
public Builder setName(String name) {
this.name = name;
return this;
}
public Builder addDeliveryTimeWindow(TimeWindow timeWindow) {
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null");
if(!deliveryTimeWindowAdded){
deliveryTimeWindows = new TimeWindowsImpl();
deliveryTimeWindowAdded = true;
}
deliveryTimeWindows.add(timeWindow);
return this;
}
public Builder addDeliveryTimeWindow(double earliest, double latest) {
addDeliveryTimeWindow(TimeWindow.newInstance(earliest, latest));
return this;
}
public Builder addPickupTimeWindow(TimeWindow timeWindow) {
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null");
if(!pickupTimeWindowAdded){
pickupTimeWindows = new TimeWindowsImpl();
pickupTimeWindowAdded = true;
}
pickupTimeWindows.add(timeWindow);
return this;
}
public Builder addPickupTimeWindow(double earliest, double latest) {
return addPickupTimeWindow(TimeWindow.newInstance(earliest, latest));
}
/**
* Set priority to shipment. Only 1 (high) to 10 (low) are allowed.
* <p>
* Default is 2 = medium.
*
* @param priority
* @return builder
*/
public Builder setPriority(int priority) {
if (priority < 1 || priority > 10)
throw new IllegalArgumentException("incorrect priority. only 1 (very high) to 10 (very low) are allowed");
this.priority = priority;
return this;
}
/**
* Sets maximal time the job can be in vehicle.
*
* @param maxTimeInVehicle
* @return
*/
public Builder setMaxTimeInVehicle(double maxTimeInVehicle){
if(maxTimeInVehicle < 0) throw new IllegalArgumentException("maxTimeInVehicle should be positive");
this.maxTimeInVehicle = maxTimeInVehicle;
return this;
}
}
private final String id;
private final double pickupServiceTime;
private final double deliveryServiceTime;
private final TimeWindow deliveryTimeWindow;
private final TimeWindow pickupTimeWindow;
private final Capacity capacity;
private final Skills skills;
private final String name;
private final Location pickupLocation_;
private final Location deliveryLocation_;
private final TimeWindowsImpl deliveryTimeWindows;
private final TimeWindowsImpl pickupTimeWindows;
private final int priority;
private final double maxTimeInVehicle;
Shipment(Builder builder) {
setUserData(builder.userData);
this.id = builder.id;
this.pickupServiceTime = builder.pickupServiceTime;
this.pickupTimeWindow = builder.pickupTimeWindow;
this.deliveryServiceTime = builder.deliveryServiceTime;
this.deliveryTimeWindow = builder.deliveryTimeWindow;
this.capacity = builder.capacity;
this.skills = builder.skills;
this.name = builder.name;
this.pickupLocation_ = builder.pickupLocation_;
this.deliveryLocation_ = builder.deliveryLocation_;
this.deliveryTimeWindows = builder.deliveryTimeWindows;
this.pickupTimeWindows = builder.pickupTimeWindows;
this.priority = builder.priority;
this.maxTimeInVehicle = builder.maxTimeInVehicle;
}
@Override
public String getId() {
return id;
}
public Location getPickupLocation() {
return pickupLocation_;
}
/**
* Returns the pickup service-time.
* <p>
* <p>By default service-time is 0.0.
*
* @return service-time
*/
public double getPickupServiceTime() {
return pickupServiceTime;
}
public Location getDeliveryLocation() {
return deliveryLocation_;
}
/**
* Returns service-time of delivery.
*
* @return service-time of delivery
*/
public double getDeliveryServiceTime() {
return deliveryServiceTime;
}
/**
* Returns the time-window of delivery.
*
* @return time-window of delivery
*/
public TimeWindow getDeliveryTimeWindow() {
return deliveryTimeWindows.getTimeWindows().iterator().next();
}
public Collection<TimeWindow> getDeliveryTimeWindows() {
return deliveryTimeWindows.getTimeWindows();
}
/**
* Returns the time-window of pickup.
*
* @return time-window of pickup
*/
public TimeWindow getPickupTimeWindow() {
return pickupTimeWindows.getTimeWindows().iterator().next();
}
public Collection<TimeWindow> getPickupTimeWindows() {
return pickupTimeWindows.getTimeWindows();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
/**
* Two shipments are equal if they have the same id.
*
* @return true if shipments are equal (have the same id)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Shipment other = (Shipment) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
@Override
public Capacity getSize() {
return capacity;
}
@Override
public Skills getRequiredSkills() {
return skills;
}
@Override
public String getName() {
return name;
}
/**
* Get priority of shipment. Only 1 = high priority, 2 = medium and 3 = low are allowed.
* <p>
* Default is 2 = medium.
*
* @return priority
*/
@Override
public int getPriority() {
return priority;
}
@Override
public double getMaxTimeInVehicle() {
return maxTimeInVehicle;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.