Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

let me start by saying this program needs to be completed in C language. Basically this program needs to use a 2d array system to

let me start by saying this program needs to be completed in C language. Basically this program needs to use a 2d array system to build a pointer system to ships using input verrification of numbers. This also need to allow ships to be swapped to be removed from the "fleet" however these ships must be at the end of the convoy to be removed. my general Idea is to build a struct for a ship, use a main array to keep track of the fleet, usa while loop to cycle though the input data from the file and use for loops inside of those to call different functions from within the for loops to do specifically what i need them to do. for example (in pseudo code)

while(file has input data to read){

if( input == 1){

createShip();

} else if (input == -1){

Return Exit Program

} else if (input == 0){

removeShip()

}

}

and so on and so forth.

The input is also read in from an input file read in when running the program not on compilation.

The Question is as follows.

C program

Shipping

You finally achieved your dream of managing Omazans large convoy of ships; its so futuristic its next gen shipping. These ships carry good across the globe. Ships will send in requests to join and leave your convoy, and traders will query the contents of the convoy (either the goods on ships and potentially the ids of said ships). Your job is to write program on C which stores all this information and services the traders strange inquiries. As an example you could have the following set of ships,

Ship 3 being the first ship in the convoy. To prevent nautical accidents from happening, you only allow ships to leave when they are the last ship in the convoy. If ship 3 requests to leave (note its not the last ship in the convoy), it wont be able to immediately. For this reason, when Ship 3 requests to leave it will swap positions with ship 4, and then depart from the convoy. A trader does not know the ids of the ships, so they might request the id of a ship at a location in the convoy. Alternatively, a trader may request the name of an item in some particular container of a specified ship (by location starting index at 1). Suppose we have the original convoy of ships 3, 5, and 4. Imagine a trader asks what the 1stships 4thgood is. The 1stship has Ship ID 3. The 4th good is Grain. For this reason, Grain would be reported to the trader. If a trader asks for a ship or container not in the convoy, you should report that the ship-container request is not valid.

Input Specification

Each line of input describes either an event or contains the integer -1. If a ship wishes to leave, the event begins with the integer 0 (zero). Following the integer 0, the id of the ship (1 indexed) will be given. The id given will be a valid ship in the convoy. If a ship wishes to join the convoy, the event begins with the integer 1 (one). Following the integer 1, a positive integer, n, representing the number of containers on the ship will be given. Following n will be n (n 10,000) space separated container descriptions. Each container description will be composed of two values a positive integer k (k 100) representing the number of alphanumeric characters in the containers name and a string composed of only k alphanumeric characters.

If a trader requests the id of a ship in some position of the Convoy, the event begins with the integer 2 (two). Following the integer 2, the position of the ship in the convoy will be given. You will need to output the id for such a request. If a trader requests the contents of some container, the event begins with the integer 3 (three). Following the integer 3, the position of the ship in the convoy will be given. Following the ship position will be an integer representing the container position requested. If the request in the input is just the value -1 then the program should exit with a successful return code.

Output Specification

For each trader event (type 2 and type 3) you will need to output a line with some value. In type 2 you will output the id of the ship at the given position. If the ship position is invalid output a -1 instead. In type 3 yowl output the name of the contents of a container at the given position. If the ship/container position is invalid output a -1 instead.

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

Input Output Example Output AnotherShip Input 1 1 3 Dog 1 2 5 AShip 11 AnotherShip 1 4 5 Cocoa 5 Sugar 5 Sugar 5 Grain 0 1 3 2 2 1 2 4 Corn 6 Carrot 2 1 4 2 Corn Grain 2 3 1 6 3 Car 3 Car 3 Car 3 Car 3 Car 3 Car 0 2 3 3 1 3 1 4 3 4 1 1 1 3 DOG 1 1 3 CAT 1 5 1 A 1 B1 C1 D 1 E 3 1 1 3 3 1 3 3 5 3 1 5 0 2 DOG Input Output Example Output AnotherShip Input 1 1 3 Dog 1 2 5 AShip 11 AnotherShip 1 4 5 Cocoa 5 Sugar 5 Sugar 5 Grain 0 1 3 2 2 1 2 4 Corn 6 Carrot 2 1 4 2 Corn Grain 2 3 1 6 3 Car 3 Car 3 Car 3 Car 3 Car 3 Car 0 2 3 3 1 3 1 4 3 4 1 1 1 3 DOG 1 1 3 CAT 1 5 1 A 1 B1 C1 D 1 E 3 1 1 3 3 1 3 3 5 3 1 5 0 2 DOG

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago