-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
86 lines (73 loc) · 2.26 KB
/
main.cpp
File metadata and controls
86 lines (73 loc) · 2.26 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
//------------------------------------------------------------------------------
// main.cpp - contains main function for testing functional.
//------------------------------------------------------------------------------
#include <stdlib.h> // For rand().
#include <time.h> // For time().
#include <string.h>
#include <stdio.h>
#include "Container.h"
void errMessage1() {
printf("incorrect command line!\n"
" Waited:\n"
" command -f infile outfile01 outfile02\n"
" Or:\n"
" command -n number outfile01 outfile02\n");
}
void errMessage2() {
printf("incorrect qualifier value!\n"
" Waited:\n"
" command -f infile outfile01 outfile02\n"
" Or:\n"
" command -n number outfile01 outfile02\n");
}
//------------------------------------------------------------------------------
int main(int argc, char* argv[]) {
clock_t start = clock(); // Start time.
if(argc != 5) {
errMessage1();
return 1;
}
printf("Start");
Container c;
char buffer[10];
FILE *file;
if(!strcmp(argv[1], "-f")) {
file = fopen(argv[2], "r");
c.In(file);
fclose(file);
}
else if(!strcmp(argv[1], "-n")) {
int size = atoi(argv[2]);
if((size < 1) || (size > 29999)) {
printf("incorrect");
snprintf(buffer, 10, "%d", size);
printf(". Set 0 < number <= 29999\n");
return 3;
}
// System clock.
srand(static_cast<unsigned int>(time(0)));
// Random data for container.
c.InRnd(c, size);
}
else {
errMessage2();
return 2;
}
// Output container data.
FILE *fileOutput;
fileOutput = fopen(argv[3], "w");
c.Out(c, fileOutput);
fclose(fileOutput);
// The 2nd part of task.
FILE *fileOutputSecond;
fileOutputSecond = fopen(argv[4], "w");
c.ShakerSort(c, c.len);
c.Out(c, fileOutputSecond);
fclose(fileOutputSecond);
c.Clear(c);
clock_t end = clock(); // Конечное время.
double total_time = static_cast<double>(end - start) / CLOCKS_PER_SEC;
printf("%s %lf %s \n", "Total time for program:", total_time, "seconds");
printf("Stop");
return 0;
}