Class and Sub Class

I am having trouble with the code i have enclosed. The sub class beamcalc does not takes the values assigned in the elment class. These values are needed for the calculations :(.

I have been stuck on this for hours, any help would be appreicated.









#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <istream>

using namespace std;

// design factors
double Ym = 1.3; // partial material
double Yd = 1.35; // dead load
double Yl = 1.5; // live load





class element {

protected:
double Fmk;
double Ft0k;
double Ft90k;
double Fc0k;
double Fc90k;
double Fvk;
double depth;
double width;
double length;
double secmoment;
double strength;
double distjoist;

double liveload;
double deadload;
double totaldesignload;
double maxmoment;
double bendingstress;
double designbending;
double Vd;
double designshear;
double shearstress;

public:

element()
{}

element(float Fmk1, float Ft0k1, float Ft90k1, float Fc0k1, float Fc90k1, float Fvk1, float depth1, float width1, float length1, float secmoment1, float strength1, float distjoist1, float liveload1, float deadload1, float totaldesignload1, float maxmoment1, float bendingstress1, float designbending1, float Vd1, float designshear1,float shearstress1)
:Fmk(Fmk1)
,Ft0k(Ft0k1)
,Ft90k(Ft90k1)
,Fc0k(Fc0k1)
,Fc90k(Fc90k1)
,Fvk(Fvk1)
,depth(depth1)
,width(width1)
,length(length1)
,secmoment(secmoment1)
,strength(strength1)
,distjoist(distjoist1)
,liveload(liveload1)
,deadload(deadload1)
,totaldesignload(totaldesignload1)
,maxmoment(maxmoment1)
,bendingstress(bendingstress1)
,designbending(designbending1)
,Vd(Vd1)
,designshear(designshear1)
,shearstress(shearstress1)
{}


void datainput();
void secondmomentarea();
void timbercharacteristics();

};


void element::datainput()
{
cout << "all values must be in mm and N"<<endl;
cout<<"depth"<<endl;
cin >> depth;
cout <<"width"<<endl;
cin >> width;
cout <<"length"<< endl;
cin >> length;
cout<<"distance between joist"<<endl;
cin>>distjoist;
}


void element::secondmomentarea()
{
secmoment=(width*(depth*depth*depth))/12;
cout << "2nd Moment Area I = " << secmoment << "mm^4" <<endl;
}


void element::timbercharacteristics()
{
cout<<"enter strength group "<<endl;
cin>>strength;
if (strength==14)
{
Fmk = 14.0;
Ft0k = 8.0;
Ft90k = 0.4;
Fc0k = 16.0;
Fc90k = 2.0;
Fvk = 1.7;
}
else if (strength==16)
{
Fmk = 16.0;
Ft0k = 10.0;
Ft90k = 0.5;
Fc0k = 17.0;
Fc90k = 2.2;
Fvk = 1.8;
}
else if (strength==18)
{
Fmk = 18.0;
Ft0k = 11.0;
Ft90k = 0.5;
Fc0k = 18.0;
Fc90k = 2.2;
Fvk = 2.0;
}
else if (strength==20)
{
Fmk = 20.0;
Ft0k = 12.0;
Ft90k = 0.5;
Fc0k = 19.0;
Fc90k = 2.3;
Fvk = 2.2;
}
cout << "Fmk= "<<Fmk<<endl;
cout << "Ft0k = "<<Ft0k<<endl;
cout << "Ft90k = "<<Ft90k<<endl;
cout << "Fc0k = "<<Fc0k<<endl;
cout << "Fc90k = "<<Fc90k<<endl;
cout << "Fvk = "<<Fvk<<endl;


return ;
}


class beamcalc : public element{


public:

beamcalc()
{}

beamcalc(float Fmk1,float Ft0k1,float Ft90k1,float Fc0k1,float Fc90k1,float Fvk1,float depth1,float width1,float length1,float secmoment1,float strength1,float distjoist1,float liveload1,float deadload1,float totaldesignload1,float maxmoment1,float bendingstress1,float designbending1,float Vd1,float designshear1,float shearstress1)
:element(Fmk1,Ft0k1,Ft90k1,Fc0k1,Fc90k1,Fvk1,depth1,width1,length1,secmoment1,strength1,distjoist1,liveload1,deadload1,totaldesignload1,maxmoment1,bendingstress1,designbending1,Vd1,designshear1,shearstress1)
{}





void loadings();
void totalload();
void calculations();



};


void beamcalc::loadings(){
cout << "Enter total live load in N/mm^2 : ";
cin >> liveload;
cout<<"Enter total dead load in N/mm^2 : ";
cin >> deadload;
};

void beamcalc::totalload(){
totaldesignload= (liveload*Yl)+(deadload*Yd);
cout << "Total design loading = "<<totaldesignload<<endl;
};

void beamcalc::calculations(){

maxmoment=(totaldesignload*length)/8;
cout << "maximum bending moment = "<<maxmoment<<endl;

bendingstress=(maxmoment*(depth/2))/secmoment;
cout << "Total bending stress in beam = "<<bendingstress<<endl;

designbending=(1*1.1*0.8*Fmk)/Ym;
cout << "Total design bending moment = "<<designbending<<endl;

if (designbending<bendingstress)
{
cout << "beam not ok, try choosing a deeper or stronger beam"<<endl;
}
else if (designbending>=bendingstress)
{
cout << "beam bending ok"<<endl;
}
else
{
cout<<"Problem with calculations, check entries"<<endl;
}



Vd=totaldesignload*distjoist*length;


shearstress=(3*Vd)/(2*depth*width);
cout<<"maximum shear stress = "<<shearstress<<endl;

designshear=(Fvk*0.8*1.1)/1.3;
cout<<"Design shear strength = "<<designshear<<endl;

if (shearstress<designshear)
{
cout<<"Beam ok in shear"<<endl;
}
else if (shearstress>=designshear)
{
cout<<"Beam not ok in shear, choose different beam"<<endl;
}









}


int main(){
element myElement;
myElement.timbercharacteristics();
myElement.datainput();
myElement.secondmomentarea();

beamcalc myBeamcalc;
myBeamcalc.loadings();
myBeamcalc.totalload();
myBeamcalc.calculations();


return 0;
}
Last edited on
I have highlighted the problem areas in bold
What do you mean by "does not take the values", exactly?
You have two different objects - an element and a beamcalc.

You're calling three methods on the element, and then creating a whole new object and calling three different methods on that.

Just create one beamcalc object and call all six methods on that.

Jim
Also, you're just using the default constructor (with no parameters), so your initialization lists aren't being used at all.
Topic archived. No new replies allowed.