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