Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Houston, and Chicago. In each warehouse the compary stocks three items. A record

ID: 3729453 • Letter: H

Question

Houston, and Chicago. In each warehouse the compary stocks three items. A record contains the amount of each Item currently in each warehouse. This program assumes that a company has warehouses in 5 cities: New York, Los Angeles, Miami, The record should contain an array of 5 warehouses with the name of each warehouse and an array of the 3 tems with the amount that is currenty in stock in the warehouse. Initially the warehouses are empty. Read in a card containing the three prices of the three items. Then read in cards which may be any one of two types: 1. Shipment cards containing.. S city amt amt2 amt3 This data represents a shipment to a given city of amti of item1, amt2 of tem2, and amt3 of item3. 2. Order cards containing.... O city amt2amt3 This data represents an order in a given city of the respective amounts of the various items. As each shipment card is read in, print it out, update the amounts in that warehouse and then print on the next line: city amtt amt2 amt3 As each order card is read in, print it out. If there is enough in stock at that warehouse of each item, update the amounts. If there is not enough, search the other warehouses for the one which has the most of that particular item, ship the amount needed from one warehouse to the other, printing out x of item y shipped from city1 to city2 city1 amt1 am12 amt3 10% extra is to be charged for any item shipped form one cy to another. enough extra to fill the order for a particular item, print out tnosingle warehouse has Order Unfilled However any shipments of the previous items remain in effect. In either case print out the adjusted... city amt1 amt2 amt3 And if the order if filled print... Price of Order: Price

Explanation / Answer

#include <cstdlib>
#include <iostream>
#include <map>
#include <fstream>
#include <fcntl.h>
#include <sstream>

#define RECORD "record.txt"

using namespace std;
class WareHouse{
public:
    string name;
    int item[3] = {};
};
map<int,string> Name = { {0,"New York"}, {1,"Los Angeles"}, {2,"Miami"},{3,"Houston"},{4,"Chicago"} };
WareHouse record[5];
float Prices[3] = {};

void fill_record(){
    for(int i = 0 ;i < 5; i++){
        record[i].name = Name[i];
    }
}
void show_record(){
    for(int i = 0 ;i < 5; i++){
        cout<<record[i].name<<" "<<record[i].item[0]<<" "<<record[i].item[1]<<" "<<record[i].item[2]<<endl;
    }
}
//Strictly considering the given text file to read prices
void read_price(){
    fstream rd;
    rd.open(RECORD,ios::in);
    char ch;
    while (ch!= '='){//read all characters till = is found
        rd>>ch;
    }rd.get();//ignore $ sign
    rd>>Prices[0];
    ch = ' ';//reset ch value
    while (ch!= '='){
        rd>>ch;
    }rd.get();
    rd>>Prices[1];
    ch = ' ';
    while (ch!= '='){
        rd>>ch;
    }rd.get();
    rd>>Prices[2];
    rd.close();
}

