Hi everyone,,,,this problem is from my C class...
The question is below,,,,I finished almost of then,,,but I'm confused about the calculation for the cost..
Can anyone give me the code for this function:
"double costFunc(double x, double y)"???
(The power station problem) 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 7-21). 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:
3. 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.
Here is what I have so far....Thank you very much!!!
----------------------------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <iostream>
using namespace std;
void conversionFunc(double& dFactory, double& wRiver);
double costFunc(double, double);
int main()
{
double wRiver;
double dFactory;
double cUnderWater;
double cOverLand;
cout << "Please enter the width of the river: ";
cin >> wRiver;
cout << endl;
cout << "Please enter the distance of the factory downstream on the other side of the river in miles: ";
cin >> dFactory;
cout << endl;
conversionFunc(dFactory, wRiver);
cout << "Enter the cost of laying the power line under water: ";
cin >> cUnderWater;
cout << endl;
cout << "Enter the cost of laying the power line over land: ";
cin >> cOverLand;
cout << endl;
costFunc(dFactory, wRiver);
return 0;
}
void conversionFunc(double& x, double& y)
{
y /= 5280;
x /= 5280;
cout << "converted miles to feet, dFactory is: " << x
<< ", and wRiver is: " << y << endl;
}
double costFunc(double x, double y)
{
return 0;
}
|