9.5k views
1 vote
Give additional practice with dynamic memory in C. Give practice with Queues in C.

Story
The ship arrived back at the harbor (mostly) in one piece. You have already walked through the ship and have noted the problems with the ship. You don't have the time (or parts) to repair the ship, so you will rely on a third party group to make the ship seaworthy again.
You fear that the repair crew will overcharge you. For this reason you want to write a program that will determine an estimate as to how much money the repair will cost. You are certain that they won't look for problems. The repair crew maintains a list of broken components that need to be fixed. The list begins empty, because they don't look for the problems directly. The repair crew will try to tum the ship on, and while some component is still broken, the repair crew will look for the most obvious component that is broken and add that component to the end of the list of broken components to fix
Sometimes when a component is fixed it will reveal additional components that need to be fixed. Those revealed components will be added to the end of the list of components to fix assuming that they are still broken in the order they are revealed.
To fix a component a part will be required. If the part is available the repair crew will expend the part and the component will be fixed. If the required part is not available, then the repair crew will place an order for the part from some distribution center, but to charge you extra they will order an additional part from the distribution center claiming that it can save you money in the long run. For each part type you know the additional part type that will be ordered and the cost of order said parts. Since it takes a little bit of time to get the part once it has been ordered, the crew will place the component at the end of the list of components to fix. The good news is that by the time the next component in the list of components to fix is examined the 2 parts ordered will have arrived
You want to know the sum of all the costs of all the parts ordered based on the repair crews repair procedure.
Problem
Given a list of parts pairs and their cost, the components that are broken in order of their obviousness, and the components that are revealed when a component is fixed. Determine the amount of money you will have to pay to repair the ship.

User Jtlim
by
8.6k points

1 Answer

3 votes

Final answer:

To estimate ship repair costs, a mathematical model that simulates the queue of repairs is created using dynamic memory in C, incorporating cost estimates for parts required for the repair process.

Step-by-step explanation:

Estimating Ship Repair Costs

To estimate the repair costs for the ship, we will employ a mathematical model to simulate the queue of repair tasks and the associated costs of parts required. We will use dynamic memory in C to manage a queue that represents the sequence of repair jobs as they are discovered and processed. As repairs commence, newly revealed issues are added to the queue, and associated parts are either used from stock or ordered with an upcharge, affecting the total cost. The following steps should be taken:

  1. Identify all the broken components and their order of repair.
  2. Define the parts pairs, their individual costs, and the additional part type that would be ordered if a part is not available.
  3. Implement a queue structure in C using dynamic memory to represent the repair list.
  4. Determine cost estimation by simulating the repair process, taking into account the availability of spare parts and the need for ordering additional ones.

This process not only involves building a software simulation of the queue management for repairs but also incorporates mathematical strategies for estimating costs, providing an intersection of technology and mathematics.

User Gavin Mogan
by
8.3k points