add Programmyday form github

This commit is contained in:
Ruben Kallinich
2024-07-25 15:47:46 +02:00
parent 09c8eab938
commit 7362c3d7ce
132 changed files with 3669 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Intrinsics.X86;
using System.Text;
using System.Threading.Tasks;
namespace StudentenDatenbank
{
internal class Datenbank
{
private Student[] studenten;
public Datenbank(int anzahl)
{
studenten = new Student[anzahl];
}
public bool AddStudent(Student student)
{
for (int i = 0; i < studenten.Length; i++)
{
if (studenten[i] == null)
{
studenten[i] = student;
return true;
}
}
return false;
}
public bool RemoveStudent(Student student)
{
for (int i = 0; i < studenten.Length; i++)
{
if (studenten[i] == student)
{
studenten[i] = null;
return true;
}
}
return false;
}
public bool RemoveStudent (int martrieklNr)
{
for (int i = 0; i < studenten.Length; i++)
{
if (studenten[i] != null)
{
if (studenten[i].GetMatrikelNr() == martrieklNr)
{
studenten[i] = null;
return true;
}
}
}
return false;
}
public int CountStudents()
{
int cnt = 0;
for (int i = 0; i < studenten.Length; i++)
{
if (studenten[i] != null)
{
cnt++;
}
}
return cnt;
}
public void PrintMe()
{
for (int i = 0; i < studenten.Length; i++)
{
if (studenten[i] != null)
{
studenten[i].PrintMe();
}
}
}
}
}

View File

@@ -0,0 +1,32 @@
namespace StudentenDatenbank
{
internal class Program
{
static void Main(string[] args)
{
Student s1 = new Student(1, "Max", "Informatik");
Student s2 = new Student(2, "Dörte", "Mathematik");
Student s3 = new Student(3, "Udo", "Agrartechnik");
Student s4 = new Student(4, "Sibille", "Architecktur");
Datenbank db = new Datenbank(5);
db.AddStudent(s1);
db.PrintMe();
Console.WriteLine();
db.AddStudent(s2);
db.AddStudent(s3);
db.PrintMe();
Console.WriteLine();
db.RemoveStudent(s2);
db.PrintMe();
Console.WriteLine();
db.RemoveStudent(1);
db.PrintMe();
}
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentenDatenbank
{
internal class Student
{
private int matrikelNr;
private string? name;
private string? fachrichtung;
public Student(int matrikelNr, string? name, string? fachrichtung)
{
this.matrikelNr = matrikelNr;
this.name = name;
this.fachrichtung = fachrichtung;
}
public int GetMatrikelNr() { return this.matrikelNr; }
public string? GetName() { return this.name; }
public string? GetFachrichtung() { return this.fachrichtung; }
public void PrintMe()
{
Console.WriteLine($"Matrikel-Nr.: {this.matrikelNr}");
Console.WriteLine($"Name: {this.name}");
Console.WriteLine($"Fachrichtung: {this.fachrichtung}");
}
}
}

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>