Question

C++ Program Description Unloading Merchandise and Delivery (UMD) is in charge of loading air planes and...

C++ Program

Description
Unloading Merchandise and Delivery (UMD) is in charge of loading air planes and trains from containers that have been unloaded from ships. The material from the dock is stacked (up to 5 containers high) if it to be sent by train. The materials destined to be sent by planes are are unpacked and placed on an assembly line. Each item is labeled either a train number or plane number (which is its destination). Items destined for trains are placed in a stack until it reaches 5 items high, then a new stack is begun behind the original. Items are planes are placed on a long assembly line (there is only 1 assembly line). You can assume 1 worker is loading trains and 1 worker is loading the planes at the same time. The trains (planes) closer to the dock have the smaller train (plane) numbers Each worker requires 2 minutes x train number to move an item from the dock to a train and return. Each worker required 10 minutes x the plane number to move an item from the dock to a plane and return. Given the order that items are unloaded from the ship, your job is write a program to determine the total time it will take to load all the materials.

Input
All input will be from the keyboard. The first line of input will be 4 integers (t,p and nt and np) (0 <= t < 100, 0 <= p < 10,0 <= nt,0 <= np) (each separated by a single space), which represent the total number of trains , the total number of planes and the total number of to be loaded into trains and the total number of items to be loaded into planes. The second line will contain t integers (again separated by a single space) representing the number of items to be loaded to each train. The third line will contain p integers (again separated by a single space) representing the number of items to be loaded to each plane. The fourth line will contain nt representing the destination of each item being sent by a train. The last line will contain np representing the destination of each item being sent by a plane.

Output
Output will be on the screen in 2 lines. The first line contains nt integers each separated by 1 space. The ith integer represents the time the ith train finished loading. The second line contains np integers each separated by 1 space. The ith integer represents the time the ith plane finished loading.

sample Input
3 2 10 5
2 7 1
3 2
2 2 2 1 3 2 2 2 1 2
2 1 1 2 1

corresponding Output
25 36 3
65 50
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ program:

#include <bits/stdc++.h>
using namespace std;

int t, p, nt, np;
vector<int> tCap, pCap, tAns, pAns, tItem, pItem;

void readInput() {
for(int i = 1; i <= t; i++)
cin>>tCap[i];
for(int i = 1; i <= p; i++)
cin>>pCap[i];
for(int i = 1; i <= nt; i++)
cin>>tItem[i];
for(int i = 1; i <= np; i++)
cin>>pItem[i];
}

void solveForTrains() {
int timer = 0;
for(int i = 1; i <= nt; i+=5) {
for(int j = min(i+4,nt); j >= i; j--) {
timer += tItem[j];
tCap[tItem[j]]--;
if(tCap[tItem[j]] == 0)
tAns[tItem[j]] = timer;
timer += tItem[j];
}
}
}

void solveForPlains() {
int timer = 0;
for(int i = 1; i <= np; i++) {
timer += pItem[i]*5;
pCap[pItem[i]]--;
if(pCap[pItem[i]] == 0)
pAns[pItem[i]] = timer;
timer += pItem[i]*5;
}
}

int main() {

cin>>t>>p>>nt>>np;

tCap.resize(t+1); pCap.resize(p+1);
tAns.resize(t+1); pAns.resize(p+1);
tItem.resize(nt+1); pItem.resize(np+1);

readInput();
solveForTrains();
solveForPlains();

for(int i = 1; i <= t; i++)
cout<<tAns[i]<<" ";
cout<<"\n";
for(int i = 1; i <= p; i++)
cout<<pAns[i]<<" ";
cout<<"\n";

}

Output:

Comment down for any queries

Please give a thumb up

D:!1Programming\main bin Debug\main.exe 3 2 10 5 2 7 1 32 2 2 2 1 3 2 2 2 1 2 2 1 1 2 1 25 36 3 65 50 Process returned @ (@xo_execution time : 7.828 s Press any key to continue.

Add a comment
Know the answer?
Add Answer to:
C++ Program Description Unloading Merchandise and Delivery (UMD) is in charge of loading air planes and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Unloading Merchandise and Delivery (UMD) is in charge of loading air planes and trains from containers...

    Unloading Merchandise and Delivery (UMD) is in charge of loading air planes and trains from containers that have been unloaded from ships. The material from the dock is stacked (up to 5 containers high) if it to be sent by train. The materials destined to be sent by planes are are unpacked and placed on an assembly line. Each item is labeled either a train number or plane number (which is its destination). Items destined for trains are placed in...

  • C++ ONLY Please TRAINS DESCRIPTION You are completing a program that allows for several different types...

    C++ ONLY Please TRAINS DESCRIPTION You are completing a program that allows for several different types of passenger trains. One train can hold only cats. Another train can hold only wizards. You are going to create a Wizard class, a Cat class, and a Train class. You are provided the driver, lab2.cpp. The Train class should be a template class where the type of passenger is the template data type. Specifications cat class Attributes: name of cat breed of cat...

  • Write a C++ program that will read in image data from the file "image.txt" and illustrate...

    Write a C++ program that will read in image data from the file "image.txt" and illustrate that image as ASCII art. The Image file will contain several lines, representing horizontal rows in the image, and each line will have several integers in the range 0-255. representing povels, separated by spaces. You should read this image data into a vector vector in Once you've read in the phel data, go through the image and print out each piel in the image...

  • C++ File I/O Create a program that will work for all "infile.txt" of similar structure: The...

    C++ File I/O Create a program that will work for all "infile.txt" of similar structure: The first line will contain two integers. The first integer is the number of elements in array1, and the second integer the number of elements in array2. The second line will contain all the values of array1, and the third line will contain all values of array2. All numbers are separated by a space and all lines separated by a newline character. "infile.txt" has three...

  • This program will provide the user the tools to make up trains from a file of...

    This program will provide the user the tools to make up trains from a file of available cars. The car data will be the reporting identifier, car type, weight (in tons) and length (in feet) for each car. The user can select to make up a train by total weight, total length or car type. The user will be able to display any train’s consist, and will be able to delete a train (returning the cars to the pool of...

  • You need to start doing your CST370 homework, but you don't really feel like it. You...

    You need to start doing your CST370 homework, but you don't really feel like it. You decide to take the longest route from your current location on campus to where you plan to do your homework to procrastinate a bit. You're given a graph representing CSUMB's campus, and your goal is to nd the path with the most stops to your homework destination without visiting any location more than once. Input • The first line contains your current location. •...

  • In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a seri...

    In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a series of characters separated by a single space - The second line contains the number of states as an integer k 2 1; states will be numbered 0,1,..., k -1. The start state is always state O The third line contains a series...

  • In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a seri...

    In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a series of characters separated by a single space - The second line contains the number of states as an integer k 2 1; states will be numbered 0,1,..., k -1. The start state is always state O The third line contains a series...

  • in C++ and comments please for better understanding 3. How Will You Compare? Write a Comparator...

    in C++ and comments please for better understanding 3. How Will You Compare? Write a Comparator class with the following 3 overloaded compare methods: 1. boolean compare(int a, int b): Return true if int a = int b, otherwise return false. 2. boolean compare(string a, string b): Return true if string a = string b, otherwise return false. 3. boolean compare(int[] a, int[] b): Return true if both of the following conditions hold true: O Arrays a and b are...

  • Description An array in C++ is a collection of items stored at contiguous memory locations and...

    Description An array in C++ is a collection of items stored at contiguous memory locations and elements can be accessed randomly using indices of an array. They are used to store similar type of elements as in the data type must be the same for all elements. One advantage of arrays is easy data manipulation and accessibility of elements stored in consecutive locations. The Problem: One teaching assistant of a computer science department in Engineering University got a simple question...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT