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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
using namespace std;
int take_num_letters(void) {
int number_of_letters;
cout << "How many letters does your word have?: ";
cin >> number_of_letters;
return number_of_letters;
} // Takes Input
void initialize_file(string file_name, string exten = ".txt", string direc = "") {
if (direc.empty())
file_name += exten;
else
file_name = direc + '\\' + file_name + exten;
remove(file_name.c_str());
ofstream initializing(file_name);
initializing.close();
} // Initializes File
bool if_num_file_exist(int number_of_letters) {
ifstream file("words\\" + to_string(number_of_letters) + "_letters.txt");
if (file) {
file.close();
return true;
}
else {
file.close();
return false;
}
}
char find_most_occuring(string file_name, unsigned int &occ, string exten = ".txt", string direc = "") {
if (direc.empty())
file_name += exten;
else
file_name = direc + '\\' + file_name + exten;
long long int char_occurance[256] = { 0 };
char highest = 97;
ifstream file(file_name);
string line;
while (getline(file, line)) {
bool in_word[256] = { 0 };
for (char i : line) {
if (!(in_word[i])) {
char_occurance[i]++;
if (char_occurance[i] > char_occurance[highest])
highest = i;
}
in_word[i] = true;
}
}
file.close();
occ = char_occurance[highest];
return highest;
}
void file_to_file_write(string file_from, string file_to, string from_exten = ".txt",
string to_exten = ",txt", string direc_from = "", string direc_to = "") {
if (direc_from.empty())
file_from += from_exten;
else
file_from = direc_from + '\\' + file_from + from_exten;
if (direc_to.empty())
file_to += to_exten;
else
file_to = direc_to + "\\" + file_to + to_exten;
ifstream input_file(file_from);
ofstream output_file(file_to);
string line;
while (getline(input_file, line)) {
output_file << line << '\n';
}
input_file.close();
output_file.close();
}
void update_possibilities(char search_element, bool has_or_not, string file_name,
string exten = ".txt", string direc = "") {
if (direc.empty())
file_name += exten;
else
file_name = direc + '\\' + file_name + exten;
ifstream input_file(file_name);
ofstream temporary_file("temporary_19245.txt");
string line;
while (getline(input_file, line)) {
bool has = false;
for (char i : line)
if (i == search_element)
has = true;
if (has_or_not) {
if (has)
temporary_file << line << '\n';
}
else
if (!has)
temporary_file << line << '\n';
}
input_file.close();
temporary_file.close();
remove(file_name.c_str());
rename("temporary_19245.txt", file_name.c_str());
}
bool is_all_anagram() {
}
void retry_message(void) {
system("cls");
cout << "Hmm I don't know of any word with that "
<< "many letters, try again.\n\n";
}
int main() {
int num_letters;
while (num_letters = take_num_letters()) {
if (if_num_file_exist(num_letters)) {
initialize_file("possibilities");
file_to_file_write("words\\" + to_string(num_letters), "possibilities");
break;
// write from file to possibilities
}
else {
retry_message();
}
}
unsigned int num_occ{ 0 };
char most_occuring_char = find_most_occuring("possibilities", num_occ);
char asked_chars[20];
system("pause");
return 0;
}
|