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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
#include <iostream>
#include <cmath>
using namespace std;
class calcformulae
{
private:
//vars--------------------------------------------------------------------
double vc,vs,vco,vcy,sac,sas,saco,sacy,l,b,h,ll,bb,hh,r,rr,rrr,rd,hhh,hd,rco,rcc,hco,hcc;
//eqns--------------------------------------------------------------------
void cuboidv(){vc=l*b*h;}
void cuboidsa(){sac=2*hh*(ll+bb);}
void spherev(){vs=(4/3)*(22/7)*r*r*r;}
void spheresa(){sas=4*(22/7)*rr*rr;}
void cylinderv(){vcy=(22/7)*rrr*rrr*hhh;}
void cylindersa(){sacy=2*(22/7)*rd*(rd+hd);}
void conev(){vco=(1/3)*(22/7)*rco*rco*hco;}
void conesa(){saco=(22/7)*rcc*(rcc+sqrt(rcc*rcc+hcc*hcc));}
public:
//setters-------------------------------------------------------------------------
void setCuboidv(double x,double y,double z){l=x;b=y;h=z;}
void setCuboidsa(double xx,double yy,double zz){ll=xx;bb=yy;hh=zz;}
void setSpherev(double w){r=w;}
void setSpheresa(double ww){rr=ww;}
void setCylinderv(double www,double zzz){rrr=www;hhh=zzz;}
void setCylindersa(double wd,double zd){rd=wd;hd=zd;}
void setConev(double wco,double zco){rco=wco;hco=zco;}
void setConesa(double wcc,double zcc){rcc=wcc;hcc=zcc;}
//getters--------------------------------------------------------------------------
double getCuboidv(){return vc;}
double getCuboidsa(){return sac;}
double getSpherev(){return vs;}
double getSpheresa(){return sas;}
double getCylinderv(){return vcy;}
double getCylindersa(){return sacy;}
double getConev(){return vco;}
double getConesa(){return saco;}
};
//implementation code----------------------------------------------------------------------
int main()
{
calcformulae cf;
cout<<"\nVOLUME, SURFACE AREA CALCULATOR";
cout<<"\n-------------------------------\n\n";
cout<<"Calculate:\n\n1)Volume \nOR\n2)Surface area?\n\n";
int selector,shapeselector;
double i,o,p;
cin>>selector;
switch(selector)
{ case 1: case 2:
cout<<"\nOf:\n\n1)Cuboid\n2)Sphere\n3)Cylinder\nOR\n4)Cone?\n\n";
cin>>shapeselector;
switch(shapeselector)
{
case 1:
cout<<"\nEnter length:\n\n";
cin>>i;
cout<<"\nEnter width:\n\n";
cin>>o;
cout<<"\nEnter height:\n\n";
cin>>p;
switch(selector)
{
case 1: cf.setCuboidv(i,o,p); cout<<endl<<cf.getCuboidv(); break;
case 2: cf.getCuboidsa(); cout<<endl<<cf.getCuboidsa(); break;
}
break;
case 2:
cout<<"\nEnter radius:\n\n";
cin>>i;
switch(selector)
{
case 1: cf.setSpherev(i); cout<<endl<<cf.getSpherev(); break;
case 2: cf.setSpheresa(i); cout<<endl<<cf.getSpheresa(); break;
}
break;
case 3: case 4:
cout<<"\nEnter radius:\n\n:";
cin>>i;
cout<<"\nEnter height:\n\n:";
cin>>o;
switch(shapeselector)
{
case 3:
switch(selector)
{
case 1: cf.setCylinderv(i,o); cout<<endl<<cf.getCylinderv(); break;
case 2: cf.setCylindersa(i,o); cout<<endl<<cf.getCylindersa(); break;
}
break;
case 4:
switch(selector)
{
case 1: cf.setConev(i,o); cout<<endl<<cf.getConev(); break;
case 2: cf.setConesa(i,o); cout<<endl<<cf.getConesa(); break;
}
break;
}
default: cout<<"\nERROR\n\n\n";
main();
}
default: cout<<"\nERROR\n\n\n";main();
}
return 0;
}
|