void process_card(){
    fstream rd;
    rd.open(RECORD,ios::in);
    string line;
    getline(rd,line);
    while(getline(rd,line)){
        if( ( line.compare("")!=0 )&&(line.find("End of data")==string::npos) ){/*if there is no data or if it is end of file we ignore*/
            char type;
            stringstream ss;
            ss<<line;
            ss>>type;
            string name;
            ss>>name;
            string tmp;
            int item[3];
            ss>>tmp;
            if( (tmp.find("York")!=string::npos) || (tmp.find("Angeles")!=string::npos) ){/*new york and los angeles have two strings so this logic was kept*/
                name.append(" "+tmp);
                ss>>item[0];
            }else{
                item[0] = stoi(tmp);
            }
            ss>>item[1];
            ss>>item[2];
            if(type=='s'){
                for(int i = 0; i < 5 ;++i){
                    if(record[i].name.find(name)!=string::npos){
                        record[i].item[0] += item[0];
                        record[i].item[1] += item[1];
                        record[i].item[2] += item[2];
                        break;
                    }
                }
            }else if(type == 'o'){
                float cost = 0;
                for(int i = 0; i < 5 ;++i){
                  
                    if(record[i].name.find(name)!=string::npos){
                        for(int column =0 ; column < 3; ++column){/*we have three items to to calculate, navigating through the three items using variable column*/
                            if(item[column] <= record[i].item[column]){/*If we can ship directly*/
                                cost += (Prices[column]*item[column]);
                                record[i].item[column] = record[i].item[column] - item[column];
                            }else{
                                int req = item[column]-record[i].item[column];/*req is the amount of items to be shipped from other cities*/
                                int j;
                                for(j = 0; j < 5; ++j){
                                    if(j==i){/*We don't ship from the same city right!!*/
                                        continue;
                                    }
                                    if (record[j].item[column] >= req) {
                                        cout<<req<<" of "<<"item "<<column+1<<" shipped from "<<record[j].name<<" to "<<record[i].name<<endl<<"and"<<endl;
                                        cost += ( (Prices[column]+(Prices[column]/10))*req );
                                        cost += (Prices[column]*record[i].item[column]);
                                        record[j].item[column] = record[j].item[column] - req;/*After shipping from city in jth position we need to reduce the availability there*/
                                        record[i].item[column] = 0;/*we deliver all the available items from the current city we hence stock becomes 0 here*/
                                        /*cout<<"Now "<<record[i].name<<" "<<record[i].item[0]<<" "<<record[i].item[1]
                                                <<" "<<record[i].item[2]<<endl;
                                        cout<<"And "<<record[j].name<<" "<<record[j].item[0]<<" "<<record[j].item[1]
                                                <<" "<<record[j].item[2]<<endl;*/
                                      
                                        break;
                                    }
                                }
                                if(j>=5){/*Means we didn't find any other city where we can get the extra items*/
                                    cout<<"Order unfilled"<<endl;
                                }
                            }
                        }
                        cout<<record[i].name<<" "<<record[i].item[0]<<" "<<record[i].item[1]<<" "<<record[i].item[2]<<endl;
                        if(cost){/*sometimes non of the orders may get placed hance checking here*/
                            cout<<"Price of Order:"<<cost<<endl;
                        }
                    }
                  
                  
                }
            }
          
        }
    }
}
int main(int argc, char** argv) {
    fill_record();
    //show_record();
    read_price();
    process_card();
    show_record();
  
    return 0;
}

///////////////////////////////input record.txt///////////////////////

/*

Price 1=$2.00 Price 2=$7.00 Price 3=$8.50

s New York 23 14 1
s Miami 25 25 25
s Los Angeles 40 13 17
s Houston 100 30 10
s Chicago 42 23 19
s New York 0 0 15
s Miami 13 17 21
o Los Angeles 15 10 15
o New York 12 24 8
o Houston 75 45 10
o Chicago 20 15 15
o New York 15 0 0
s Los Angeles 10 20 10
s Houston 0 30 40
o New York 15 15 25
o Chicago 75 30 40
s New York 20 15 20
o Houston 10 20 10

End of data

*/

///////////////////////////////////output///////////////////////////////
/*

Los Angeles 25 3 2
Price of Order:227.5
10 of item 2 shipped from Miami to New York
and
New York 11 0 8
Price of Order:267
15 of item 2 shipped from Miami to Houston
and
Houston 25 0 0
Price of Order:560.5
Chicago 22 8 4
Price of Order:272.5
4 of item 1 shipped from Los Angeles to New York
and
New York 0 0 8
Price of Order:30.8
15 of item 1 shipped from Los Angeles to New York
and
15 of item 2 shipped from Los Angeles to New York
and
17 of item 3 shipped from Miami to New York
and
New York 0 0 0
Price of Order:375.45
Order unfilled
22 of item 2 shipped from Houston to Chicago
and
36 of item 3 shipped from Houston to Chicago
and
Chicago 22 0 0
Price of Order:596
12 of item 2 shipped from New York to Houston
and
6 of item 3 shipped from New York to Houston
and
Houston 15 0 0
Price of Order:258.5
New York 20 3 14
Los Angeles 16 8 12
Miami 38 17 29
Houston 15 0 0
Chicago 22 0 0

*/
////////////////////////////end of output///////////////////////////

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote