Question
Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART A PART B Assignment 1 #include #include #include #include
Need help with C++ assignment
Assignment 1 and .txt files are provided at the bottom.
PART A
PART B
Assignment 1
#include
using namespace std;
/**
This structure is to store the date and it has three integer fields
**/
struct Date{
int day;
int month;
int year;
};
/**
This structure is to store the size of the box and it also have three int fields
**/
struct SizeOfBox{
int length;
int width;
int height;
};
/**
This is the main shipment structure which contains the instances of the above structures
as member of structure. You can see that we are using the same Date struct for both expiry date
and shipment received date. We are just creating different instance of the struct
**/
struct Shipment {
string foodName;
Date expdate;
SizeOfBox sizeofbox;
float weightOfBox;
char storageMethod;
Date shipmentrecieved;
double priceofitem;
};
/**
This is the struct for storing customer information
**/
struct Customers{
string customerName;
string city;
int distance;
};
/**
This is the struct used to store the information about orders. this struct also contains the
instances of other structures
**/
struct Orders{
string customerName;
string itemName;
int numberOfBoxes;
double costofitem;
Date orderDate;
};
/**
As we are also using shipment struct for searching we are using a fixed number for shipment
which is 20. This is the maximum size the shipment array can be
**/
const int NO_OF_SHIPMENTS = 20;
/**
This is the object name for the struct Shipment of size 20
**/
Shipment shipments[NO_OF_SHIPMENTS];
/**
The following are the functions that are used for opening the data file and reading
contents into the respective struct arrays. Each function takes the input stream
as the parameter.
These three functions are mandatory as instructed in the Assignment
**/
void getDataShipments(ifstream& inFile);
void getDataOrders(ifstream& inFile);
void getDataCustomers(ifstream& inFile);
/**
The following are the functions that are used for displaying the
contents from the respective struct arrays on Monitor.
Each function takes the respective struct array and total items.
**/
void displayShipments(Shipment shipments[],int totalShipments);
void displayCustomers(Customers customer[], int totalCustomers);
void displayOrders(Orders orders[], int totalOrders);
/**
These functions are used for printing horizontal line and heading before you display
the contents of the struct
**/
void printHorizontalLine( int width, char border_char);
void printHeading( string title, int width );
/**
This function is used to search the shipment array by taking the shipment struct array
the item name to be searched and total number of shipments as the parameters
**/
void searchShipments(Shipment shipments[], string itemName, int totalShipments);
/**
This is the main function and it is mandatory that it should contains only declarations and function calls
**/
int main(){
cout
/**
Declaring the input streams for each file
**/
ifstream inDataShipments;
ifstream inDataCustomers;
ifstream inDataOrders;
/**
Opening the files. You can either hardcode the name of the files or ask the user to give the names
**/
inDataShipments.open("Shipments.txt");
inDataCustomers.open("Customers.txt");
inDataOrders.open("Orders.txt");
/**
If the any of the file cannot be opened then the program terminates displaying
the error message
**/
if (!inDataShipments)
{
cout
return 1;
}
if (!inDataCustomers)
{
cout
return 1;
}
if (!inDataOrders)
{
cout
return 1;
}
/**
Function calls to read data from input files.
**/
/**
One way to display the information is to automatically display the information after reading from the input
file or give the user for option to which information user wants to print
In this we have called the Display******* functions after reading the data. And finally asked the user weather
user wants to search or not.
**/
getDataShipments(inDataShipments);
getDataCustomers(inDataCustomers);
getDataOrders(inDataOrders);
/**
After displaying the contents that are read from the file, program is asking weather the user want to search or not
**/
int searchOption;
do{
cout
cin >> searchOption;
/**
If the user wants to search, it asks for the name of the item and calls the appropriate function to search
else the program terminates
**/
if(searchOption == 1){
string itemName;
cout
cin >> itemName;
searchShipments(shipments,itemName,NO_OF_SHIPMENTS);
}
}while(searchOption != 2);
if(searchOption == 2){
exit(0);
}
}
void printHorizontalLine( int width, char border_char){
cout.fill( border_char );
cout
cout.fill(' ');
}
void printHeading( string title, int width ){
//Declare Variables
int magic_width = 0;
magic_width = (width/2) - (title.length()/2) + title.length();
cout
cout
cout
cout
//reset count
cout.clear();
cout.fill(' ');
//VOID functions do NOT return a value
}
/**
Using the input stream sent as parameter we are reading the content from the Shipments.txt and storing it in the shipments struct array
**/
void getDataShipments(ifstream& inFile){
char decimal;
int totalShipmentItems;
inFile >> totalShipmentItems;
for(int i = 0; i
inFile >> shipments[i].foodName;
inFile >> shipments[i].expdate.month >> decimal >> shipments[i].expdate.day >> decimal >> shipments[i].expdate.year;
inFile >> shipments[i].sizeofbox.length >> decimal >> shipments[i].sizeofbox.width >> decimal >> shipments[i].sizeofbox.height;
inFile >> shipments[i].weightOfBox;
inFile >> shipments[i].storageMethod;
inFile >> shipments[i].shipmentrecieved.month >> decimal >> shipments[i].shipmentrecieved.day >> decimal >> shipments[i].shipmentrecieved.year;
inFile >> shipments[i].priceofitem;
}
inFile.close();
printHeading("Shipments", 80);
displayShipments(shipments,totalShipmentItems);
}
/**
Using the input stream sent as parameter we are reading the content from the Customers.txt and storing it in the customers struct array
**/
void getDataCustomers(ifstream& inFile){
int totalCustomerItems;
inFile >> totalCustomerItems;
Customers customers[totalCustomerItems];
for(int i = 0; i
inFile >> customers[i].customerName;
inFile >> customers[i].city;
inFile >> customers[i].distance;
}
inFile.close();
printHeading("Customers", 60);
displayCustomers(customers,totalCustomerItems);
}
/**
Using the input stream sent as parameter we are reading the content from the Orders.txt and storing it in the orders struct array
**/
void getDataOrders(ifstream& inFile){
char decimal;
int totalOrderItems;
inFile >> totalOrderItems;
Orders orders[totalOrderItems];
for(int i = 0; i
inFile >> orders[i].customerName;
inFile >> orders[i].itemName;
inFile >> orders[i].numberOfBoxes;
inFile >> orders[i].costofitem;
inFile >> orders[i].orderDate.month >> decimal >> orders[i].orderDate.day >> decimal >> orders[i].orderDate.year;
}
inFile.close();
printHeading("Orders", 60);
displayOrders(orders, totalOrderItems);
}
/**
Displaying the content from the shipments struct array on the monitor
**/
void displayShipments(Shipment shipments[], int totalShipments){
cout
printHorizontalLine(80,'-');
for(int i = 0; i
cout
cout.unsetf(ios_base::fixed);
}
}
/**
Displaying the content from the customers struct array on the monitor
**/
void displayCustomers(Customers customers[], int totalCustomers){
cout
printHorizontalLine(60,'-');
for(int i = 0; i
cout
}
}
/**
Displaying the content from the orders struct array on the monitor
**/
void displayOrders(Orders orders[],int totalOrders){
cout
printHorizontalLine(60,'-');
for(int i = 0; i
cout
}
}
/**
Function used to search the shipments struct array and if there is a match then
it displays all the information about the product on the monitor
**/
void searchShipments(Shipment shipment[], string itemName, int totalShipments){
string originalItemName;
bool searchHit = false;
cout
/**
Converts the user input value of item name to Upper Case, so that we can have case insensitive copmarision
**/
transform(itemName.begin(),itemName.end(),itemName.begin(), ::toupper);
printHeading("Search Results",80);
cout
printHorizontalLine(80,'-');
for(int i = 0; i
/**
Converts the item name to Upper Case without modifying the original data, so that we can have case insensitive comparision
**/
originalItemName = shipment[i].foodName;
transform(originalItemName.begin(),originalItemName.end(),originalItemName.begin(),::toupper);
if(itemName.compare(originalItemName) == 0){
searchHit = true;
cout
cout.unsetf(ios_base::fixed);
}
}
if(!searchHit){
cout
}
}
Shipments.txt
100
Tomato 09:20:2018 01:30:32 18.11 D 04:25:2015 44.00
EggPlant 01:30:2013 02:28:34 55.55 R 01:26:2015 20.00
EggPlant 09:10:2017 04:26:36 55 D 02:28:2015 16.69
Bananas 09:15:2013 24:38:60 40.66 F 01:26:2015 39.93
Potato 09:22:2015 08:22:40 20.2 D 01:29:2015 39.93
EggPlant 04:10:2019 10:20:42 76.18 R 10:11:2016 11.00
Grapes 06:30:2016 12:18:44 40.4 F 02:25:2015 20.00
Bread 07:10:2016 14:16:46 55 F 09:18:2015 24.25
Lays 09:10:2015 03:42:45 55 D 11:16:2015 39.93
Bananas 06:13:2015 06:39:48 80.8 R 01:29:2015 39.93
Potato 01:25:2015 09:36:51 24.42 D 01:30:2015 64.46
Apples 02:26:2019 12:33:54 58.85 R 03:13:2015 16.69
Lays 03:10:2015 15:30:57 70.7 D 01:29:2015 20.00
Plum 09:20:2017 18:27:60 96.69 D 12:12:2015 16.69
Plum 07:10:2018 21:24:63 55 F 02:18:2015 64.46
Lays 09:12:2020 04:64:68 12 F 07:22:2015 20.00
Potato 09:12:2016 08:60:72 28 R 07:22:2015 39.93
PineApple 06:28:2016 12:56:76 35.53 F 10:25:2015 39.93
Apples 08:10:2016 16:52:80 55 F 09:12:2015 64.46
Potato 06:18:2018 20:48:84 45.54 R 10:25:2015 16.69
Chicken 08:13:2018 24:44:88 99.99 R 10:11:2016 80.00
Lays 08:16:2018 28:40:92 25.12 D 04:25:2015 12.00
EggPlant 07:10:2015 32:36:96 55 R 01:12:2015 20.00
Tomato 09:10:2016 94:76:74 55 R 07:29:2015 39.93
Apples 07:10:2018 92:78:72 55 F 03:26:2015 20.00
EggPlant 08:27:2017 90:80:70 50.5 D 02:25:2015 24.25
Lays 01:10:2015 88:82:68 50 D 08:26:2015 39.93
EggPlant 07:13:2016 86:84:66 26.62 F 12:12:2015 39.93
Apples 02:30:2017 62:20:16 20.12 R 04:25:2015 12.00
Chicken 06:25:2015 58:24:14 30 R 01:29:2015 20.00
Bananas 01:29:2016 54:12:06 34.43 R 01:30:2015 39.93
EggPlant 01:28:2015 50:32:10 34.43 D 01:30:2015 20.00
Bread 06:14:2016 46:36:08 55.55 F 10:25:2015 39.93
Lays 02:29:2018 42:38:06 88.88 F 03:13:2015 20.00
Lays 09:10:2015 01:18:19 55 D 03:22:2015 20.00
Plum 02:23:2015 02:17:20 28.82 R 03:13:2015 20.00
Grapes 05:26:2017 03:16:21 25.52 D 10:25:2015 64.46
Pears 02:25:2015 04:15:22 48.84 D 03:13:2015 24.25
Grapes 08:19:2017 05:14:23 86.68 R 12:12:2015 39.93
Tomato 09:12:2014 06:13:24 56 F 07:22:2015 20.00
Lays 08:11:2019 07:12:25 65.56 D 10:25:2015 24.25
Grapes 02:24:2016 08:11:26 58.85 F 03:13:2015 39.93
Potato 09:18:2019 09:10:27 76.67 D 12:12:2015 20.00
Chicken 09:12:2019 28:39:40 80 F 07:22:2015 20.00
PineApple 07:17:2017 29:38:41 66.66 F 12:12:2015 20.00
Bananas 08:10:2016 30:37:42 55 F 01:29:2015 24.25
Apples 08:10:2016 31:36:43 55 F 01:28:2015 24.25
Grapes 03:28:2015 33:34:45 40 D 01:29:2015 64.46
Tomato 01:26:2016 46:55:56 34.43 F 01:30:2015 39.93
Potato 05:10:2016 47:54:57 55.44 F 08:26:2015 39.93
Chicken 07:10:2015 48:53:58 55 D 08:21:2015 20.00
Bananas 02:10:2015 49:52:59 86 R 08:26:2015 24.25
Chicken 04:22:2015 50:51:60 55 F 01:26:2015 80.52
Pears 09:16:2015 61:74:75 90.9 D 01:29:2015 20.00
Pears 09:10:2019 62:73:76 55 F 06:12:2015 24.25
Bananas 09:10:2019 63:72:77 55 D 11:14:2015 16.69
PineApple 01:24:2016 64:71:78 14.41 R 01:30:2015 16.69
Tomato 08:22:2016 65:70:79 60.6 R 02:25:2015 20.00
Bananas 07:15:2019 66:69:80 46.64 R 12:12:2015 39.93
Lays 08:25:2016 67:68:81 15.51 R 10:25:2015 20.00
Grapes 09:13:2018 82:93:94 10 R 07:22:2015 39.93
Carrot 02:15:2018 83:92:96 55.55 F 10:11:2016 32.00
Apples 09:12:2015 05:04:06 57 D 07:22:2015 24.25
Potato 08:10:2019 84:91:97 55 D 04:26:2015 64.46
Chicken 07:16:2016 86:89:99 56.65 F 12:12:2015 24.25
PineApple 09:10:2020 87:88:98 55 R 05:24:2015 39.93
Bread 08:16:2019 97:82:81 55.55 D 10:11:2016 24.25
PineApple 09:12:2018 96:83:82 78 R 07:22:2015 39.93
Oranges 06:11:2018 95:84:83 55.55 D 10:11:2016 16.00
Grapes 08:22:2017 94:85:84 55 D 04:25:2015 64.00
Grapes 08:10:2018 93:86:82 55 D 05:10:2015 20.00
PineApple 04:25:2013 92:87:88 65.56 D 01:26:2015 39.93
Apples 07:12:2019 91:88:86 16.61 F 12:12:2015 16.69
Grapes 08:10:2017 90:89:87 55 D 08:20:2015 20.00
Bananas 02:28:2019 05:04:06 78.87 D 03:13:2015 64.46
Bread 09:10:2016 05:04:06 55 R 04:16:2015 39.93
Tomato 09:10:2018 05:04:06 55 R 07:22:2015 39.93
PineApple 04:22:2018 05:04:06 40 R 04:25:2015 55.00
Tomato 07:14:2017 05:04:06 36.63 R 12:12:2015 20.00
Oranges 07:22:2015 05:04:06 55 F 01:10:2015 20.00
Chicken 09:10:2018 05:04:06 55 R 12:14:2015 20.00
Potato 08:18:2017 05:04:06 66.12 D 04:25:2015 34.00
Plum 08:08:2013 05:04:06 55 D 01:26:2015 20.00
EggPlant 02:27:2018 05:04:06 68.86 R 03:13:2015 39.93
Apples 08:10:2016 05:04:06 28.72 F 08:26:2015 64.46
Plum 08:10:2018 05:04:06 55 D 01:20:2015 16.69
Pears 08:20:2013 05:04:06 10 F 01:26:2015 24.25
PineApple 02:30:2019 05:04:06 98.89 D 03:13:2015 39.93
PineApple 04:21:2017 05:04:06 30.3 D 02:25:2015 39.93
Apples 09:19:2015 05:04:06 10.1 F 01:29:2015 24.25
Bread 02:20:2017 05:04:06 20.2 F 02:25:2015 20.00
Pears 09:10:2015 05:04:06 55 F 01:27:2015 20.00
Pears 09:14:2019 05:04:06 55.55 D 10:11:2016 21.00
Bananas 04:28:2018 05:04:06 25.25 R 04:25:2015 15.00
Pears 09:10:2019 05:04:06 55 D 06:22:2015 16.69
Tomato 07:10:2015 05:04:06 17.71 D 08:26:2015 16.69
Grapes 09:12:2017 05:04:06 68 F 07:22:2015 20.00
Kiwi 08:12:2019 05:04:06 88.88 F 10:11:2016 14.00
Chicken 07:10:2015 05:04:06 55 R 01:26:2015 20.00
Apples 06:26:2017 05:04:06 20.12 D 04:25:2015 40.00
Orders.txt
100
Charlie Lays 07 32.00 01:21:2015
Jay Potato 05 12.32 03:14:2015
Pepp PineApple 03 37.54 01:13:2015
Rishi Tomato 03 34.43 12:13:2014
Jay Tomato 09 16.00 01:13:2015
Rishi Kiwi 10 88.99 12:13:2014
Sajan Oranges 20 87.00 10:12:2014
John EggPlant 05 24.20 03:16:2015
Rishi Grapes 05 38.80 01:12:2015
Vijay Grapes 20 14.30 01:13:2015
Pepp Chicken 18 14.30 12:13:2014
Jay Carrot 08 90.09 10:12:2014
Rishi PineApple 13 54.78 02:12:2015
Rishi Bananas 15 29.99 02:14:2015
Vijay Kiwi 10 88.98 12:25:2014
John Oranges 13 34.00 01:21:2015
Sajan Potato 15 99.90 12:13:2014
Charlie Apples 20 99.99 02:14:2015
Vijay PineApple 07 22.10 01:25:2015
Sajan Lays 03 18.26 03:10:2015
Sajan Potato 07 62.68 04:18:2015
John Apples 15 45.90 01:25:2015
Pepp Grapes 09 80.72 04:30:2015
Sajan Oranges 9 87.00 01:25:2015
Pepp Grapes 09 36.00 01:21:2015
Pepp Chicken 07 22.22 03:14:2015
Pepp EggPlant 03 15.52 02:12:2015
Pepp Bananas 05 10.10 10:12:2014
Smith Apples 02 80.00 10:12:2014
Rishi Potato 18 38.00 01:21:2015
John PineApple 07 16.28 03:18:2015
Smith PineApple 07 50.20 10:12:2014
Jay Grapes 07 78.54 02:12:2015
Rishi Apples 15 25.52 02:12:2015
John Oranges 09 42.24 01:12:2015
Rishi Apples 10 34.10 03:25:2015
Rishi Apples 09 20.24 03:12:2015
John Grapes 09 78.78 12:13:2014
Charlie EggPlant 15 08.99 01:13:2015
Anne Chicken 09 72.80 04:22:2015
Pepp Chicken 13 94.92 12:25:2014
Pepp Potato 09 65.50 01:25:2015
Pepp Chicken 15 99.22 01:12:2015
Anne PineApple 09 24.24 01:12:2015
Jay Tomato 13 54.00 01:12:2015
John Apples 10 28.00 01:21:2015
Andrew Apples 03 23.00 01:25:2015
Pepp Apples 10 29.92 01:12:2015
Charlie Grapes 10 11.11 02:12:2015
Finn PineApple 08 55.55 10:12:2014
Andrew Apples 11 89.55 01:12:2015
Pepp Oranges 13 14.30 03:16:2015
Rishi Lays 05 96.90 12:25:2014
Pepp EggPlant 10 30.30 02:14:2015
Jay Tomato 13 27.00 02:12:2015
Anne Apples 09 98.88 12:25:2014
Charlie Apples 07 20.85 10:12:2014
John Lays 03 26.18 03:18:2015
Charlie PineApple 03 77.89 01:13:2015
Pepp Potato 10 48.45 02:12:2015
Pepp Lays 05 08.99 01:25:2015
Sajan Potato 15 77.00 01:12:2015
Charlie Apples 18 66.64 04:14:2015
Vijay PineApple 15 30.00 01:21:2015
John Tomato 03 21.20 02:14:2015
Rishi EggPlant 09 19.03 01:25:2015
Jay PineApple 03 31.96 01:13:2015
Rishi Tomato 03 45.50 01:13:2015
Sajan PineApple 07 25.45 12:13:2014
Vijay Potato 09 41.50 02:14:2015
John Plum 09 55.98 01:12:2015
Pepp Bananas 09 22.00 01:21:2015
John Kiwi 05 20.20 02:12:2015
Anne Potato 09 30.14 03:22:2015
Sajan Tomato 10 10.34 03:22:2015
Rishi Grapes 13 60.70 04:20:2015
Sajan Oranges 13 76.76 04:26:2015
John Apples 20 78.74 04:28:2015
Rishi Potato 02 29.99 10:12:2014
Anne Oranges 15 18.00 01:13:2015
Pepp Lays 20 68.62 04:12:2015
Rishi Potato 18 90.96 12:25:2014
Rishi Bananas 15 70.60 04:10:2015
Vijay PineApple 09 17.13 02:12:2015
Charlie Grapes 13 26.60 01:25:2015
Pepp Grapes 18 32.12 03:24:2015
Anne Tomato 10 77.90 01:25:2015
Rishi Chicken 09 90.90 01:25:2015
John Oranges 03 69.69 01:13:2015
Rishi Lays 13 89.99 02:14:2015
Jay EggPlant 07 74.78 04:24:2015
Rishi Lays 20 10.10 02:12:2015
Rishi EggPlant 05 25.00 01:21:2015
Gracy Grapes 09 47.74 10:12:2014
Jay Bananas 07 28.16 03:20:2015
Charlie Tomato 07 92.94 12:25:2014
Sajan Tomato 15 22.55 01:13:2015
John Kiwi 05 64.66 04:16:2015
Ben PineApple 10 55.99 01:12:2015
Bruce Bananas 05 32.20 10:12:2014
Problem description: In this assignment, we will revisit Assignment #1 "th company which tries to run its storehouse perfectly". You will need to modify the program such that the company can make some critical decisions, including processing the received orders from customers and storing coming shipments. This assignment only needs the structs Shipments and Orders e example of the food orders businesses) in the sequence your program places the orders. The prioritization will be based on the time orders were received. If orders (from two or more customers) were received at the same exact moment, then your program should make the decision by comparing the total price of all orders from each customer. The orders from the customer with higher total price should be processed first. You must use a member function of the appropriate corresponding struct to perform the comparison. Print all orders in the sequence they will be processed by the company, i.e. print all orders in chronological order. You will need to save the output into a text file named SequencedOrders.txt Storing coming shipments: Your program should also prioritize the storage process so that the shipments received first, should be stored first. If two shipments were received at the same moment, then your program should make the decision based on the expiration date. You must use a member function of the appropriate corresponding struct to perform the comparison. Print all shipments inStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started