Must be C++, please read carefully. A power station is on one side of a river th
ID: 668350 • Letter: M
Question
Must be C++, please read carefully.
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 (see Figure here> http://postimg.org/image/op81qd5of/ ) 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.
Write a program that prompts the user to enter:
a. The width of the river
b. The distance of the factory downstream on the other side of the river
c. The cost of laying the power line under water
d. The cost of laying the power line over land
The program then outputs the length of the power line that should run under water and the length that should run over land so the cost of constructing the power line is at the minimum. The program should also output the total cost of constructing the power line.
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
double wR,fd,uW,oL;
cout<<"enter width of the river:";
cin>>wR;
cout<<"enter the distance of the factory downstream on the other side of the river:";
cin>>fd;
cout<<"enter the cost of laying the power line under water:";
cin>>uW;
cout<<"enter the cost of laying the power line over land:";
cin>>oL;
double fL=0.5,fixedLand=8;
double fixedTotalCost=0.5*uW+oL*8;
double underWater,OnLand;
double TotalCost=((wR*uW)+(oL*fd)),finalCost;
if(TotalCost<=fixedTotalCost){
underWater=wR;
> finalCost=TotalCost;
}else{
underWater=fL;
> finalCost=TotalCost;
}
cout<<"length power lines of river:"<<underWater<<"miles ";
cout<<"length of power lines on land:"<<OnLand<<"miles ";
cout<<"Total Cost:$"<<TotalCost<<" ";
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.