General Description: The program that you are writing for this assignment is a s
ID: 3628376 • Letter: G
Question
General Description:
The program that you are writing for this assignment is a software simulation for a harbour.
The harbour has ships coming and going. A ship comes into the harbour with a load on it.
After docking, the ship must be unloaded and then sent on its way. A ship can only dock in
a bay that is at least as large enough to hold it at maximum capacity.
A harbour has a certain number of docking bays that can be used by ships to dock at.
Each docking bay has a maximum load size that it can hold. It also has a time that it takes
to unload a ship of that maximum size.
Your program will read from 2 different ?les. One ?le will contain all the details about the
harbour and its docking bays. The second ?le will contain all the details about the ships
that are going to dock at the harbour.
The scenario:
Each harbour has a ?xed number of docking bays. Each docking bay has a unique ID
number, a maximum size ship it can hold, a time it takes to unload the ship when it is at full
capacity, and a charge per unit it unloads.
Each ship has a unique ID number, a maximum capacity, an actual capacity, and an arrival
time.
When a ship docks it can only be docked into a bay that is equal to or larger than its
maximum capacity. Each ship is processed into a docking bay in the order it arrives but
may need to wait for a docking bay big enough to hold it to become free. In this case, if
there are ships that arrive after it they may be processed before it, if there are free docking
bays that can accommodate the other ship’s maximum capacity.
Your program must process the ships, assigning them to the appropriate docking bay,
unload their cargo, and then move them out of the docking bay. A bay is only free 2 time
units after the last cargo container has been removed from the ship.
You must output the capacity that the harbour is working at, the total amount of money it
collected from unloading the ships and the total number of ships it unloaded.
The ?les for your program:
The harbour ?le will be in the following format:
the ?rst line will contain an integer that tells you how many docking bays the harbour
contains followed by a string which will be the name of the harbour. Each line after that will
contain the information about each docking bay: an integer representing the unique ID, an
integer representing the maximum size ship it can hold, an integer representing how many
time units it takes to unload a ship at full capacity and a double representing the amount of
money charged per unit it unloads.
An example ?le:
3 Aqaba
49789 10000 5200 25.78
6987 148976 12941 15.78
99885 35262 2501 22.98
The ship information ?le will be in the following format:
the ?rst line will contain an integer that tells you how many ships you will process. Each
line after that will contain the information about each ship: an integer representing the
ship’s unique ID, an integer representing the ship’s maximum capacity, an integer
representing actual capacity of the ship and an integer representing the time of arrival.
An example ?le:
4
1234 25000 2400 10
4789 15000 14900 12
698 4750 4400 8
45 8950 5874 11
Structuring your program’s code:
You will need to open the two ?les and read the information from them.
The information from each ?le should be loaded into structures.
Use a structure for each docking bay and another structure to represent each boat.
Arrays and dynamic memory allocation is needed.
I suggest breaking the program into several functions as this will enable you to test your
program function by function.
The output of your program needs to be structured in a manner that is easily readable. You
may want to output it into a table format. The output will be displayed to screen and written
to a ?le. Please ensure that it is easily readable and understandable for the user.
Deliverables:
• needs a well commented C code that you have produced.
needs a description of the testing data and output.
Explanation / Answer
//Reading data from file ship.txt
fship>>s[i].no_ships;
cout<<s[i].no_ships;
while(i<4)
{
fship>>s[i].uid>>s[i].max>>s[i].cap>>s[i].time;
cout<<s[i].uid<<s[i].max<<s[i].cap<<s[i].time ;
cout<<endl;
i++;
}
cout<<endl;
i=0;
cout<<"3 aquaba"<<endl;
//Reading data from harbour.txt
while(i<3)
{
fharbour>>h[i].uid>>h[i].max>>h[i].timeunits>>h[i].price;
cout<<h[i].uid<<h[i].max<<h[i].price<<h[i].timeunits;
cout<<endl;
i++;
}
system("pause");
return 0;
}
Hope this would help you.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.