Problem: Write a program in C++ to find the ship’s displacement in tonnes when floating in salt water at 4 metres draft by taking WPA values from user.


The areas of a ship’s water plane are as follows:
Draft (m)
0
1
2
3
4
Area of WP (m2)
650
660
662
661
660




Code: 
#include <iostream>
#define rho 1.025       //for salt water
using namespace std;

int main(){
    float y0, y1, y2, y3, y4, simp, vol, ton, h;

    cout << "Enter WP area values serially: <enter> ";
    cin >> y0>> y1>> y2>> y3>> y4;

    cout << "Enter draft: ";
    cin >> h;

    h /= 4;

    simp = y0+(4*y1)+(2*y2)+(4*y3)+y4;

    vol = (h*simp)/3;
    ton = rho * vol;

    cout << "The tonne displacement is " << ton;
}

Output: 

Enter WP area values serially: <enter> 650
660
662
661
660
Enter draft: 4
The tonne displacement is 2705.32
Process returned 0 (0x0)   execution time : 14.898 s
Press any key to continue.

أحدث أقدم