//@cadyp@6@ // // The program will find the optimal radius that minimizes cost for a particular volume. // The program will ask for user to input a minimum and maximum tank volume and the increment. // Results will be displayed in form of a table. // #include #include #include using namespace std; const double PI = 3.14159265358979323846; double totalvolume (double volume); // prototype class Constants { public: double cost_cyl; double cost_cone; }; int main() { cout << "Enter the minimum tank volume (integer, cubic meters) >>> "; double minvol; cin >> minvol; cout << "Enter the maximum tank volume (integer, cubic meters) >>> "; double maxvol; cin >> maxvol; cout << "Enter the tank volume increment (integer, cubic meters) >>> "; double increment; cin >> increment; double volume = 0.0; double finalvolume = 0.0; double new_volume = 0.0; double radius = 0.0; double cost = 3000000.0; cout << "" << endl; cout << " Tank Volume (m^3) Tank radius (m) Minimum Cost ($) " << endl; cout << "---------------------------------------------------------" << endl; for (volume = minvol; volume <= maxvol; volume = volume + increment) { for (radius = 1.0; radius <= 7.0; radius = radius + 0.1) { } } { finalvolume = volume; new_volume = volume; double rndcost = ((int)(cost*0.001+0.5))*1000.0; cout << " " << finalvolume << " " << new_radius << " " << rndcost << endl; return 0; } // // Calculate and displays the optimal radius where the cost is minimized; // and that displays the cost at this radius. // double totalvolume (double volume) { Constants tank; //input - tank constants double cone_cost; //input - cost of the cone portion of the tank double cyl_cost; //input - cost of the cylinder portion of the tank // Get data on the tank tank.cost_cyl = 300; tank.cost_cone = 400; cout << "Enter the tank volume (cubic meters) >>> "; double volume; cin >> volume; double radius = 0.0; double new_radius = 0.0; double cost = 3000000.0; for (radius = 1.0; radius <= 7.0; radius = radius + 0.1) { // Calculate the cost of the tank and height of cylinder and cone double height_cyl = (volume - (PI*radius*radius*radius) / 3.0) / (PI*radius*radius); double height_cone = radius; double SA_cone = PI * radius * sqrt(radius*radius + height_cone*height_cone); if (SA_cone > 100) cone_cost = SA_cone * tank.cost_cone - 0.2*tank.cost_cone*(SA_cone-100.0); else cone_cost = SA_cone * tank.cost_cone; double SA_cyl = PI*radius*radius + 2.0*PI*radius*height_cyl; if (SA_cyl > 200) cyl_cost = SA_cyl*tank.cost_cyl - 0.1*tank.cost_cyl*(SA_cyl-200.0); else cyl_cost = SA_cyl*tank.cost_cyl; double total_cost = cyl_cost + cone_cost; if (total_cost < cost) { cost = total_cost; new_radius = radius; } return ans; } Output code double rndcost = ((int)(cost*0.001+0.5))*1000.0; cout << "" << finalvolume << "" << new_radius << "" << rndcost << endl;