Witam, czy mógłby mi ktoś pomóc napisać albo naprowadzić jak zrobić, aby zrobić dobrze działającą tablicę struktur i do niej wprowadzać dane z klawiatury a następnie po wciśnieciu okreslonego klawisza w menu wyświetlić wprowadzone dane?
Napisałem coś takiego :
using System;
using System.IO;
using System.Collections.Generic;
**public struct student
{
public string Imie;
public int indeks;
public int oceny;
public int nieobecnosci;
public student(string FImie, int Findeks, int Foceny, int Fnieobecnosci)
{
Imie = FImie;
indeks = Findeks;
oceny = Foceny;
nieobecnosci = Fnieobecnosci;**
}
}
class Projekt
{
public static void Main(string[] args)
{
char c;
string s;
string d;
string path = "Lista.txt";
string[] lista = null;//tablica studentów
** student[] studentArr = null;**
int n = 0; // rozmiar tablicy, ilośc studentów
**int m = 0;//rozmiar struktury**
if (File.Exists(path))
{
lista = File.ReadAllLines(path);
n = lista.Length;
m = studentArr.Length;
}
Console.WriteLine("witamy w programie lista studentów");
do
{
Console.WriteLine("\nAby wypisać listę wciśnij a\nAby wpisać osobę wciśnij b\nAby wyszukać wciśnij c\nAby zakończyć wciśnij k\n");
c = Console.ReadKey(true).KeyChar;
//przetwarzanie polecenia użytkownika
switch (c)
{
case 'a':
case 'A':
if (lista != null && studentArr !=null)
for (int j = 0; j < m; j++)
{
Console.WriteLine(studentArr[j]);
for (int i = 0; i < n; i++)
Console.WriteLine(lista[i]);
}
else Console.WriteLine("lista jest pusta");
Console.WriteLine();
break;
case 'b':
case 'B':
Console.WriteLine("podaj nazwisko");
s = Console.ReadLine();
if (n == 0)
{
lista = new string[1];
}
else
{
string[] tmp = new string[n + 1];
for (int i = 0; i < n; i++)
tmp[i] = lista[i];
lista = tmp;
}
lista[n] = s;
n = n + 1;
** Console.WriteLine("podaj dane studenta");
d = Console.ReadLine();
if (m == 0)
{
studentArr = new student[0];
}
else
{
student[] tmp = new student[n + 1];
for (int j = 0; j < m; j++)
tmp[j] = studentArr[j];
studentArr = tmp;
}
**
break;
case 'c':
case 'C':
Console.WriteLine("podaj nazwisko do wyszukania");
s = Console.ReadLine();
bool b = true;
if (lista != null)
{
for (int i = 0; i < n; i++)
{
if (s == lista[i])
{
Console.WriteLine("znaleziono na pozycji " + i + " - " + lista[i]);
b = false;
}
}
if (b) Console.WriteLine("nie znaleziono");
}
else Console.WriteLine("lista jest pusta");
Console.WriteLine();
break;
}
}
while (!(c == 'k' || c == 'K'));
File.WriteAllLines(path, lista);
}
}
Bardzo proszę o odpowiedzi :)
Pozdrawiam.