SUVAT

by Alkesh Gajjar: L6 Age 17

Introduction

The usual SUVAT equations and many rearranged versions of them are used to calculate the distance (S), initial velocity (U), final velocity (V), acceleration (A) and time (T) given three of the other variables. The user selects first the unknown to be calculated and then has a choice of combinations of known variables to input. In total, the program caters for 18 different scenarios.

The Program

program SUVAT;
{$APPTYPE CONSOLE}

{
    Copyright (c) 2010 Alkesh Gajjar
    
    Licensed under the Apache License, Version 2.0 (the "License"); you may not 
    use this file except in compliance with the License, as described at
    http://www.apache.org/licenses/ and http://www.pp4s.co.uk/licenses/
}

uses
  SysUtils;
var
  Option1, Option2: integer; Distance, InitialVelocity, FinalVelocity, Acceleration,
  Time, S, U, V, A, T: Real;
begin
  Writeln ('This Is The SUVAT Equation Solver.');
  Sleep (1000);
  Writeln ('What do you need to find?');
  Sleep (1000);
  Writeln ('1. The Distance?');
  Sleep (750);
  Writeln ('2. The Initial Velocity?');
  Sleep (750);
  Writeln ('3. The Final Velocity?');
  Sleep (750);
  Writeln ('4. The Acceleration?');
  Sleep (750);
  Writeln ('5. The Time Taken?');
  Sleep (750);
  Write ('Please select the option you need to find: ');
  Read (Option1);
  Writeln;
  If Option1 = 1 then
    Begin
      Writeln ('  You need to find the Distance.');
      Sleep (500);
      Writeln ('  Which Values do you have?');
      Sleep (500);
      Writeln ('  1. Initial Velocity, Final Velocity & Acceleration');
      Sleep (500);
      Writeln ('  2. Initial Velocity, Final Velocity & Time Taken');
      Sleep (500);
      Writeln ('  3. Initial Velocity, Acceleration & Time Taken');
      Sleep (500);
      Writeln ('  4. Final Velocity, Acceleration & Time Taken');
      Sleep (500);
      Write ('  Please select the Correct option: ');
      Read (Option2);
      Writeln;
      if Option2 = 1 then
        Begin
          Write ('Please enter the Initial Velocity (m/s): ');
          Readln (U);
          Write ('Please enter the Final Velocity (m/s): ');
          Readln (V);
          Write ('Please enter the Acceleration (m/s/s): ');
          Readln (A);
          Distance := (sqr (V) - Sqr (U)) / (2 * A);
          Writeln (Distance:5:5, 'm');
          Readln;
        End;
      if Option2 = 2 then
        Begin
          Write ('Please enter the Initial Velocity (m/s): ');
          Readln (U);
          Write ('Please enter the Final Velocity (m/s): ');
          Readln (V);
          Write ('Please enter the Time Taken (s): ');
          Readln (T);
          Distance := 0.5 * (U + V) * T;
          Writeln (Distance:5:5, 'm');
          Readln;
        End;
      if Option2 = 3 then
        Begin
          Write ('Please enter the Initial Velocity (m/s): ');
          Readln (U);
          Write ('Please enter the Acceleration (m/s/s): ');
          Readln (A);
          Write ('Please enter the Time Taken (s): ');
          Readln (T);
          Distance := (U * T) + (0.5 * A * Sqr(T));
          Writeln (Distance:5:5, 'm');
          Readln;
        End;
      if Option2 = 4 then
        Begin
          Write ('Please enter the Final Velocity (m/s): ');
          Readln (V);
          Write ('Please enter the Acceleration (m/s/s): ');
          Readln (A);
          Write ('Please enter the Time Taken (s): ');
          Readln (T);
          Distance := (V * T) - (0.5 * A * Sqr(T));
          Writeln (Distance:5:5, 'm');
          Readln;
        End;
    End;

  If Option1 = 2 then
    Begin
      Writeln ('  You need to find the Initial Velocity.');
      Sleep (500);
      Writeln ('  Which Values do you have?');
      Sleep (500);
      Writeln ('  1. Distance, Final Velocity & Acceleration');
      Sleep (500);
      Writeln ('  2. Distance, Final Velocity & Time Taken');
      Sleep (500);
      Writeln ('  3. Distance, Acceleration & Time Taken');
      Sleep (500);
      Writeln ('  4. Final Velocity, Acceleration & Time Taken');
      Sleep (500);
      Write ('  Please select the Correct option: ');
      Read (Option2);
      Writeln;
      if Option2 = 1 then
        Begin
          Write ('Please enter the Distance (m): ');
          Readln (S);
          Write ('Please enter the Final Velocity (m/s): ');
          Readln (V);
          Write ('Please enter the Acceleration (m/s/s): ');
          Readln (A);
          InitialVelocity := Sqrt(Sqr(V) - (2 * A * S));
          Writeln (InitialVelocity:5:5, 'm/s');
          Readln;
        End;
      if Option2 = 2 then
        Begin
          Write ('Please enter the Distance (m): ');
          Readln (S);
          Write ('Please enter the Final Velocity (m/s): ');
          Readln (V);
          Write ('Please enter the Time Taken (s): ');
          Readln (T);
          InitialVelocity := (2 * S / T) - V;
          Writeln (InitialVelocity:5:5, 'm/s');
          Readln;
        End;
      if Option2 = 3 then
        Begin
          Write ('Please enter the Distance (m): ');
          Readln (S);
          Write ('Please enter the Acceleration (m/s/s): ');
          Readln (A);
          Write ('Please enter the Time Taken (s): ');
          Readln (T);
          InitialVelocity := (S/T)-(0.5*A*T);
          Writeln (InitialVelocity:5:5, 'm/s');
          Readln;
        End;
      if Option2 = 4 then
        Begin
          Write ('Please enter the Final Velocity (m/s): ');
          Readln (V);
          Write ('Please enter the Acceleration (m/s/s): ');
          Readln (A);
          Write ('Please enter the Time Taken (s): ');
          Readln (T);
          InitialVelocity := (V - (A * T));
          Writeln (InitialVelocity:5:5, 'm/s');
          Readln;
        End;
    End;

  If Option1 = 3 then
    Begin
      Writeln ('  You need to find the Final Velocity.');
      Sleep (500);
      Writeln ('  Which Values do you have?');
      Sleep (500);
      Writeln ('  1. Distance, Initial Velocity & Acceleration');
      Sleep (500);
      Writeln ('  2. Distance, Initial Velocity & Time Taken');
      Sleep (500);
      Writeln ('  3. Distance, Acceleration & Time Taken');
      Sleep (500);
      Writeln ('  4. Initial Velocity, Acceleration & Time Taken');
      Sleep (500);
      Write ('  Please select the Correct option: ');
      Read (Option2);
      Writeln;
      if Option2 = 1 then
        Begin
          Write ('Please enter the Distance (m): ');
          Readln (S);
          Write ('Please enter the Initial Velocity (m/s): ');
          Readln (U);
          Write ('Please enter the Acceleration (m/s/s): ');
          Readln (A);
          FinalVelocity := Sqrt(U * U + (2 * A * S));
          Writeln (FinalVelocity:5:5, 'm/s');
          Readln;
        End;
      if Option2 = 2 then
        Begin
          Write ('Please enter the Distance (m): ');
          Readln (S);
          Write ('Please enter the Initial Velocity (m/s): ');
          Readln (U);
          Write ('Please enter the Time Taken (s): ');
          Readln (T);
          FinalVelocity := ((2*S)/T)- U;
          Writeln (FinalVelocity:5:5, 'm/s');
          Readln;
        End;
      if Option2 = 3 then
        Begin
          Write ('Please enter the Distance (m): ');
          Readln (S);
          Write ('Please enter the Acceleration (m/s/s): ');
          Readln (A);
          Write ('Please enter the Time Taken (s): ');
          Readln (T);
          FinalVelocity := (S/T) + (0.5*A*T);
          Writeln (FinalVelocity:5:5, 'm/s');
          Readln;
        End;
      if Option2 = 4 then
        Begin
          Write ('Please enter the Initial Velocity (m/s): ');
          Readln (U);
          Write ('Please enter the Acceleration (m/s/s): ');
          Readln (A);
          Write ('Please enter the Time Taken (s): ');
          Readln (T);
          FinalVelocity := U + (A*T);
          Writeln (FinalVelocity:5:5, 'm/s');
          Readln;
        End;

    End;

  If Option1 = 4 then
    Begin
      Writeln ('  You need to find the Acceleration.');
      Sleep (500);
      Writeln ('  Which Values do you have?');
      Sleep (500);
      Writeln ('  1. Distance, Initial Velocity & Final Velocity');
      Sleep (500);
      Writeln ('  2. Distance, Initial Velocity & Time Taken');
      Sleep (500);
      Writeln ('  3. Distance, Final Velocity & Time Taken');
      Sleep (500);
      Writeln ('  4. Initial Velocity, Final Velocity & Time Taken');
      Sleep (500);
      Write ('  Please select the Correct option: ');
      Read (Option2);
      Writeln;
      if Option2 = 1 then
        Begin
          Write ('Please enter the Distance (m): ');
          Readln (S);
          Write ('Please enter the Initial Velocity (m/s): ');
          Readln (U);
          Write ('Please enter the Final Velocity (m/s): ');
          Readln (V);
          Acceleration := (Sqr (V) - Sqr (U))/ (2*S);
          Writeln (Acceleration:5:5, 'm/s/s');
          Readln;
        End;
      if Option2 = 2 then
        Begin
          Write ('Please enter the Distance (m): ');
          Readln (S);
          Write ('Please enter the Initial Velocity (m/s): ');
          Readln (U);
          Write ('Please enter the Time Taken (s): ');
          Readln (T);
          Acceleration := 2*((S - (U*T))/Sqr(T));
          Writeln (Acceleration:5:5, 'm/s/s');
          Readln;
        End;
      if Option2 = 3 then
        Begin
          Write ('Please enter the Distance (m): ');
          Readln (S);
          Write ('Please enter the Final Velocity (m/s): ');
          Readln (V);
          Write ('Please enter the Time Taken (s): ');
          Readln (T);
          Acceleration := 2*((V * T) - S)/Sqr(T);
          Writeln (Acceleration:5:5, 'm/s/s');
          Readln;
        End;   
      if Option2 = 4 then
        Begin
          Write ('Please enter the Initial Velocity (m/s): ');
          Readln (U);
          Write ('Please enter the Final Velocity (m/s): ');
          Readln (V);
          Write ('Please enter the Time Taken (s): ');
          Readln (T);
          Acceleration := (V-U)/T;
          Writeln (Acceleration:5:5, 'm/s/s');
          Readln;
        End;
    End;

  If Option1 = 5 then
    Begin
      Writeln ('  You need to find the Time Taken.');
      Sleep (500);
      Writeln ('  Which Values do you have?');
      Sleep (500);
      Writeln ('  1. Distance, Initial Velocity & Final Velocity');
      Sleep (500);
      Writeln ('  2. Initial Velocity, Final Velocity & Acceleration');
      Sleep (500);
      Write ('  Please select the Correct option: ');
      Read (Option2);
      if Option2 = 1 then
        Begin
          Write ('Please enter the Distance (m): ');
          Readln (S);
          Write ('Please enter the Initial Velocity (m/s): ');
          Readln (U);
          Write ('Please enter the Final Velocity (m/s): ');
          Readln (V);
          Time := (2*S)/(U+V);
          Writeln (Time:5:5, 's');
          Readln;
        End;
      if Option2 = 2 then
        Begin
          Write ('Please enter the Initial Velocity (m/s): ');
          Readln (U);
          Write ('Please enter the Final Velocity (m/s): ');
          Readln (V);
          Write ('Please enter the Acceleration (m/s/s): ');
          Readln (A);
          Time := (V-U)/A;
          Writeln (Time:5:5, 's');
          Readln;
        End;
    End;
End.

Remarks

Can you think of a program like this that you could write?

Programming - a skill for life!

Student programs to inspire you!