رایانشکده *** Computation Hub

رایانشکده *** Computation Hub

محاسبات ریاضی، حل مسئله های برنامه نویسی و پیاده سازی الگوریتم
رایانشکده *** Computation Hub

رایانشکده *** Computation Hub

محاسبات ریاضی، حل مسئله های برنامه نویسی و پیاده سازی الگوریتم

واکاوی لحظه‌به‌لحظه‌ی سقوط آزاد یک جسم در سی پلاس پلاس

به زبان سی‌پلاس‌پلاس برنامه‌ای بنویسید که پیوسته ارتفاعی که از آن یک جسم به سمت زمین سقوط می‌کند را در واحد متر به‌عنوان ورودی از کاربر دریافت می‌کند. آن‌گاه با به‌کارگیری فرمول‌های سقوط آزاد نشان می‌دهد از لحظه‌ی صفر تا لحظه‌ی برخورد جسم به زمین با سپری شدن هر یک ثانیه، مسافت طی‌شده، ارتفاع باقی‌مانده و سرعت لحظه‌ای جسم چه قدر است. شتاب گرانشی را ثابت و برابر با ۹٫۸۰۶۶۵ متر در مجذور ثانیه فرض کنید. هم‌چنین از اصطکاک هوا چشم‌پوشی کنید. در صورتی که کاربر ارتفاع صفر را به‌عنوان ورودی برگزیند خروج از برنامه رخ می‌دهد.

Write a program in C++ which constantly receives the height from which an object falls down as input. Then using the equations for a falling body, it computes the traveled distance, the remaining height and the instantaneous velocity of the object from the beginning until the end in intervals of one second. The gravitational acceleration is considered as a constant which corresponds to 9.80665 m/s2. If the height equals zero, the program is terminated.

 

#include<iostream>

#include<math.h>

using namespace std;

 

int main()

{

                cout << " Distance Traveled & Velocity of a Falling Object \n\n";

                cout << " Programmer: Mohammad Rajabpur \t rajabpur.blogsky.com \n\n";

                cout << ".......................................................\n\n";

                while (true)

                {

                                double h0;

                                cout << " Height = ";

                                cin >> h0;

                               

                                if (h0 == 0)

                                {

                                                cout << " Free fall is impossible!!! \n";

                                                cout << " The program is terminated.";

                                                break;

                                }

                               

                                double g = 9.80665;

                                double time = sqrt(2.0 * h0 / g);

                               

                                for (int t = 0; t < time; t++)

                                {

                                                double d = 0.5 * g * t * t;

                                                double h = h0 - d;

                                                double v = g * t;

                                                cout << endl;

                                                cout << "           Time Elapsed: " << t << " s \n";

                                                cout << "      Distance Traveled: " << d << " m \n";

                                                cout << "       Height Remaining: " << h << " m \n";

                                                cout << " Instantaneous Velocity: " << v << " m/s \n" ;

                                }

                               

                                cout << endl;

                                cout << "          Time Elapsed: " << time << " s \n";

                                cout << "     Distance Traveled: " << h0 << " m \n";

                                cout << "       Height Remaining: 0 m \n";

                                cout << " Instantaneous Velocity: " << g * time << " m/s \n" ;

                                cout << ".....................................................\n\n";

                }

}



دانلود کد برنامه

نظرات 0 + ارسال نظر
برای نمایش آواتار خود در این وبلاگ در سایت Gravatar.com ثبت نام کنید. (راهنما)
ایمیل شما بعد از ثبت نمایش داده نخواهد شد