2 / 2 / 2
Регистрация: 10.10.2016
Сообщений: 142
|
|
1
|
Подробно объяснить код
30.11.2016, 19:55. Показов 428. Ответов 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
132
133
| #include"stdafx.h"
#include<string.h>
#include <iostream>
using namespace std;
const int MAX = 5;
struct polinom
{
int stepen[30];
int koifetient[30];
}polinom_list[MAX];
void init_list()
{
register int t;
for (t = 0; t<MAX; ++t) polinom_list[t].stepen[0] = '\0';
}
int find_free()
{
register int t;
for (t = 0; polinom_list[t].stepen[0] && t<MAX; ++t);
if (t == MAX) return -1;
return t;
}
int menu_select()
{
char s[80];
int c;
cout << "1. Ввести полiном" << endl;
cout << "2. Вивiд полiнома"<< endl;
cout << "3. Диференцiювання полiнома" << endl;
cout << "4. Вихiд" << endl;
do
{
cout << endl<< "Введiть номер потрiбного пункту: ";
cin >> s;
c = atoi(s);
cout << endl;
} while (c<0 || c>4);
return c;
}
void enter()
{
cout << "Натиснiть N для виходу" << endl << endl;
int slot, k = 0;
char s[80];
slot = find_free();
if (slot == -1)
{
cout << "Список заповнений!" << endl;
return;
}
while (strcmp(s, "N") != NULL)
{
cout << "Введiть степiнь при x" << k + 1 << ":";
cin >> s;
polinom_list[slot].stepen[k] = strtoul(s, '\0', 10);
cout << "Введiть кoефiцiєнт при x" << k + 1 << ":";
cin >> s;
polinom_list[slot].koifetient[k] = strtoul(s, '\0', 10);
k++;
}
cout << endl;
polinom_list[slot].stepen[k - 1] = '\0';
polinom_list[slot].koifetient[k - 1] = '\0';
}
void list()
{
int t, i;
for (t = 0; t<MAX && polinom_list[t].stepen[0]; t++)
{
cout << t + 1 << ". ";
for (i = 0; i<MAX && polinom_list[t].stepen[i]; i++)
{
if (i != 0) cout << " + ";
cout << polinom_list[t].koifetient[i]<< "x^"<< polinom_list[t].stepen[i];
}
cout << endl;
}
cout << endl << endl;
}
void def()
{
char s[80];
int t, i;
cout << "Введiть номер рядка з полiномом якої треба продеференцiювати: ";
cin >> s;
t = atoi(s);
t--;
cout << endl;
cout << t + 1 << ". ";
for (i = 0; i<MAX && polinom_list[t].stepen[i]; i++)
{
polinom_list[t].koifetient[i] *= polinom_list[t].stepen[i];
polinom_list[t].stepen[i] -= 1;
cout << polinom_list[t].koifetient[i] << "x^" << polinom_list[t].stepen[i] << " + ";
}
cout << endl << endl;
}
int main()
{
setlocale(LC_ALL, "Ukrainian");
char choice;
init_list();
for (;;)
{
choice = menu_select();
switch (choice)
{
case 1: enter();
break;
case 2: list();
break;
case 3: def();
break;
case 4: exit(0);
}
}
return 0;
} |
|
Добавлено через 7 часов 6 минут
хотя бы первые две функции, пожалуйста
0
|