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

Assignment: The power station problem. Task: A power station is on one side of a

ID: 3857107 • Letter: A

Question

Assignment:

The power station problem.

Task:

A power station is on one side of a river that is one-half mile wide, and a factory is eight miles downstream on the other side of the river. It costs $7 per foot to run power lines over land and $9 per foot to run them under water. Your objective is to determine the most economical path to lay the power line. That is, determine how long the power line should run under water and how long it should run over land to achieve the minimum total cost of laying the power line.

Objectives:

Creating abstract code.

Creating code that is easier to read and modify/maintain.

Using functions.

Using constants.

Formatting output.

Using the modulus operator.

Specification:

Write a program that prompts the user to enter:

The distance of the factory downstream on the other side of the river.

The width of the river.

The cost of laying the power line over land.

The cost of laying the power line under water.

The program then determines and outputs the length of the power line that should run under water and the length that should run over land so that the cost of constructing the power line is at the minimum. The program should also output the total cost of constructing the power line.

You can make the following assumptions:

Move down the river in ¼ mile (1320’) increments when determining the cost of laying the cable.

The power station and the factory are right next to the river.

You can disregard the z axis (the depth of the cable) when determining the cost.

Requirements:

Your code should:

Use functions whenever possible.

Use ‘constants’ when warranted.

Cable length should be displayed in miles to 4 decimal places.

Dollar amounts should be preceded by a dollar sign (‘$’) to 2 decimal places.

Output:

Your output shall:

List the cable length going over land and its cost with an appropriately written prompt that identifies what the length and cost represents.

List the cable length going across the river and its cost with an appropriately written prompt that identifies what the length and cost represents.

List the overall cost to lay the cable with an appropriately written prompt that identifies what the cost represents.

The execution of your program should be exactly as the output below:

Enter the distance downstream to the factory in miles: 8

Enter the width of the river in miles: .5

Enter the dollar cost per foot to run power over land: 7

Enter the dollar cost per foot to run power under water: 9

The most cost effective solution is:

Lay power line across land for 7.2500 miles at a cost of $267960.00.

Lay power line under water for 0.9015 miles at a cost of $42833.95.

The total cost = $310793.95.

Explanation / Answer

//Header file section

#include
#include

using namespace std;

//Start main

int main( )

{

      //Declare variables

      double w;    //let width of river=w

      double x;     //let distance of factory=x

      double y;    //let cost of under water=y

      double z;     //let cost of over land=z

      double i = 0.0, distance, totalCost;

      double widthMin = 0, DistanceMin = 0, minCost;


     //Read the width of the river from user

      cout << " Enter the width of the river=";

      cin >> w;

      //Read the factory distance from user

      cout << " Enter distance of the factory downstream=";

      cin >> x;


      //Read cost of power line under water

      cout<<" Enter the cost of laying the power line under water=";

      cin >> y;


      //Read cost of power line over land

      cout<<" Enter the cost of laying the power line over land=";

      cin >> z;


      //Calculate the minimum cost

      minCost = ( w * y ) +( x * z );

      do

      {

            distance = sqrt( (w * w) + ( i*i ));

            //Find the cost with this dimensions

            totalCost = distance * y;

            totalCost += (x - i) * z;

            //    If cost is less than existing minimum cost

           //     then change minimum values of width and distance

            if ( minCost > totalCost )

            {

                  widthMin = distance;

                  DistanceMin = x - i;

                  minCost = totalCost;

            }     

            i += 0.1;

      } while ( i < x );

//Display Result

     cout << " Length of power line under water= "<< widthMin;

     cout<<" Length of power line over land=" << DistanceMin;

     cout<< " Total Cost of constructing the power line="<< minCost;    
    //Pause a system for a while
    system("Pause");

     return 0;

}     //End main

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