You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Übungen_LF6_WinFormanwendung
{
public partial class TestProgramm : Form
{
Random zufall = new Random();
int[] zFeld = new int[100];
int summe = 0, min = 0, max = 0;
double mittel;
public TestProgramm()
{
InitializeComponent();
}
private void button_startZufall_Click(object sender, EventArgs e)
{
listBox_RandomArray.Items.Clear();
for (int i = 0; i < zFeld.GetLength(0); i++)
{
zFeld[i] = zufall.Next(1000);
listBox_RandomArray.Items.Add(zFeld[i]);
}
}
private void button_Max_Click(object sender, EventArgs e)
{
max = zFeld.Max();
textBox_Max.Text = max.ToString();
}
private void button_Mittelwert_Click(object sender, EventArgs e)
{
mittel = zFeld.Average();
textBox_Mittel.Text = mittel.ToString();
}
private void button_Summe_Click(object sender, EventArgs e)
{
summe = 0;
for (int i = 0; i < zFeld.GetLength(0); i++)
{
summe = summe + zFeld[i];
}
textBox_Summe.Text = summe.ToString();
}
private void button_enthalten_Click(object sender, EventArgs e)
{
string enthalten = textBox_enthalten.Text;
bool arrEnthalten = false;
foreach (int zahl in zFeld)
{
if (enthalten == zahl.ToString())
{
textBox_enthalten.Text = enthalten + " ist im Array enthalten!";
arrEnthalten = true;
}
}
if (!arrEnthalten)
{
textBox_enthalten.Text = enthalten + " ist im Array nicht enthalten!";
}
}
private void button_sortieren_Click(object sender, EventArgs e)
{
//bubble sort
int temp = 0;
bool swapped = true;
listBox_RandomArray.Items.Clear();
while (swapped)
{
swapped = false;
for (int i = 0; i < zFeld.GetLength(0)-1; i++)
{
if (zFeld[i + 1] < zFeld[i])
{
temp = zFeld[i + 1];
zFeld[i + 1] = zFeld[i];
zFeld[i] = temp;
swapped = true;
}
}
}
foreach(int zahl in zFeld )
{
listBox_RandomArray.Items.Add(zahl);
}
}
private void button_ende_Click(object sender, EventArgs e)
{
this.Close();
}
private void textBox_Summe_TextChanged(object sender, EventArgs e)
{
}
private void listBox_RandomArray_SelectedIndexChanged(object sender, EventArgs e)
{
listBox_RandomArray.Items.Clear();
for (int i = 0; i < zFeld.GetLength(0); i++)
{
listBox_RandomArray.Items.Add(zFeld[i]);
}
}
private void button_Min_Click(object sender, EventArgs e)
{
min = zFeld.Min();
textBox_Min.Text = min.ToString();
}
}
}