Advertisement
AbdRoufBUET

CalculateTheCenterOFFloatation.cpp

Sep 3rd, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. #define N 10
  5.  
  6. void takeOrdinateFromInput(float * ordinate)
  7. {
  8.     for(int i = 0; i < N;i++)
  9.     {
  10.         cout<<"Enter "<<i+1<<"th value : ";
  11.         cin>>ordinate[i];
  12.     }
  13. }
  14. void smValueInitialize(float * sm)
  15. {
  16.     sm[0] = 1;
  17.     sm[1] = 3;
  18.     sm[2] = 3;
  19.     sm[3] = 2;
  20.     sm[4] = 3;
  21.     sm[5] = 3;
  22.     sm[6] = 2;
  23.     sm[7] = 3;
  24.     sm[8] = 3;
  25.     sm[9] = 1;
  26. }
  27.  
  28. float calculateAreaSum(float * ordinate, float * sm)
  29. {
  30.     float area = 0;
  31.     for(int i = 0; i < N; i++)
  32.     {
  33.         area += ordinate[i] * sm[i];
  34.     }
  35.    
  36.     return area;
  37. }
  38.  
  39.  
  40. float calculateTotalArea(float areaSum,double h)
  41. {
  42.     return (3*h*areaSum)/8;
  43. }
  44.  
  45. float calculateMomentSum(float* ordinate, float * sm)
  46. {
  47.     float momentSum = 0;
  48.     float area = 0;
  49.     for(int i = 0; i < N ; i++)
  50.     {
  51.         area = ordinate[i] * sm[i];
  52.         momentSum += area * sm[i];
  53.     }
  54.     return momentSum;
  55. }
  56.  
  57. float calculateCenterOfFloatation(float momentSum,float finalArea,double h)
  58. {
  59.     return (momentSum * h) / finalArea;
  60. }
  61.  
  62. int main()
  63. {
  64.     double h; //common interval
  65.     cout<<"Enter the Value of common interval : ";
  66.     cin>>h;
  67.    
  68.     float * ordinate;
  69.     ordinate = new float[N];
  70.     takeOrdinateFromInput(ordinate);
  71.    
  72.     float * sm;
  73.     sm = new float[N];
  74.     smValueInitialize(sm);
  75.    
  76.     float areaSum = calculateAreaSum(ordinate,sm); // this function calculate the summation of (ordinate * sum)
  77.     float finalArea = calculateTotalArea(areaSum,h); // this function calculate the final area which is formulated by Area = (3*h*areaSum) / 8
  78.    
  79.     float momentSum = calculateMomentSum(ordinate,sm); // this function calculate the moment of sum
  80.     float centerOfFloatation = calculateCenterOfFloatation(momentSum,finalArea,h); // calculate centerOfFloatation
  81.    
  82.     cout<<"\n\nTotal Area : "<<finalArea<<" unit^2"<<endl;
  83.     cout<<"\nCenter of Floatation : "<<centerOfFloatation<<endl;
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement