add Programmyday form github
This commit is contained in:
80
StudentenDatenbank/Datenbank.cs
Normal file
80
StudentenDatenbank/Datenbank.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
StudentenDatenbank/Program.cs
Normal file
32
StudentenDatenbank/Program.cs
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
32
StudentenDatenbank/Student.cs
Normal file
32
StudentenDatenbank/Student.cs
Normal 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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
10
StudentenDatenbank/StudentenDatenbank.csproj
Normal file
10
StudentenDatenbank/StudentenDatenbank.csproj
Normal 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>
|
||||
Reference in New Issue
Block a user