C# program to calculate the traveled distance based on speed and time
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Program:
The source code to calculate the traveled distance based on speed and time is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
Here, we created a Distance class that contains two methods CaclulatDistance() and Main().
In the CalculateDistance() method, we calculated traveled distance using the below formula,
distance = speed * time;
The Main() method is the entry point for the program, here we read the value of time and distance and then calculate the traveled distance using CalculateDistance() method and print the result on the console screen.