-
-
Save Experiment5X/5601806 to your computer and use it in GitHub Desktop.
#include "EssayScrambler.h" | |
using namespace std; | |
EssayScrambler::EssayScrambler(const string &essayText) : | |
essayText(essayText) | |
{ | |
parseText(); | |
} | |
void EssayScrambler::parseText() | |
{ | |
string word, nextWord; | |
istringstream stream(essayText); | |
// iterate through all of the words in the 'essay' | |
stream >> word; | |
word = formatWord(word); | |
while (stream >> nextWord) | |
{ | |
nextWord = formatWord(nextWord); | |
// if the word doesn't exist in the map, then add it | |
if (wordMap.find(word) == wordMap.end()) | |
wordMap[word] = { nextWord }; | |
// otherwise, just add the word that follows it | |
else | |
wordMap.find(word)->second.push_back(nextWord); | |
word = nextWord; | |
} | |
} | |
void EssayScrambler::GenerateNonsenseEssay(const int wordCount, string& outBlock) | |
{ | |
// seed the random number generator | |
srand(time(0)); | |
// get a random element from the word map to start off with | |
map<string, vector<string> >::iterator iter = wordMap.begin(); | |
std::advance(iter, rand() % wordMap.size()); | |
string currentWord = iter->first; | |
// clear the output string | |
outBlock = ""; | |
for (int i = 0; i < wordCount; i++) | |
{ | |
// add the current string onto the output | |
outBlock += currentWord + " "; | |
// get the next word | |
currentWord = iter->second.at(rand() % iter->second.size()); | |
iter = wordMap.find(currentWord); | |
if (iter == wordMap.end()) | |
return; | |
} | |
} | |
string EssayScrambler::formatWord(const string& word) | |
{ | |
string toReturn = ""; | |
for (char c : word) | |
{ | |
if (c >= 'a' && c <= 'z') | |
toReturn += c; | |
else if (c >= 'A' && c <= 'Z') | |
toReturn += tolower(c); | |
} | |
return toReturn; | |
} |
#ifndef ESSAYSCRAMBLER_H | |
#define ESSAYSCRAMBLER_H | |
#include <iostream> | |
#include <map> | |
#include <vector> | |
#include <sstream> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <ctype.h> | |
using std::string; | |
using std::vector; | |
using std::map; | |
class EssayScrambler | |
{ | |
public: | |
/*=================================================================== | |
EssayScrambler(essayText) | |
Create an EssayScrambler object based off of the text block | |
passed in | |
essayText text block to base the scrambled text from | |
=================================================================== | |
*/ | |
EssayScrambler(const string &essayText); | |
/*=================================================================== | |
GenerateNonsenseTextBlock(wordCount, outBlock) | |
Generate a nonsense text block that is roughly based off | |
the input essay | |
wordCount Number of words in output text block | |
outBlock Destination for generated text block | |
=================================================================== | |
*/ | |
void GenerateNonsenseEssay(const int wordCount, string &outBlock); | |
private: | |
const string &essayText; | |
map<string, vector<string> > wordMap; | |
/*==================================================================== | |
parseText() | |
Parse the essay into the wordMap, so that a garbage essay | |
can easily be generated | |
==================================================================== | |
*/ | |
void parseText(); | |
/*==================================================================== | |
foramtWord(word) | |
Format the word to a standard form. All punctuation will be | |
removed, and all of the characters will be set to lowercase. | |
word The word to be formated | |
==================================================================== | |
*/ | |
string formatWord(const string &word); | |
}; | |
#endif /* ESSAYSCRAMBLER_H */ |
#include <iostream> | |
#include <fstream> | |
#include "EssayScrambler.h" | |
using namespace std; | |
int main(int argc, char **argv) | |
{ | |
if (argc != 3) | |
{ | |
cout << "Invalid arguments." << endl; | |
cout << "Usage: essayScrambler [fileName] [wordOutputCount]" << endl; | |
return -1; | |
} | |
// read in the file contents | |
ifstream inFile(argv[1]); | |
stringstream buffer; | |
buffer << inFile.rdbuf(); | |
inFile.close(); | |
// the following try and if block is kind of weird, but it's better that | |
// having the error in 2 different spots, at least I'd rather have it that way | |
int wordCount; | |
bool error = false; | |
try | |
{ | |
wordCount = stoi(string(argv[2])); | |
error = wordCount < 0; | |
} | |
catch (...) | |
{ | |
error = true; | |
} | |
if (error) | |
{ | |
cout << "Invalid format for line number, must be a positive integer."; | |
return -1; | |
} | |
string scrambledEssay; | |
EssayScrambler essay(buffer.str()); | |
essay.GenerateNonsenseEssay(wordCount, scrambledEssay); | |
cout << scrambledEssay << endl; | |
return 0; | |
} |
Hi all! I’m author Isabella Scott, and I have an essential recommendation for students grappling with essays. This service with paper writer https://www.instagram.com/paperwritercom/?igshid=YmMyMTA2M2Y%3D transcends basic writing assistance, offering a rounded educational experience that includes mentoring, constructive reviews, and thorough research aid. Managed by a versatile team of academically accomplished professionals, the platform assures that your essays will be error-free and intellectually enriching. Plus, they operate with a strong anti-plagiarism stance, giving you peace of mind about the originality of your work. What's particularly impressive is their budget-conscious pricing, which makes top-tier assistance accessible to students.
I've been using 99Papers - cheap essay papers for a while now, and I can confidently say they never disappoint! Whether it's an essay, research paper, or even editing help, their writers are always on point. The best part? They always deliver on time, and the quality is solid. Super helpful when you're drowning in deadlines. Plus, their customer support is actually responsive, which is rare! Definitely recommend for anyone juggling multiple assignments and looking for reliable academic help.
very interesting project. he can help a lot. I have to write a lot in my work. I usually edit my texts here: https://cheappaperwriting.com/20-best-networking-presentation-topics-in-ppt-format/ it saves a lot of time and helps to quickly fix mistakes. But what you wrote may also help in this matter.