Здравствуйте!Помогите пожалуйста выполнить индивидуальное задание исходя из этого кода)
По исходному файлу определить всех студентов, ФИО которых начинается на
заданную букву. Сформировать файл из этих студентов.
C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
| static void Main(string[] args)
{
Console.Write("Введите количество студентов: ");
int n = Convert.ToInt32(Console.ReadLine());
Student[] students = new Student[n];
InputStudents(students);
Student[] reader = new Student[n];
using (FileStream file = File.Open("Students.txt", FileMode.OpenOrCreate))
using (StreamWriter a = new StreamWriter(file))
for (int i = 0; i < n; i++)
{
a.WriteLine(students[i].name + " " + students[i].age + " " + students[i].course + " " + students[i].gender + " " + students[i].mark);
}
using (FileStream filestream = File.Open("Students.txt", FileMode.Open))
using (StreamReader b = new StreamReader(filestream))
for (int i = 0; i <n; i++)
{
string line = b.ReadLine();
string[] data = line.Split(' ');
reader[i].name = data[0];
reader[i].age = Convert.ToInt16(data[1]);
reader[i].course = Convert.ToInt16(data[2]);
reader[i].gender = data[3];
reader[i].mark = Convert.ToDouble(data[4]);
}
OutputReader(reader);
MainMenu(students);
// Console.WriteLine("количество отличников равно:{0} ", Individ(students));
}
static void InputStudents(Student[] students)//заполняем массив
{
for (int i = 0; i < students.Length; i++)
{
students[i].Input();
}
}
static void OutputStudents(Student[] students)//выводим массив
{
foreach (Student s in students)
{
Console.WriteLine(s.ToString());
}
}
static void OutputReader(Student[] reader)
{
foreach (Student s in reader)
{
Console.WriteLine(s.ToString());
}
}
public static void AddFile()
{
string[] allLines = File.ReadAllLines("Student.txt");
StreamWriter sw = new StreamWriter("Student.txt", true);
Console.WriteLine("Введите строку: ");
string line1 = Console.ReadLine();
for (int i = 0; i < allLines.Length; i++)
{
sw.WriteLine(line1);
}
sw.Close();
}
public static void Delete()
{
string[] line = File.ReadAllLines("Student.txt");
StreamWriter sw = new StreamWriter("Delete.txt", true);
Student[] students = new Student[line.Length];
Console.WriteLine("Введите номер строки, которую хотите удалить: ");
int number = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < line.Length; i++)
{
if (i != number - 1)
{
sw.WriteLine(line[i]);
}
}
sw.Close();
}
public static void Redakt()
{
string[] line = File.ReadAllLines("Student.txt");
StreamWriter sw = new StreamWriter("Delete.txt", true);
Student[] students = new Student[line.Length];
Console.WriteLine("Введите номер строки, которую хотите откорректировать: ");
int number = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < line.Length; i++)
{
if (i == number - 1)
{
students[i].Input();
//InputStudents(students);
sw.WriteLine(students[i]);
}
}
sw.Close();
}
public static void MainMenu(Student[] students)
{
int menu;
Console.WriteLine("Введите 1, если хотите удалить элемент из файла: ");
Console.WriteLine("Введите 2, если хотите добавить элемент в файл: ");
Console.WriteLine("Введите 3, если хотите откорректировать файл: ");
Console.WriteLine("Введите 4, если хотите выполнить индивидуальное задание: ");
Console.Write("Введите номер пункта: ");
menu = Convert.ToInt32(Console.ReadLine());
if (menu == 1)
{
Delete();
}
if (menu == 2)
{
AddFile();
}
if (menu == 3)
{
Redakt();
}
// if (menu == 4)
//{
//}
}
}
} |
|