-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctional.cpp
More file actions
57 lines (52 loc) · 1.59 KB
/
Functional.cpp
File metadata and controls
57 lines (52 loc) · 1.59 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
#include "Functional.h"
#include <string>
//------------------------------------------------------------------------------
// Input parameters from file.
void Functional::In(Functional &t, FILE *file) {
fscanf(file, "%100s", t.name.c_str());
fscanf(file, "%i", &t.year);
fscanf(file, "%lf", &t.popularity);
fscanf(file, "%i", &t.lazy);
int oy;
fscanf(file, "%i", &oy);
if (oy == 1) {
t.tip = Functional::strict;
} else if (oy == 2) {
t.tip = Functional::dinamic;
} else {
printf("Error\n");
}
}
// Random parameters.
void Functional::InRnd(Functional &t) {
int k = rand() % 2;
if (k == 0) {
t.tip = Functional::strict;
} else {
t.tip = Functional::dinamic;
}
t.popularity = dRandom();
t.lazy = bRandom();
t.year = yRandom();
for (int i = 0; i < 100; i++) {
t.name[i] = 'a' + rand() % 26;
}
}
//------------------------------------------------------------------------------
// Output
void Functional::Out(Functional &t, FILE *file) {
std::string tips;
if (t.tip == Functional::strict) {
tips = "strict";
} else if (t.tip == Functional::dinamic) {
tips = "dinamic";
} else {
tips = "Error\n";
}
fprintf(file, "It is objective language: Have type = %s\n", tips.c_str());
fprintf(file, ". Popularity = %lf\n", t.popularity);
fprintf(file, ". Year = %i\n", t.year);
fprintf(file, ". Lazy = %i\n", t.lazy);
fprintf(file, ". Parameter = %lf\n", t.Average(t));
}
//------------------------------------------------------------------------------