Posted By

ppbeto94 on 04/28/13


Tagged


Versions (?)

Section Volume


 / Published in: C++
 

The program, receives the dimensions of a drinking glass. The base radius (smallest radius), the top radius (biggest radius), the height of the glass, and a height at which you would like to know how much liquid you are missing in the glass. The problem in coj.uci.cu was called Glass with Whisky... but I can't find it now.

  1. #include <iostream>
  2. #include <iomanip>
  3. #define PI 3.14159265
  4. using namespace std;
  5.  
  6. double R1, R2, H1, H2, V;
  7. double pi = 3.14159;
  8. double volumen (double h, double r){
  9. double vol = (1.0/3.0)*PI*h*(r*r+R1*R1+r*R1);
  10. cout<<"El volumen fue: "<<vol<<endl;
  11. return vol;
  12. }
  13.  
  14. int main()
  15. {
  16. double r_nuevo;
  17. double vGrande, vChico;
  18. cin>>R1>>R2>>H1>>H2;
  19.  
  20. while (R1!=0 && R2!=0 && H1!=0 && H2!=0){
  21.  
  22. r_nuevo = ( H2 + ( H1/(R2-R1) )*R1 ) / (H1/(R2-R1)) ;
  23. vGrande = volumen(H1, R2);
  24. vChico = volumen(H2,r_nuevo);
  25.  
  26. cout << fixed;
  27. cout << setprecision(4) << vGrande-vChico << endl;
  28.  
  29. cin>>R1>>R2>>H1>>H2;
  30.  
  31. }
  32.  
  33.  
  34.  
  35.  
  36. return 0;
  37. }

Report this snippet  

You need to login to post a comment.