Code:
#include <iostream>
#include <string>
#include <cmath>
#define PI 3.141592654
using namespace std;
class Column
{
public:
Column(double l,double h,double w,double e, double i);
Column(double l, double r, double e, double i);
void print1() const;
void print2() const;
double get_length();
double get_elasticity();
double get_radius();
double get_height();
double get_width();
double get_moment_inertia();
double calc_gyr_circ();
double calc_gyr_rec();
double calc_rec_area();
double calc_circ_area();
private:
double len;
double rad;
double hei;
double wid;
double el;
double inertia;
double rgyr_rec;
double rgyr_circ;
double factor;
double area1;
double area2;
};
Column::Column(double l,double h,double w,double e, double i)
{
len = l;
hei = h;
wid = w;
el = e;
inertia = i;
}
Column::Column(double l, double r, double e, double i)
{
len = l;
rad = r;
el = e;
inertia = i;
}
void Column::print1() const
{
cout<<"The following is the data for the Column:"<<endl;
cout<<"Length = "<<len<<" mm"<<endl;
cout<<"Width = "<<wid<<" mm"<<endl;
cout<<"Heigth = "<<hei<<" mm"<<endl;
cout<<"Moment of Inertia = "<<inertia<<" m^4"<<endl;
cout<<"Cross-Sectional Area = "<<area1<<" m^2"<<endl;
cout<<"Radius of Gyration = "<<rgyr_rec<<" m"<<endl;
cout<<"Modulus of Elasticity = "<<el<<" GPa"<<endl;
}
void Column::print2() const
{
cout<<"The following is the data for the Column:"<<endl;
cout<<"Length = "<<len<<" mm"<<endl;
cout<<"Radius = "<<rad<<" mm"<<endl;
cout<<"Cross-Sectional Area = "<<area2<<" m^2"<<endl;
cout<<"Radius of Gyration = "<<rgyr_circ<<" m"<<endl;
cout<<"Moment of Inertia = "<<inertia<<" mm^4"<<endl;
cout<<"Modulus of Elasticity = "<<el<<" GPa"<<endl;
}
double Column::get_length()
{
return len;
}
double Column::get_width()
{
return wid;
}
double Column::get_radius()
{
return rad;
}
double Column::get_height()
{
return hei;
}
double Column::get_moment_inertia()
{
return inertia;
}
double Column::get_elasticity()
{
return el;
}
double Column::calc_rec_area()
{
area1 = (wid/1000) * (hei/1000);
return area1;
}
double Column::calc_circ_area()
{
area2 = PI * pow((rad/1000),2);
return area2;
}
double Column::calc_gyr_rec()
{
rgyr_rec = sqrt((inertia / area1));
return rgyr_rec;
}
double Column::calc_gyr_circ()
{
rgyr_circ = sqrt((inertia / area2));
return rgyr_circ;
}
int main()
{
double l,h,r,w,e,i,g,a,K;
string choice;
cout<<" Would You Like to Analyse a Beam or a Column ?"<<endl;
cout<<"\t(Enter 1 for Beam, 2 for Column)"<<endl;
getline(cin,choice);
if (choice == "1")
{
cout<<"Not Done Yet"<<endl;
}
else if (choice == "2")
{
string answer, reply, result;
cout<<"Does the Beam Have a Circular x-section or a Rectangular x-section ?"<<endl;
cout<<"\t (Enter 'a' for Circular, 'b' for Rectangular)"<<endl;
getline(cin,answer);
if (answer == "a" || answer == "A")
{
cout<<"Enter the Length of the beam (mm): ";
cin>>l;
cout<<"Enter the Radius of the beam (mm): ";
cin>>r;
cout<<"Here are Your Choices for the End Conditions of The Column:"<<endl;
cout<<"\t(1) Free - Fixed"<<endl<<"\t(2) Pinned - Pinned"<<endl<<"\t(3) Fixed - Pinned"<<endl;
cout<<"\t(4) Fixed - Fixed"<<endl;
cout<<"Choose the Corresponding Number for the Condition Used:"<<endl;
getline(cin,result);
if (result == "1")
{
K = 2;
}
else if (result == "2")
{
K = 1;
}
else if (result == "3")
{
K = 0.7;
}
else if (result == "4")
{
K = 0.5;
}
else
{
cout<<"You Have Not Entered a Corresponding Number Indicated."<<endl;
return 0;
}
i = (PI/4)*pow((r/1000),4);
cout<<"Here is a List of the Material Types that are Available:"<<endl;
cout<<"\t(1) Steel"<<endl<<"\t(2) Aluminum"<<endl<<"\t(3) Brass"<<endl;
cout<<"Choose a Material from the List above by Entering the Corresponding Number: ";
getline(cin,reply);
if(reply == "1") e = 200;
else if(reply == "2") e = 70;
else if(reply == "3") e = 105;
else
{
cout<<"You Have Not Entered a Corresponding Number Indicated."<<endl;
return 0;
}
Column circ(l,r,e,i);
a = circ.calc_circ_area();
g = circ.calc_gyr_circ();
circ.print1();
cout<<"From the Data Inputted, the Following Results were Obtained:"<<endl;
double crit_load = (pow(PI,2)*(e * 10e9)*(i))/ (pow(((l /1000)*K),2));
double crit_stress = (pow(PI,2)*(e * 10e9)/ (pow((((l /1000)*K)/g),2))) ;
cout<<"\t Buckling Load = "<<crit_load<<" N"<<endl;
cout<<"\t Buckling Stress = "<<crit_stress * 10e-06<<" MPa"<<endl;
}
else if (answer == "b" || answer == "B")
{
cout<<"Enter the Length of the beam (mm): ";
cin>>l;
cout<<"Enter the width of the beam (mm): ";
cin>>w;
cout<<"Enter the height of the beam (mm): ";
cin>>h;
cout<<"Here are Your Choices for the End Conditions of The Column:"<<endl;
cout<<"\t(1) Free - Fixed"<<endl<<"\t(2) Pinned - Pinned"<<endl<<"\t(3) Fixed - Pinned"<<endl;
cout<<"\t(4) Fixed - Fixed"<<endl;
cout<<"Choose the Corresponding Number for the Condition Used:"<<endl;
getline(cin,result);
if (result == "1")
{
K = 2;
}
else if (result == "2")
{
K = 1;
}
else if (result == "3")
{
K = 0.7;
}
else if (result == "4")
{
K = 0.5;
}
else
{
cout<<"You Have Not Entered a Corresponding Number Indicated."<<endl;
return 0;
}
i = ((w/1000)* pow((h/1000),3)) /12;
cout<<"Here is a List of the Material Types that are Available:"<<endl;
cout<<"\t(1) Steel"<<endl<<"\t(2) Aluminum"<<endl<<"\t(3) Brass"<<endl;
cout<<"Choose a Material from the List above by Entering the Corresponding Number: ";
getline(cin,reply);
if(reply == "1") e = 200;
else if(reply == "2") e = 70;
else if(reply == "3") e = 105;
else
{
cout<<"You Have Not Entered a Corresponding Number Indicated."<<endl;
return 0;
}
Column rec(l,w,h,e,i);
a = rec.calc_rec_area();
g = rec.calc_gyr_rec();
rec.print2();
cout<<"From the Data Inputted, the Following Results were Obtained:"<<endl;
double crit_load = (pow(PI,2)*(e * 10e9)*(i))/ (pow(((l /1000)*K),2));
double crit_stress = (pow(PI,2)*(e * 10e9)/ (pow((((l /1000)*K)/g),2)));
cout<<"\t Buckling Load = "<<crit_load<<" N"<<endl;
cout<<"\t Buckling Stress = "<<crit_stress * 10e-06<<" MPa"<<endl;
}
else
{
cout<<"There is no Choice called "<<answer<<endl;
return 0;
}
}
else
{
cout<<"You Have not Entered a Proper Argument. Please Try Again."<<endl;
return 0;
}
return 0;
}