Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Element {
- public:
- int width;
- double depth;
- int bearingLength;
- double secMmtArea;
- Element() {
- width=0; depth=0.0; bearingLength=0; secMmtArea=0.0;
- }
- // constructor that sets members to passed-in variables
- // using the initialiser list
- Element(int w, double d, int bl, double sma)
- : width(w)
- , depth(d)
- , bearingLength(bl)
- , secMmtArea(sma)
- {
- // i could equally have done this within the function body
- // but the initialiser list is preferred when possible
- // width = w;
- // depth = d;
- // bearingLength = bl;
- // secMmtArea = sma;
- }
- double SecondMomentofArea() {
- secMmtArea=width*depth*depth*depth/12;
- return secMmtArea;
- }
- };
- class Beam : public Element {
- public:
- int span;
- int spanDiff;
- // constructor that will call the base 'Element' class constructor with our
- // parameters and then set the members of this class as well
- Beam(int s, int sd, int w, double d, int bl, double sma)
- : Element(w,d,bl,sma)
- , span(s)
- , spanDiff(sd)
- {
- // again, could have done:
- // span = s;
- // spanDiff = sd;
- // but must use the initialiser list to call the base-class constructor...
- }
- Beam() {
- span=0;spanDiff=0;
- }
- };
- and then later on in your main function:
- Beam beamOne(10,2,50,2,49); // replace numbers with what you actually want to match up with the order they're passed into the beam constructor
Add Comment
Please, Sign In to add comment