0 / 0 / 0
Регистрация: 06.11.2016
Сообщений: 117
|
|
1
|
Разобрать код
17.02.2017, 08:19. Показов 539. Ответов 0
Всем привет. Ребят, объясните, пожалуйста, как работает данная программа
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
126
127
128
129
130
131
| #include <iostream>
#include <string>
#include <fstream>
using namespace std;
int N;
int *mas;
string *students;
int *frends_week;
int GetElement(int i, int j)
{
return mas[i*N+j];
}
int ShowMenu()
{
cout<<"1. Прочитать файл"<<endl;
cout<<"2. Показать список"<<endl;
cout<<"3. Задать пару студентов"<<endl;
cout<<"4. Вычислить"<<endl;
cout<<"5. Выход"<<endl;
cout<<endl;
cout<<"Введите пункт: ";
int i=0;
cin>>i;
return i;
}
int ReadFile()
{
string s; // сюда будем ложить считанные строки
ifstream file("D:\\data.txt");
getline(file, s);
N = atoi(s.c_str()); // выводим на экран
students=new string[N];
mas=new int[N*N];
for(int i=0;i<N*N;i++)
mas[i]=0;
frends_week= new int[N];
for(int i=0;i<N;i++)
frends_week[i]=0;
for(int i=0;i<N;i++)
{
getline(file, s);
students[i]=s;
}
for(int i=0;i<N;i++)
{
getline(file, s);
int j=0;
int k=0;
string temp;
while(j!=s.length())
{
if(s[j]==',')
{
temp=s.substr(k,j-k);
mas[i*N+atoi(temp.c_str())-1]=1;
k=j+1;
temp.clear();
}
j++;
}
}
file.close();
return 0;
}
void WriteList()
{
for(int i=0;i<N;i++)
{
cout<<students[i]<<endl;
for(int j=0;j<N;j++)
{
cout<<mas[i*N+j]<<';';
}
cout<<endl;
}
system("pause");
}
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(0, "ru");
int i=0;
int first,last;
while(i!=5)
{
system("cls");
i=ShowMenu();
switch(i)
{
case 1:
ReadFile();
break;
case 2:
WriteList();
break;
case 3:
cout<<"Первый:";
cin>>first;
cout<<"Второй:";
cin>>last;
break;
case 4:
{
cout<<"Количество недель: "<<rand()%3<<endl;
system("pause");}
break;
}
}
N=3;
mas=new int[N*N];
for(int j=0;j<9;j++)
{
mas[j]=j;
}
cout<<GetElement(0,2)<<endl;
system("pause");
return -1;
} |
|
0
|