C++ Code must use cin, cout, iostream, cmath for pow(n,x) Here\'s the prompt: Th
ID: 3653652 • Letter: C
Question
C++ Code must use cin, cout, iostream, cmath for pow(n,x) Here's the prompt: The distance a vehicle travels can be calculated as follows: distance = speed * time For example, if a train travels 40 miles per hour for 3 hours, the distance traveled is 120 miles. Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. The program should then use a loop to display the distance the vehicle has traveled for each hour of that time period. Here is an example of the output: What is the speed of the vehicle in mph? 40 How many hours has it traveled? 3 Hour Distance Traveled ---------------------------------------- 1 40 2 80 3 120 Input validation: do noExplanation / Answer
Loops Data validation Decision structures Sub Procedures InputBox Function MessageBox Function Modularity concept Program: This program shall determine the distance that a vehicle travels (in miles) based on the vehicle’s speed (in MPH), and the traveled time (in hours). NOTE: In most applications, the InputBox function should not be used as the primary method of input because it draws the user’s attention away from the application’s form. It also complicates data validation because if a data entry error occurs, the input box closes not allowing the user for another opportunity for coming back and fixing the error. Despite these drawbacks, it is a convenient tool for developing and testing applications. The formula for determining the distance traveled is given by: Distance = Speed * Time Create an application having a graphical user interface (GUI) similar to the Main Form shown in Figure 1. When the user clicks the Calculate button, the application displays an InputBox asking the user to enter the speed of the vehicle in miles-per-hour (MPH), followed by a second InputBox asking the user to enter the traveled time (in hours) If the user enters non-numeric data or leaves empty the contents in either of the InputBoxes, then the user receives the appropriate error message in a MessageBox. To finalize the project requirements, the program uses a Loop structure to display in a ListBox the distance that the vehicle traveled during each hour, and the total distance traveled (Figure 5). In order to meet the Modularity requirement of this project, the SpeedErrorMessage () and TimeErrorMessage () sub procedures must be called from inside the CalculateDistance() routine (sub procedure) and executed only when the user enters non-numeric data into the corresponding Input Boxes (speed and time). The validation requirements include: The vehicle’s speed of travel must be numeric (in MPH) and greater than zero, otherwise, display to the user in a MessageBox the appropriate error message. The vehicle’s time of travel must be numeric (in hours) and greater than zero, otherwise, display to the user in a MessageBox the appropriate error message. The Total travel distance must be numeric. This is what i got so far: Public Class Form1 Private Sub lbList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstOutput.SelectedIndexChanged End Sub Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click Dim intSpeed As Integer Dim intTime As Integer Dim intCount As Integer Dim intDistance As Integer Dim strDriver As String Dim strTapeMessage As String strDriver = InputBox("What's yer name?") If strDriver = "" Then DriverErrorMessage(strDriver) Exit Sub End If Try intSpeed = CInt(InputBox("Enter the vehicle's speed, in MPH.", "Input Needed")) Catch SpeedErrorMessage() ' calling the subproceduree as part of the modulatity requirement. Return End Try If intSpeedRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.