Guest User

Untitled

a guest
Apr 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. class Element {
  2.     public:
  3.         int width;
  4.         double depth;
  5.         int bearingLength;
  6.         double secMmtArea;
  7.  
  8.     Element() {
  9.         width=0; depth=0.0; bearingLength=0; secMmtArea=0.0;
  10.     }
  11.  
  12.     // constructor that sets members to passed-in variables
  13.     // using the initialiser list
  14.     Element(int w, double d, int bl, double sma)
  15.     : width(w)
  16.     , depth(d)
  17.     , bearingLength(bl)
  18.     , secMmtArea(sma)
  19.     {
  20.         // i could equally have done this within the function body
  21.         // but the initialiser list is preferred when possible
  22.         // width = w;
  23.         // depth = d;
  24.         // bearingLength = bl;
  25.         // secMmtArea = sma;
  26.     }
  27.        
  28.     double SecondMomentofArea() {
  29.         secMmtArea=width*depth*depth*depth/12;
  30.         return secMmtArea;
  31.     }
  32. };
  33.  
  34. class Beam : public Element {
  35.     public:
  36.         int span;
  37.         int spanDiff;
  38.  
  39.     // constructor that will call the base 'Element' class constructor with our
  40.     // parameters and then set the members of this class as well
  41.     Beam(int s, int sd, int w, double d, int bl, double sma)
  42.     : Element(w,d,bl,sma)
  43.     , span(s)
  44.     , spanDiff(sd)
  45.     {
  46.         // again, could have done:
  47.         // span = s;
  48.         // spanDiff = sd;
  49.         // but must use the initialiser list to call the base-class constructor...
  50.  
  51.     }
  52.  
  53.     Beam() {
  54.         span=0;spanDiff=0;
  55.     }
  56. };
  57.  
  58. and then later on in your main function:
  59.  
  60. 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