#include <iostream> #include <string> #include <fstream> #include "random_string.h" #include "random_int.h" int main(){ // The random string generator rand_string a; // A random generator to decide when to duplicate the string rand_int b{0,100}; const int DUP_PROB=30; // An output file std::ofstream f; std::string name; std::cout << " Enter the file name: "; std::cin>>name; f.open(name.c_str()); if(!f) { std::cout <<"Error in opening file: " << name << std::endl; return 1; }; std::cout << " File opened: " << name << std::endl; int maxs{500},duplicates{0}; std::cout << " Enter the number of random string to be generated: "; std::cin>>maxs; for(int i=0; i<maxs; ++i) { std::string t{a()}; f<<t <<'\n'; // Duplicate 30% of the strings if(b()<=DUP_PROB) { f<<t<<'\n'; ++duplicates; } } f.close(); std::cout<< maxs <<" random strings generated and saved into file: " << name <<". " << duplicates << " duplicates generated." << std::endl; return 0; }