Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 WindowsFormsApplication4
- {
- public partial class Form1 : Form
- {
- List<string> names = new List<string>();
- List<double> distance = new List<double>();
- public Form1()
- {
- InitializeComponent();
- }
- void AddToListBox()
- {
- listBox1.Items.Clear();
- for (int i = 0; i < names.Count; i++)
- {
- listBox1.Items.Add(names[i] + " " + distance[i]);
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- names.Add(textBoxNames.Text);
- distance.Add(Convert.ToDouble(textBoxDistance.Text));
- AddToListBox();
- textBoxDistance.Text = "";
- textBoxNames.Text = "";
- }
- private void buttonFurthest_Click(object sender, EventArgs e)
- {
- double furthest = 0.0;
- string calnames = "";
- for (int x = 0; x < distance.Count; x++)
- {
- if (distance[x] > furthest)
- {
- furthest = distance[x];
- calnames = names[x];
- }
- }
- MessageBox.Show("The person who lives the furthest away from college is " + calnames);
- }
- private void buttonNearist_Click(object sender, EventArgs e)
- {
- double nearist = Double.MaxValue;
- string caznames = "";
- for (int x = distance.Count -1; x >= 0; x--)
- {
- if (distance[x] <= nearist)
- {
- nearist = distance[x];
- caznames = names[x];
- }
- }
- MessageBox.Show("Nearist " + nearist + " (" + caznames + ")");
- }
- double CalcualteRange()
- {
- double result = distance.Max() - distance.Min();
- return result;
- }
- private void buttonRange_Click(object sender, EventArgs e)
- {
- double nearist1 = Double.MaxValue; //min
- for (int x = distance.Count - 1; x >= 0; x--) {
- if (distance[x] <= nearist1) {
- nearist1 = distance[x];
- }
- }
- double farthest1 = 0; //max
- for (int x = 0; x < distance.Count; x++) {
- if (distance[x] >= farthest1) {
- farthest1 = distance[x];
- }
- }
- double range = CalcualteRange();
- MessageBox.Show(string.Format("Max: {0}\nMin: {1}\nRange: {2}", farthest1, nearist1, range));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement