-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
94 lines (87 loc) · 3.36 KB
/
Program.cs
File metadata and controls
94 lines (87 loc) · 3.36 KB
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
using System;
namespace Virtual_array
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Введите размер страницы в байтах");
var pageSize = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите количество страниц в буфере");
var pageCount = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите кол-во элементов");
var arrayLength = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите имя файла");
var fileName = Console.ReadLine();
var fm = new FileManager();
var va = new VirtualArray(arrayLength, pageSize, pageCount, fm, fileName);
Menu(va);
}
static void Menu(VirtualArray va)
{
while (true)
{
Console.WriteLine("1 - установить значение элемента по индексу\n2 - прочитать значение элемента по индексу\n0 - завершить\n");
int menu = Convert.ToInt32(Console.ReadLine());
if (menu == 0)
{
//va.SaveAllPages();
break;
}
while (true)
{
if (menu != 1 && menu != 2 && menu != 3 && menu != 0)
{
Console.WriteLine("Некорректный ввод! Попробуйте еще раз");
menu = Convert.ToInt32(Console.ReadLine());
}
else
break;
}
switch (menu)
{
case 1:
WriteElementByIndex(va);
break;
case 2:
ReadElementByIndex(va);
break;
}
}
}
static void WriteElementByIndex(VirtualArray va)
{
Console.WriteLine("Введите индекс");
int index = Convert.ToInt32(Console.ReadLine());
while (true)
{
if (index < 0)
{
Console.WriteLine("Некорректный ввод! Попробуйте еще раз");
index = Convert.ToInt32(Console.ReadLine());
}
else
break;
}
Console.WriteLine("Введите значение");
int value = Convert.ToInt32(Console.ReadLine());
va.WriteElementByIndex(index, value);
}
static void ReadElementByIndex(VirtualArray va)
{
Console.WriteLine("Введите индекс");
int index = Convert.ToInt32(Console.ReadLine());
while (true)
{
if (index < 0)
{
Console.WriteLine("Некорректный ввод! Попробуйте еще раз");
index = Convert.ToInt32(Console.ReadLine());
}
else
break;
}
va.ReadElementByIndex(index);
}
}
}