Question & Answer: Jee-mail, a small email service provider, has been receiving complaints from customers claiming that their inboxes a…..

Jee-mail, a small email service provider, has been receiving complaints from customers claiming that their inboxes are clogged with the dozens of spam email messages they receive each day. Consequently, Jee-mail has contracted with the Fruggle Corporation to design and build a spam detection system. Of course, since Fruggle gets all of its labor by exploiting El Camino students, you’ll be doing all of the programming. Given one or more email messages, your program will have to classify each one as either spam or legitimate. Jee-mail wants you to build a point-based anti-spam system. Your program is to look for certain suspicious features in the email, such as frequent use of exclamation points (!), use of words like FREE, or excessive use of uppercase letters. Each time such a suspicious feature is found, you increase a score that indicates how suspicious an email is. If an email’s score exceeds 100 points, then it is classified as spam; otherwise, it is deemed legitimate. The detailed rules for scoring a message are in the Spam Rules section below. Sample Transcript Here is a sample transcript of the program, with boldface text representing the user’s input. Enter the subject line of the email: MAKE MONEY FAST XTFWAQQQ Enter the body of the email. Press Enter on an empty line to finish. THIS IS YOUR CHANCE TO MAKE lots of moolah! CLICK ON www.lotsofmoolah.com FOR MORE INFORMATION! ← the user just hit the enter key on this line This email is classified as spam, because its spam score is 115. Would you like to classify another email (y or n)? Quit Please enter y or n. Would you like to classify another email (y or n)? Y Please enter y or n. Would you like to classify another email (y or n)? y Enter the subject line of the email: hi mom Enter the body of the email. Press Enter on an empty line to finish. Hi mom, I hope you’re doing OK. My CS class is great, but the instructor is WEIRD! I love you! ← the user just hit the enter key on this line This email is classified as legitimate, because its spam score is 0. Would you like to classify another email (y or n)? n Number of spam messages: 1 Number of legitimate messages: 1 Input and Output Specification The first line that your program must print out is exactly this (with one space after the colon): Enter the subject line of the email: Your program must then read the subject line the user types in. (It is not an error if the subject line is the empty string.) After that, your program must print out exactly this line: Enter the body of the email. Press Enter on an empty line to finish. Your program must then read the message body lines the user types in. The message body consists of zero or more lines. After your program reads an empty line, which indicates the end of the message, it must print out exactly one of these two messages, depending on whether applying the spam rules classified the message as spam or not: This email is classified as spam, because its spam score is number. or This email is classified as legitimate, because its spam score is number. In these messages, number is to be replaced by the appropriate spam score, such as 115, or 0, or 5. After printing the classification message, your program must print exactly this (with one space after the question mark): Would you like to classify another email (y or n)? Your program must then read the line the user types in. If the user types only a lowercase y, the program must process another email, starting with the step where it prints the prompt for the subject line of the email. If instead, the user types only a lowercase n, the program must print an empty line, then print the following two lines, then terminate: Number of spam messages: number Number of legitimate messages: number In these messages, the first number is the number of messages that were classified as spam, and the second is the number that were classified as legitimate. If the user types anything other than a single lowercase y or n in response to the question, the program must print out exactly the line: Please enter y or n. and repeat the prompt about classifying another email. It must repeatedly prompt the user until y or n is selected. Spam Rules The Jee-mail spam experts have come up with five rules, each of which can contribute some points to the spam score of a message. If the total spam score for the message is more than 100, the message is classified as spam; otherwise, it is considered a legitimate message. You must use only these five rules; do not improvise and make up your own. (Save that for when you start your own competing spam filter company.) First, some definitions: a word in a string is a contiguous sequence of letters delimited either by non-letter characters or by the start or the end of the string. A letter may be upper- or lowercase. As an example, the string It’s like the old-fashioned 1980s! has these seven words: It s like the old fashioned s. A consonant is a letter other than one of these ten: aeiouAEIOU. Here are the five rules. The first three relate to the subject line of the email, while the last two are concerned with the body of the message. If the subject line has at least one word, and more than 90% of the words in the subject line consist of only uppercase letters, then add 30 points to the spam score. For example, a subject line of GET A DIPLOMA FREE!! meets this criterion. If the last word of the subject line contains more than 3 consecutive consonants, then add 40 points to the spam score. Spammers often place random words at the end of a subject line to confuse some anti-spam software; this rules detects many of those random words. For example, this subject line earns the 40 point addition to the score: This stock is going up, up, up! mqafrpxo! If the subject line contains 3 or more contiguous exclamation points, then add 20 points to the spam score. This subject line qualifies for the 20 points, for example: Make money fast!!! No experience necessary!!!!! If the body of the message has at least one word, and more than 50% of the words making up the body of the email consist entirely of uppercase letters, then add 40 points to the score. For example, this email: Subject: Greetings from your good friend Body: THIS IS YOUR CHANCE TO MAKE lots of moolah! GO TO www.lotsofmoolah.com FOR MORE INFORMATION! earns the 40 points because there are 17 words in the body of the email, 11 of which (64.7%) are entirely uppercase. Each time one of the following special words is found in the body of the email, add 5 points to the spam score for that message. The letters in these words may be in either case (e.g., SeX is the same as sex): buy cheap click diploma enlarge free lonely money now offer only pills sex For example, this message would score 35 points, 5 for each of the words indicated in boldface: Subject: Looking for cheap tickets? Body: You can find cheap! tickets ONLY on our website. Save money with this great OfFeR!! Don’t be a cheapskate. Click now for this offer! Notice that the “cheap” in the subject line is ignored by this rule, as is the word “cheapskate” in the second line of the body. Functions You Must Write We know that this will be the most complex program that many of you will have written in your programming careers to date, so we will make it easier for you by decomposing the problem for you. To get full credit for this project, you must implement all of the following functions, using the exact function names, parameters types, and return types shown in this specification. The functions must not use any global variables whose values may change. (Global constants are all right.) In addition to testing your program as a whole, we will also test each of the following functions separately. That way, if your program doesn’t work overall but you correctly implemented some of the functions, you’ll still get some credit. The functions you must implement are getFirstWord getLastWord extractWord isUppercase makeUppercase hasMultipleExclamations isGibberishWord Your solution should use these functions where appropriate (although you might not use every one of them). One reason is to help you get partial credit in the case where most of your program is correct, but a few of the function implementations are incorrect. To help you implement these functions, you might choose to write additional functions as well. While we won’t test those additional functions separately, using them may help you structure your program more readably. If you find it helpful, you might have some of these seven required functions call other functions in that list. When you turn in your solution, none of these seven required functions, nor any functions that they call, may read any input from cin or write any output to cout. (Of course, during development, you may have them write whatever you like to help you debug.) If you want to print things out for debugging purposes, write to cerr instead of cout. cerr is the standard error destination; items written to it by default go to the screen. When we test your program, we will cause everything written to cerr to be discarded instead — we will never see that output, so you may leave those debugging output statements in your program if you wish. string getFirstWord(string text) This function returns the first word in the string variable text. If text has no words, this function returns the empty string (i.e. “”). Here is an incomplete test driver for this function: void test() { // This writes “Hello” cerr << getFirstWord(“!!Hello, Fred”) << endl; // This writes “greetings 9” string msg = “greetings, mom, how are you?”; string result = getFirstWord(msg); cerr << result << ” ” << result.size() << endl; // This writes “0” string s = getFirstWord(” $@#%!!”); cerr << s.size() << endl; } Hint: The string substr function may be of use in the implementation of this function. string getLastWord(string text) This function returns the last word in the string variable text. If text has no words, this function returns the empty string (i.e. “”). As an example, getLastWord(“MAKE MONEY FAST!!”) returns “FAST”. Hint: The string substr function may be of use in the implementation of this function. string extractWord(string& text) This function returns the first word in the string that text is a reference to. If that string has no words, this function returns the empty string. This function also modifies the string that text refers to. If that string has no words, then this function sets text to the empty string. Otherwise, it removes from text the first word of text and all non-letters preceding that first word. Here is an incomplete test driver: void test() { string s = “***AMAZING!*** Do it, now!!”; string w = extractWord(s); // This writes “AMAZING” and “!*** Do it, now!!” cerr << w << endl << s << endl; w = extractWord(s); // This writes “Do” and ” it, now!!” (space before “it”) cerr << w << endl << s << endl; w = extractWord(s); // This writes “it” and “, now!!” cerr << w << endl << s << endl; w = extractWord(s); // This writes “now” and “!!” cerr << w << endl << s << endl; w = extractWord(s); // This writes “” and “” (both empty strings) cerr << w << endl << s << endl; } Hint: The string substr function may be of use in the implementation of this function. bool isUppercase(string text) This function returns true if and only if every letter in the string text is uppercase. (For a string with no letters, this means the function returns true.) Non-letter characters in the string text, if any, have no effect on the result of this function. string makeUppercase(string text) This function returns a new string identical to the value of the string text, except that each lowercase letter of text appears as its uppercase equivalent in the result string. For example, makeUppercase(“Earn *big* MONEY at home!!”) returns “EARN *BIG* MONEY AT HOME!!”. bool hasMultipleExclamations(string text) This function returns true if and only if the string text contains three consecutive exclamation marks. For example, it returns true for the strings “Wow!!!” and “Congrats!!!! Good luck”, and false for the strings “W!I!N!” and “!! !”. bool isGibberishWord(string text) This function returns true if and only if the string text contains more than three consecutive consonants. For example, it returns true for the strings “AGPQrxab” and “xxxxozzzz”, and false for the strings “mortgage” and “discount prescriptions”. Programming Guidelines The correctness of your program must not depend on undefined program behavior. Your program must never access out of range positions in a string. You must use your best programming style, including commenting where appropriate. Be sure that your program builds successfully, and try to ensure that your functions do something reasonable for at least a few test cases. That way, you can get some partial credit for a solution that does not meet the entire specification. To test your program effectively, you should unit test each of your functions individually, and system test your entire program to ensure that all of the functions work together as expected. One way to organize your program so that you can easily switch between testing individual functions and running the whole program normally is to do something like this: const bool unitTesting = true; int main() { if (unitTesting) { doUnitsTests(); return 0; } … // code for the normal behavior goes here } The doUnitTests function does all your unit tests. To test the whole program normally, just change the value of the unitTesting variable from true to false (and make sure it’s false when you turn in the program). There are a number of ways you might write doUnitTests. One way is to interactively accept test strings: void doUnitTests() { string s; for (;;) { cerr << “Enter text: “; getline(cin, s); if (s == “quit”) break; cerr << “isUppercase returns “; if (isUppercase(s)) cerr << “true” << endl; else cerr << “false” << endl; cerr << “getFirstWord returns “; cerr << getFirstWord(s) << endl; } } While this is flexible, you run the risk of not being able to reproduce all your test cases if you make a change to your code and want to test that you didn’t break anything that used to work. Another way is to hard-code various tests and report which ones the program passes: void doUnitTests() { if (getFirstWord(“hello there”) == “hello”) cerr << “Passed test 1: getFirstWord(“hello there”) == “hello”)” << endl; if (!isUppercase(“WoW”)) cerr << “Passed test 2: !isUppercase(“WoW”)” << endl; … } This can get rather tedious. Fortunately, the library has a facility to make this easier: assert. If you include the header you can call assert in the following manner: assert(some boolean expression); During execution, if the expression is true, nothing happens and execution continues normally; if it is false, a diagnostic message is written telling you the text and location of the failed assertion, and the program is terminated. As an example, here’s a very incomplete set of tests: #include … void doUnitTests() { assert(getFirstWord(“hello there”) == “hello”); assert( isUppercase(“WOW!!”) ); assert( !isUppercase(“WoW!!”) ); string s = “***hello there”; assert( extractWord(s) == “hello” && s == ” there” ); assert( extractWord(s) == “there” && s == “” ); assert( extractWord(s) == “” && s == “” ); … cerr << “All tests succeeded” << endl; } The reason for writing one line of output at the end is to ensure that you can distinguish the situation of all tests succeeding from the case where one function you’re testing silently crashes the program.

Expert Answer

 

#include <iostream>
#include <string>
#include <cassert>
#include <cctype>
using namespace std;

//Declares methods to prevent compilation errors
bool hasWord(string text);
string getFirstWord(string text);
string getLastWord(string text);
string extractWord(string& text);
bool isUppercase(string text);
string makeUppercase(string text);
bool hasMultipleExclamations(string text);
bool isGibberishWord(string text);
void doUnitTests();

int main()
{
//Turns unit testing on or off
const bool unitTesting = false;
if(unitTesting)
{
doUnitTests();
return 0;
}

const double SUBJECT_UPPER_THRESHOLD = 90;
const int SUBJECT_UPPER_SPAM_SCORE_INCREASE = 30;
const int SUBJECT_GIBBERISH_SPAM_SCORE_INCREASE = 40;
const int SUBJECT_EXCLAMATION_SPAM_SCORE_INCREASE = 20;
const int BODY_SPECIAL_WORD_SPAM_SCORE_INCRASE = 5;
const double BODY_UPPER_THRESHOLD = 50;
const int BODY_MINIMUM_WORD_COUNT = 1;
const int BODY_UPPER_SPAM_SCORE_INCREASE = 40;
const int SPAM_SCORE_THRESHOLD = 100;

//Initialize counters for spam and legitimate e-mails
int spamCounter = 0;
int legitCounter = 0;

//Tracks if the spam program should be repeated
bool repeat = true;

while(repeat)
{

//Takes in the subject line
cout << “Enter the subject line of the email: “;
string s;
getline(cin,s);
const string subject = s;

//Takes in the body of the e-mail and puts it all into one string (n placed after input to account for getline function removing n)
cout << “Enter the body of the email. Press Enter on an empty line to finish.” << endl;
string b = “”;
string t = “”;
do
{
getline(cin,t);
b += (t + “n”);
}while(t!=””);
const string body = b;
//Subject and body input complete

/*cerr << “Subject: ” << subject << endl;*/

int spamScore = 0;

double sWordCount = 0;
double sUpperCount = 0;

//Holds the remainder of subject after extractWord function is invoked
string remainingSubject = subject;
//Holds the returned value of function extractWord
string sWord = extractWord(remainingSubject);

//Calculates number of words and uppercase words in subject
while(sWord!=””)
{
sWordCount++;
if(isUppercase(sWord))
{
sUpperCount++;
}
sWord = extractWord(remainingSubject);
}

//Calculates percentage of uppercase words in subject, changing spamScore as needed
double sPercentUpper = 0;
if(sWordCount>=1)
sPercentUpper = 100 * (sUpperCount / sWordCount);
if(sPercentUpper > SUBJECT_UPPER_THRESHOLD)
{
spamScore += SUBJECT_UPPER_SPAM_SCORE_INCREASE;
}
/*cerr << “Spam score (subject upper check): ” << spamScore << endl;*/

//Changes spamScore as needed for gibberish word rule
if(isGibberishWord(getLastWord(subject)))
{
spamScore += SUBJECT_GIBBERISH_SPAM_SCORE_INCREASE;
}
/*cerr << “Spam score (subject gibberish check): ” << spamScore << endl;*/

//Changes spamScore as needed for exclamation rule
if(hasMultipleExclamations(subject))
{
spamScore += SUBJECT_EXCLAMATION_SPAM_SCORE_INCREASE;
}
/*cerr << “Spam score (subject exclamation check): ” << spamScore << endl;

//Output for accuracy
cerr << “Number of words: ” << sWordCount << endl;
cerr << “Number of upper: ” << sUpperCount << endl;
cerr << “Percent of upper: ” << sPercentUpper << endl;
cerr << “Spam score (subject line checks): ” << spamScore << endl <<endl;

//Outputs body for readability
cerr << “Body: ” << body << endl;*/

double bWordCount = 0;
double bUpperCount = 0;

//Holds remainder of the string after extractWord function is invoked
string remainingBody = body;
//Holds the results of extractWord on remainingBody string
string bWord = extractWord(remainingBody);

//Counts number of words and number of uppercase words
while(bWord!=””)
{
bWordCount++;
if(isUppercase(bWord))
{
bUpperCount++;
}

//Detects presence of special spam words and changes spamScore as needed
string ss = makeUppercase(bWord);
if(ss==”BUY” || ss==”CHEAP” || ss==”CLICK” || ss==”DIPLOMA”
|| ss==”ENLARGE” || ss==”FREE” || ss==”LONELY” || ss==”MONEY”
|| ss==”NOW” || ss==”OFFER” || ss==”ONLY” || ss==”PILLS” || ss==”SEX”)
{
spamScore += BODY_SPECIAL_WORD_SPAM_SCORE_INCRASE;
}

bWord = extractWord(remainingBody);
}
/*cerr << “Spam score (body word check): ” << spamScore << endl;*/

//Calculates percent of uppercase words if the body has at least 1 word
//Changes the spamScore accordingly
double bPercentUpper = 0;
if(bWordCount>=BODY_MINIMUM_WORD_COUNT)
{
bPercentUpper = 100 * (bUpperCount / bWordCount);
if(bPercentUpper > BODY_UPPER_THRESHOLD)
{
spamScore += BODY_UPPER_SPAM_SCORE_INCREASE;
}
}

//Outputs for accuracy
/*cerr << “Spam score (body upper check): ” << spamScore << endl;
cerr << “Number of words: ” << bWordCount << endl;
cerr << “Number of upper: ” << bUpperCount << endl;
cerr << “Percent of upper: ” << bPercentUpper << endl;
cerr << “Spam score(total): ” << spamScore << endl;*/

//Categorizes the message based upon the spamScore
if(spamScore>SPAM_SCORE_THRESHOLD)
{
cout << “This email is classified as spam, because its spam score is ” << spamScore << “.” << endl;
spamCounter++;
}
else
{
cout << “This email is classified as legitimate, because its spam score is ” << spamScore << “.” << endl;
legitCounter++;
}

//Detects whether the user wants to use the program for another message
bool validResponse = false;
while(!validResponse)
{
cout << “Would you like to classify another email (y or n)? “;
string response = “”;
getline(cin,response);
if(response==”y”)
{
//The user has input a valid response, ending this while loop
//boolean repeat is still true, leading to another iteration of the program
validResponse = true;
}
else if(response==”n”)
{
cout << endl;
cout << “Number of spam messages: ” << spamCounter << endl;
cout << “Number of legitimate messages: ” << legitCounter << endl;

//User has input a valid response ending this while loop
//The program will not repeat
validResponse = true;
repeat = false;
}
else
{
//The user has failed to input a valid response
//validResponse is still false and the loop repeats
cout << “Please enter y or n.” << endl;
}
}
}
}

//Checks to see if the string text has a word (series of contiguous letters)
//Returns true if there is a word
bool hasWord(string text)
{
for(size_t i=0; i<text.size(); i++)
{
if(isalpha(text[i]))
{
return true;
}
}
return false;
}

//Returns the first word in the string text
//If there is no word, the function returns an empty string
string getFirstWord(string text)
{
if(!hasWord(text))
{
return “”;
}

//Removes all non-letters before first letter in the string
for(size_t i=0; i<text.size(); i++)
{
if(isalpha(text[i]))
{
text = text.substr(i,text.size()-i);
i = text.size();
}
}

//Adds letters to string s until a non-letter is reached
string s = “”;
for(size_t j = 0; j<text.size(); j++)
{
if(isalpha(text[j]))
{
s += text[j];
}
else
{
j = text.size();
}
}
return s;
}

//Returns the last word in string text
//If there is no word, returns an empty string
string getLastWord(string text)
{
if(!hasWord(text))
{
return “”;
}

//Removes all non-letters after the last letter in the string
size_t i = text.size();
do
{
i–;
if(isalpha(text[i]))
{
text = text.substr(0,i+1);
i = 0;
}
}while(i>0);

//Puts letters from text into the string “reversed” from the end of the string until the first non-letter character
//Characters are in reversed order
i = text.size();
string reversed = “”;
do
{
i–;
if(isalpha(text[i]))
{
reversed += text[i];
}
else
{
i = 0;
}
}while(i>0);

//Takes the reversed string and puts the characters into string “forward” in the correct order
i = reversed.size();
string forward = “”;
do
{
i–;
forward += reversed[i];
}while(i>0);

return forward;
}

//Returns the first word in string text
//All characters before and including the first word are removed from string text
string extractWord(string& text)
{
//If there is no word in text, text is set to the empty string and an empty string is returned
if(!hasWord(text))
{
text = “”;
return “”;
}

string firstWord = getFirstWord(text);

for(size_t i = 0; i<text.size(); i++)
{
//When the text substring is the same as the firstWord string
if(text.substr(i,firstWord.size())==firstWord)
{
//The text string becomes equal to the substring beginning one position after the firstWord string until the end of the string.
text = text.substr(i+firstWord.size(), text.size() – (i+firstWord.size()) );
i = text.size();
}
}
return firstWord;
}

//Checks to see if all letters in string text are uppercase
//Returns true if all letters are uppercase
bool isUppercase(string text)
{
for(size_t i = 0; i < text.size(); i++)
{
if(isalpha(text[i]) && islower(text[i]))
{
return false;
}
}
return true;
}

//Returns string text with all lowercase letters converted to their respective uppercase letters
string makeUppercase(string text)
{
for(size_t i=0; i<text.size(); i++)
{
text[i] = toupper(text[i]);
}
return text;
}

//Returns true if string text has “!!!”
bool hasMultipleExclamations(string text)
{
const int MULTIPLE_EXCLAMATION_THRESHOLD = 3;
if(text.size()<MULTIPLE_EXCLAMATION_THRESHOLD)
{
return false;
}
string exclam = “”;
for(int j = 0; j<MULTIPLE_EXCLAMATION_THRESHOLD; j++)
{
exclam += “!”;
}
for(size_t i = 0; i<text.size()-MULTIPLE_EXCLAMATION_THRESHOLD+1; i++)
{
if(text.substr(i,MULTIPLE_EXCLAMATION_THRESHOLD)==exclam)
{
return true;
}
}
return false;
}

//Returns false if char a is a letter or a vowel
bool isConsonant(char a)
{
char b = tolower(a);
if( !isalpha(b) || (b==’a’||b==’e’||b==’i’||b==’o’||b==’u’) )
{
return false;
}
return true;
}

//Returns true if text contains 4 consonants in a row
bool isGibberishWord(string text)
{
const double GIBBERISH_THRESHOLD = 4;
if(text.size()<GIBBERISH_THRESHOLD)
{
return false;
}

for(size_t i=0; i<text.size()-GIBBERISH_THRESHOLD+1; i++)
{
bool allConsonant = true; //Resets to true after each iteration
for(size_t j=0; j<GIBBERISH_THRESHOLD; j++)
{
if(!isConsonant(text[i+j])) //If there is never a non-consonant, allConsonant remains true and the function returns true
{
allConsonant = false;
}
}
if(allConsonant)
{
return true;
}
}
return false;
}

//Used to test individual functions
void doUnitTests()
{
//assert(boolean expression);
//if the expression is true -> program continues to run
//if the expression is false -> program writes diagnostic message of text and location of failure
assert(!hasWord(” “));
assert(hasWord(“h”));
assert(hasWord(“h ell o”));
assert(!hasWord(“9 84   57348″));
assert(hasWord(”              h h”));
assert(!hasWord(” 9 5 45 42″));
assert(!hasWord(”   ^%&*^   (*& (*& (* ^*^   %& $”));

assert(getFirstWord(“”)==””);
assert(getFirstWord(“k”)==”k”);
assert(getFirstWord(“h4r “)==”h”);
assert(getFirstWord(“hello”)==”hello”);
assert(getFirstWord(“hello hello”)==”hello”);
assert(getFirstWord(“@#!#!%#%hello”)==”hello”);
assert(getFirstWord(“2348723648@!$#@!$#!hello, bob”)==”hello”);
assert(getFirstWord(” 8768#hello, bob”)==”hello”);
assert(getFirstWord(“876987698768324762984763298467 hello kjhfa8937492837&(*^*%^$^467 “)==”hello”);
assert(getFirstWord(“898798 465 4658″)==””);
assert(getFirstWord(“3498537happy98347923874*&^%#&%#& 8&^*&^* 768762384 876idaskufh 87″)==”happy”);
assert(getFirstWord(” t 209837492 jfdkjsah 8 9823yiuhkg hgiu87236r8iegfhjh”)==”t”);
assert(getFirstWord(“9″)==””);

assert(getLastWord(“h4r”)==”r”);
assert(getLastWord(“h”)==”h”);
assert(getLastWord(“Hello”)==”Hello”);
assert(getLastWord(“Hello Hello”)==”Hello”);
assert(getLastWord(“Happy Sad”)==”Sad”);
assert(getLastWord(“93279324879kjashdkfjh983279482743h”)==”h”);
assert(getLastWord(“eioau84t984u98u49uooiaodhfakjdsbnfiauwe4ygiauwhvjksdbflkajhewfoaihgf9328y92u938247298392yfjh”)==”yfjh”);
assert(getLastWord(“APPLE!!!!”)==”APPLE”);
assert(getLastWord(“(*&^*&&*^*^*876842376823746836742876*&^*&^*768aaa98237492837(*&&^(^&^%&*^%*&%786868 876876 6%&5″)==”aaa”);
assert(getLastWord(“”)==””);
assert(getLastWord(“9″)==””);
assert(getLastWord(“MAKE MONEY FAST!!!”)==”FAST”);
assert(getLastWord(“MAKE MONEY FAST!!!”)!=” FAST”);

string test = “9834793847589734”;
assert(extractWord(test)==””);
assert(test==””);
test = “*&^*^*^*98374923798379*&^$^%^%98794 98734 8397 &^%&5 98 (*&( 657″;
assert(extractWord(test)==””);
assert(test==””);
test = “hello”;
assert(extractWord(test)==”hello”);
assert(test==””);
test = ” hello “;
assert(extractWord(test)==”hello”);
assert(test==” “);
test = “239847932(*&(*&765happy birthd ay98734(*&”;
assert(extractWord(test)==”happy”);
assert(test==” birthd ay98734(*&”);
test = “QTYHY564dg”;
assert(extractWord(test)==”QTYHY”);
assert(test==”564dg”);
test = “hello hello”;
assert(extractWord(test)==”hello”);
assert(test==” hello”);
string s = “***AMAZING!*** Do it, now!!”;
string w = extractWord(s);
assert(w==”AMAZING”);
assert(s==”!*** Do it, now!!”);
w = extractWord(s);
assert(w==”Do”);
assert(s==” it, now!!”);
w = extractWord(s);
assert(w==”it”);
assert(s==”, now!!”);
w = extractWord(s);
assert(w==”now”);
assert(s==”!!”);
w = extractWord(s);
assert(w==””);
assert(s==””);
s=”happy birthday”;
w = extractWord(s);
assert(w!=”happy “);
assert(s!=”happy birthday”);

assert(isUppercase(“”));
assert(isUppercase(”     “));
assert(isUppercase(“LKSDFJLSDKJFLDSKJF”));
assert(isUppercase(” LKJDF L KJL LKJ ASDFHY 98 OIHLHF HY9F8Y9UFHKWEFNSK 98E7Y”));
assert(!isUppercase(“LKDJ LKJDLF LKDJF 899 98u9fs 89879K HKJDHF 9879”));

assert(makeUppercase(“happy”)==”HAPPY”);
assert(makeUppercase(“LKSDJFLKJL 98798797 *&^*&^*( hh 897987 (*&(*&^%& JKSHKDFHSD”)==”LKSDJFLKJL 98798797 *&^*&^*( HH 897987 (*&(*&^%& JKSHKDFHSD”);
assert(makeUppercase(“ART”)==”ART”);
assert(makeUppercase(“Earn *big* MONEY at home!!”)==”EARN *BIG* MONEY AT HOME!!”);

assert(!hasMultipleExclamations(“h”));
assert(!hasMultipleExclamations(“”));
assert(!hasMultipleExclamations(“hh”));
assert(hasMultipleExclamations(“Wow!!!”));
assert(hasMultipleExclamations(“Congrats!!!! YOU ARE GREAT!”));
assert(!hasMultipleExclamations(“W!I!N!”));
assert(!hasMultipleExclamations(“!! !”));

assert(!isGibberishWord(“”));
assert(!isGibberishWord(“h”));
assert(!isGibberishWord(“h4h”));
assert(isGibberishWord(“xxxz”));
assert(!isGibberishWord(“oooooooooxxoooooo”));
assert(isGibberishWord(“happy birthday”));
assert(isGibberishWord(“AGPQrxab”));
assert(isGibberishWord(“xxxxozzzz”));
assert(!isGibberishWord(“mortgage”));
assert(!isGibberishWord(“discount prescriptions”));
assert(!isGibberishWord(”                   “));
assert(!isGibberishWord(“$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4”));
assert(isGibberishWord(“FJGHFJGHFJGHFJGHFJHFJHFGFJGHFGJHFKJFHGJFHGJFHG”));
assert(isGibberishWord(“ooooooooooooooookjgfoooooooooooooo”));
assert(isGibberishWord(“ooabcdf”));

cerr << “All tests succeeded” << endl;
}

Question & Answer: Jee-mail, a small email service provider, has been receiving complaints from customers claiming that their inboxes a..... 1

Still stressed from student homework?
Get quality assistance from academic writers!