/*This
code was written by A. El-Gadi of Tripoli University for educational
purposes. It illustrates the concept of data hiding and complexity hiding. For any
questions and discussion
use the comment section below.*/
#include <iostream>
using namespace std;
class Box{/* A box is assumed to be a rectangular cuboid. The box is also assumed to be of uniform thickness which includes the cover. Please keep in mind that this example is hypothetical and bears no affinity to the reality of determining box characteristics whatsoever.*/
private:
double st;//Stiffness
double den;//Density: 7.82 steel/0.55 wood/0.7 cardboard
int matid;//Material id: (1) cardboard (2) wood (3) steel
double wd,dp,ht,tk;//width, depth, height, thickness
double outervolume(){return wd*dp*ht;}
bool impossiblebox(double w,double d,double h,double t){
bool truthvalue;
truthvalue=w>=0&&d>=0&&h>=0;
truthvalue=truthvalue&&w>2*t&&d>2*t&&h>2*t;
return !truthvalue;
}
public:
Box():st(0), den(0), matid(0), wd(0), dp(0),ht(0){}
Box(int m,double w,double d,double h,double t){
if(!impossiblebox(w,d,h,t)){
matid=m; wd=w; dp=d; ht=h; tk=t;
switch(m)
{
case 1: st=0.5;den=1; break;
case 2: st=1.5;den=0.7; break;
case 3: st=2.9;den=0.1;
}
}
}
double capacity(){return (wd-2*tk)*(dp-2*tk)*(ht-2*tk);}
double tare(){return (outervolume()-capacity())*den;}//The weight of an empty box is called: tare
double maxLoad(){return st*tk*den*1.4;}
};
int main(){
Box b1(2,100,50,40,3);
Box b2(2,100,50,40,70);
cout << b1.maxLoad()<<' ';
cout << b2.maxLoad();
return 0;
}
using namespace std;
class Box{/* A box is assumed to be a rectangular cuboid. The box is also assumed to be of uniform thickness which includes the cover. Please keep in mind that this example is hypothetical and bears no affinity to the reality of determining box characteristics whatsoever.*/
private:
double st;//Stiffness
double den;//Density: 7.82 steel/0.55 wood/0.7 cardboard
int matid;//Material id: (1) cardboard (2) wood (3) steel
double wd,dp,ht,tk;//width, depth, height, thickness
double outervolume(){return wd*dp*ht;}
bool impossiblebox(double w,double d,double h,double t){
bool truthvalue;
truthvalue=w>=0&&d>=0&&h>=0;
truthvalue=truthvalue&&w>2*t&&d>2*t&&h>2*t;
return !truthvalue;
}
public:
Box():st(0), den(0), matid(0), wd(0), dp(0),ht(0){}
Box(int m,double w,double d,double h,double t){
if(!impossiblebox(w,d,h,t)){
matid=m; wd=w; dp=d; ht=h; tk=t;
switch(m)
{
case 1: st=0.5;den=1; break;
case 2: st=1.5;den=0.7; break;
case 3: st=2.9;den=0.1;
}
}
}
double capacity(){return (wd-2*tk)*(dp-2*tk)*(ht-2*tk);}
double tare(){return (outervolume()-capacity())*den;}//The weight of an empty box is called: tare
double maxLoad(){return st*tk*den*1.4;}
};
int main(){
Box b1(2,100,50,40,3);
Box b2(2,100,50,40,70);
cout << b1.maxLoad()<<' ';
cout << b2.maxLoad();
return 0;
}
No comments:
Post a Comment