Advertisement
varungurnaney

HSC: Two classes; Cone, Cube

Sep 10th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3.  
  4. class cone
  5. {
  6. float r,h,l;
  7. public:
  8. float area(float r,float l);
  9. float vol(float r,float h);
  10. };
  11.  
  12. class cube
  13. {
  14. float l;
  15. public:
  16. float area(float l);
  17. float vol(float l);
  18. };
  19.  
  20. float cone::area(float r,float l)
  21. {
  22.     float acone = 3.14*r*l;
  23.     cout<<acone<<endl;
  24.     return acone;
  25. }
  26. float cone::vol(float r,float h)
  27. {
  28.     float vcone=0.333*r*r*h*3.14;
  29.     cout<<vcone<<endl;
  30.     return vcone;
  31. }
  32.  
  33. float cube::area(float l)
  34. {
  35.     float acube=6*l*l;
  36.     cout<<acube<<endl;
  37.     return acube;
  38. }
  39.  
  40. float cube::vol(float l)
  41. {
  42.     float vcube=l*l*l;
  43.     cout<<vcube<<endl;
  44.     return vcube;
  45. }
  46.  
  47. void add(float x, float y)
  48. {
  49.     float z = x+y;
  50.     cout<<"The sum is"<<z<<endl;
  51. }
  52.  
  53.  
  54. void main()
  55. {
  56. float r,lco,lcu,h,ra1,rv1,ra2,rv2;
  57. clrscr();
  58. cone co;
  59. cube cu;
  60. cout<<"Enter r,l,h of cone"<<endl;
  61. cin>>r>>lco>>h;
  62. cout<<"Enter l for cube:"<<endl;
  63. cin>>lcu;
  64. ra1=co.area(r,lco);
  65. rv1=co.vol(r,h);
  66. ra2=cu.area(lcu);
  67. rv2=cu.vol(lcu);
  68. add(ra1,ra2);
  69. add(rv1,rv2);
  70. getch();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement