Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define N 10
- void takeOrdinateFromInput(float * ordinate)
- {
- for(int i = 0; i < N;i++)
- {
- cout<<"Enter "<<i+1<<"th value : ";
- cin>>ordinate[i];
- }
- }
- void smValueInitialize(float * sm)
- {
- sm[0] = 1;
- sm[1] = 3;
- sm[2] = 3;
- sm[3] = 2;
- sm[4] = 3;
- sm[5] = 3;
- sm[6] = 2;
- sm[7] = 3;
- sm[8] = 3;
- sm[9] = 1;
- }
- float calculateAreaSum(float * ordinate, float * sm)
- {
- float area = 0;
- for(int i = 0; i < N; i++)
- {
- area += ordinate[i] * sm[i];
- }
- return area;
- }
- float calculateTotalArea(float areaSum,double h)
- {
- return (3*h*areaSum)/8;
- }
- float calculateMomentSum(float* ordinate, float * sm)
- {
- float momentSum = 0;
- float area = 0;
- for(int i = 0; i < N ; i++)
- {
- area = ordinate[i] * sm[i];
- momentSum += area * sm[i];
- }
- return momentSum;
- }
- float calculateCenterOfFloatation(float momentSum,float finalArea,double h)
- {
- return (momentSum * h) / finalArea;
- }
- int main()
- {
- double h; //common interval
- cout<<"Enter the Value of common interval : ";
- cin>>h;
- float * ordinate;
- ordinate = new float[N];
- takeOrdinateFromInput(ordinate);
- float * sm;
- sm = new float[N];
- smValueInitialize(sm);
- float areaSum = calculateAreaSum(ordinate,sm); // this function calculate the summation of (ordinate * sum)
- float finalArea = calculateTotalArea(areaSum,h); // this function calculate the final area which is formulated by Area = (3*h*areaSum) / 8
- float momentSum = calculateMomentSum(ordinate,sm); // this function calculate the moment of sum
- float centerOfFloatation = calculateCenterOfFloatation(momentSum,finalArea,h); // calculate centerOfFloatation
- cout<<"\n\nTotal Area : "<<finalArea<<" unit^2"<<endl;
- cout<<"\nCenter of Floatation : "<<centerOfFloatation<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement