Tuesday, 17 September 2013

Simple Data Structure for Tower Crane (Tower only)

// Data Structure for Generic Tower Crane (?)
// Program finds necessary size of concrete base to be poured and overall weight of tower segment.
// Note since the horizontal jib has not yet been accounted for the math to calculate the base weight is currently arbitrary. Once the moment of the crane is available, trigonometric functions can be used to calculate a more accurate size and weight.

#define _USE_MATH_DEFINES
#include<iostream>
#include<cmath>

using namespace std;

struct Rod{
    float diameter;
    float length;
};

struct Segment{
    int sides, segmentSize;
    float length, width;
    
    void CalcDimensions(bool tower){
        //Totally legit maths
        length = length * 2;
        width  = width/2;
        
        if (tower){sides=4;}else{sides=3;};
    }
};

struct Tower{
    int segnum, segheight;
    float height, weight;
    void CalcHeight( ){
        height = segnum * segheight;
    }
    void calcWeight(float diam, float sdiam, float slength){
        double pi = M_PI;
        float vol = (4 * (pi * pow(diam/2, 2) * height)) + (8 * (pi * pow(sdiam/2,2) * slength));
        //Density of steel = 8000kg/m^3
        weight = vol*8000;
    }
        
    
};

struct Base{
//public:
    float weight;
    void CalcBase(float towerheight, int towersides, float roddiam){
        //totally legit math
        float vol = towerheight*towersides*roddiam;
        //density of concrete = 2400 kg/m^3
        weight = vol*2400;
    }
    
    
};


int main(){
    
    Rod longr;
    Rod shortr;
    Segment s;
    Tower t;
    Base b;
    
    cout << "How long is each long rod? (m)" << endl;
    cin >> longr.length;
    cout << "What's the diameter of these rods? (m)" << endl;
    cin >> longr.diameter;
    cout << "How long is each short rod? (m)" << endl;
    cin >> shortr.length;
    cout << "What's the diameter of the short rods? (m)" << endl;
    cin >> shortr.diameter;
    cout << "How many Tower segments have you ordered?" << endl;
    cin >> t.segnum;
    
    s.length = longr.length;
    s.width = shortr.length;
    s.CalcDimensions(true);
    
    t.segheight = s.length;
    t.CalcHeight();
    //Calculate weight of tower
    t.calcWeight(longr.diameter, shortr.diameter, shortr.length);
    //calculuate weight of tower
    b.CalcBase(t.height, s.sides, longr.diameter);
    
    cout << endl << "Your tower is going to be " << t.height << " m tall, and you'll need a base that weighs " << b.weight << " kilograms" << endl;
    
    cout << "Your tower is going to weigh: " << t.weight/1000 << " tonnes." << endl;
    return(0);
    

}