-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c++
99 lines (82 loc) · 2.4 KB
/
main.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
// ------------------------------
// projects/c++/decipher/main.c++
// Copyright (C) 2009
// Glenn P. Downing
// ------------------------------
// To run the tests:
// g++ -ansi -pedantic -lcppunit -ldl -Wall -DTEST main.c++ -o main.app
// valgrind main.app
// To run the program:
// g++ -ansi -pedantic -Wall main.c++ -o main.app
// valgrind main.app < main.in > main.out
// To configure Doxygen:
// doxygen -g
// That creates the file Doxyfile.
// Make the following edits:
// EXTRACT_ALL = YES
// EXTRACT_PRIVATE = YES
// EXTRACT_STATIC = YES
// GENERATE_LATEX = NO
// To document the program:
// doxygen Doxyfile
// --------
// includes
// --------
#include <cassert> // assert
#include <iostream> // cout, endl, ios_base, noskipws
#include <fstream> // ifstream
#ifdef TEST
#include "cppunit/TestSuite.h" // TestSuite
#include "cppunit/TextTestRunner.h" // TestRunner
#include "TestDecipher.h"
#endif // TEST
#include "Decipher.h"
// ----
// main
// ----
int main (int argc, char* argv[]) {
using namespace std;
using namespace Decipher;
ios_base::sync_with_stdio(false); // turn off synchronization with C I/O
#ifdef TEST
// ----------
// unit tests
// ----------
using namespace CppUnit;
TextTestRunner tr;
tr.addTest(TestDecipher::suite());
tr.run();
#else
// -------
// program
// -------
static char text[5000];
istream* p = &cin;
ifstream in;
if (argc > 1) {
in.open(argv[1]); //opening the file from argv[1]
assert(in);
in >> noskipws;
p = ∈}
assert(*p);
*p >> noskipws; //don't skip whitespaces
assert(*p);
// rewrite the code below
char* iter = text;
char c;
while (*p >> c){ //read the input either from the keyboard or the file
// cout << c;
*iter = c; // copy the input to the text[]
++iter;
}// iter now pts to the end of the text file
c = max_frequency(text, iter);
rotate(text, iter, 'e' - c);
char* t = text;
//outputting the decyphered file into the standard output
while (t < iter){
assert(t >= text && t < iter);
cout<< *(t++);
}
in.close(); //close the file
#endif // TEST
return 0;}