You are on page 1of 3

10/2/23, 12:38 PM f23lab04_starter

In [1]: /* Abdullah Mustafa and Mohammed Abdulaziz


October 2, 2023
Version 1.0 */

In [2]: #include <iostream>


#include <string>
using namespace std;

string story_names[] = {"Little Red Riding Hood","Spider-Man","Rock Concerts","Kim Kar


string stories[] = {"\"Little Red Riding <::nn/>\" is a/an <::jj/> fairy tale for youn
string hints[20];
string words[20];

/*
The following are the hint types and their descriptions:

HINT TYPE DESC


————————— ————
animal: name of an animal
animal_plural: plural of an animal
body: name of a part of the human body
body_plural: plural of a part of the human body
food: type of food
food_plural: plural of a type of food
jj: adjective
liquid: type of liquid
nn: noun
nns: plural noun
rb: adverb
vb: verb, base form
vbd: verb, past tense
vbg: verb gerund or present participle (i.e. verb ending in "ing")
vbn: verb, past participle
vbz: verb, 3rd person singular present (i.e. verb ending in "s")

Here they are in a convenient format:


Hints: "animal","animal_plural","body","body_plural","food","food_plural","jj","liquid
Descriptions: "name of an animal","plural of an animal","name of a part of the human b

*/

In [3]: stories[0]

https://csci1060u.science.ontariotechu.ca/csci-env/user/abdullah.mustafa@ontariotechu.net/lab/tree/work/f23lab04_starter.ipynb 1/3
10/2/23, 12:38 PM f23lab04_starter

Out[3]: ""Little Red Riding <::nn/>" is a/an <::jj/> fairy tale for young children.
It is a story about a/an <::jj/> girl and a wolf.
The girl's mother sends her to take <::food/> to her sick grandmother.
The mother tells her she must not <::vb/> on the way.
A wolf sees the girl walking through the <::nns/> and makes a plan to <::vb/> her.
The wolf <::rb/> asks the girl where she is going.
The girl <::vbz/> him, because he seems <::jj/>.
Then the wolf tells her to pick some <::nns/> for her grandmother.
While she is <::vbg/> flowers, the wolf goes to her grandmother's house and eats her.
He puts on the grandmother's <::nn/> and gets into her bed.
When the girl arrives at her grandmother's house, she gets into <::nn/> with the wol
f.
The wolf leaps upon the child and <::vbz/> her."

In [4]: string getDescription(string hint){


//TODO: Complete this function!
string hint_types[] = {"animal", "animal_plural", "body", "body_plural", "food", "
"nn", "nns", "rb", "vb", "vbd", "vbg", "vbn", "vbz"
};

string hint_descriptions[] = {
"name of an animal", "plural of an animal", "name of a part of the human body", "p
"type of food", "plural of a type of food", "adjective", "type of liquid",
"noun", "plural noun", "adverb", "verb, base form", "verb, past tense", "verb geru
"verb, past participle", "verb, 3rd person singular present (i.e. verb ending in '
};

for (int i = 0; i < sizeof(hint_types); i++) {


if (hint == hint_types[i]) {
return hint_descriptions[i];
}
}
return "Missing Hint Type";
}

In [5]: string getHint(string tag){


//TODO: Complete this function!
string hint;
int x = tag.length();
hint = tag.substr(3,(x-5));
return hint;
}

In [ ]:

In [6]: //Populate hints array with the correct hints


int fillHints(string story){
int hint_count = 0;
string tag;
while(story.find('<') != string::npos){

tag = story.substr(story.find('<'), story.find('>') - story.find('<') + 1)


hints[hint_count] = getHint(tag);
story = story.substr(story.find('>') + 1, story.length());
hint_count++;

https://csci1060u.science.ontariotechu.ca/csci-env/user/abdullah.mustafa@ontariotechu.net/lab/tree/work/f23lab04_starter.ipynb 2/3
10/2/23, 12:38 PM f23lab04_starter

return hint_count;
}

In [7]: fillHints(stories[0])

Out[7]: 15

In [ ]:

In [8]: string modifyStory(string story, int hint_count){


//TODO: Complete this function!
for (int i = 0; i < hint_count; i++) {
int tag_length = story.find('>') - story.find('<') + 1;
story.replace(story.find('<'),tag_length,words[i]);

}
return story;
}

In [ ]:

In [9]: modifyStory(stories[0], 15)

Out[9]: ""Little Red Riding " is a/an fairy tale for young children.
It is a story about a/an girl and a wolf.
The girl's mother sends her to take to her sick grandmother.
The mother tells her she must not on the way.
A wolf sees the girl walking through the and makes a plan to her.
The wolf asks the girl where she is going.
The girl him, because he seems .
Then the wolf tells her to pick some for her grandmother.
While she is flowers, the wolf goes to her grandmother's house and eats her.
He puts on the grandmother's and gets into her bed.
When the girl arrives at her grandmother's house, she gets into with the wolf.
The wolf leaps upon the child and her."

In [10]: void madLibs(){


//TODO: Complete this function!

In [ ]:

In [ ]:

https://csci1060u.science.ontariotechu.ca/csci-env/user/abdullah.mustafa@ontariotechu.net/lab/tree/work/f23lab04_starter.ipynb 3/3

You might also like