Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Distance Calculator Using Visual Studio 2010 C# what is the code? If you know a

ID: 3669329 • Letter: D

Question

Distance Calculator

Using Visual Studio 2010 C#


what is the code?

If you know a vehicle's speed and the amount of time it has traveled, you can calculate the distance it has traveled as follows. Distance = Speed Times Time For example, if a train travels, 40 miles per hour for 3 hours, the distance traveled is 120 miles. Create an application with a form similar to the one shown in Figure 5.51. The user enters a vehicle s speed and the number of hours traveled into text boxes When the user clicks the Calculate button, the application should use a loop to display in a list box the distance the vehicle has traveled for each hour of that time period.

Explanation / Answer

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace distance_calculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);

for (int i = 1; i <= b; i++)
listBox1.Items.Add("After hout " + i + " the distance is " + (a * i));

}
}
}