Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Untitled document LANGUAGE: C++ 1. This will give you some experience using a few STL containers and iterators Implement the removeOdds function: #include #include #include #include #include using...

1 answer below »
Untitled document
LANGUAGE: C++
1. This will give you some experience using a few STL containers and iterators
Implement the removeOdds function:
#include #include #include #include #include using namespace std;
Remove the odd integers from li.
It is acceptable if the order of the remaining even
integers is not
the same as in the original list.
void removeOdds(list& li)
{
}
void test1()
{
int a[8] = { 2, 8, 5, 6, 7, 3, 4, 1 };
list x(a, a+8);
construct x from the a
ay
assert(x.size() == 8 && x.front() == 2 && x.back() ==
1);
emoveOdds(x);
assert(x.size() == 4);
vecto
int> v(x.begin(), x.end());
construct v from
x
sort(v.begin(), v.end());
int expect[4] = { 2, 4, 6, 8 };
for (int k = 0; k < 4; k++)
assert(v[k] == expect[k]);
}
int main()
{
test1();
cout
"Passed"
endl;
}
1.
Implement the removeOdds function:
#include #include #include #include using namespace std;
Remove the odd integers from v.
It is acceptable if the order of the remaining even
integers is not
the same as in the original vector.
void removeOdds(vecto
int>& v)
{
}
void test2()
{
int a[8] = { 2, 8, 5, 6, 7, 3, 4, 1 };
vecto
int> x(a, a+8);
construct x from the a
ay
assert(x.size() == 8 && x.front() == 2 && x.back() ==
1);
emoveOdds(x);
assert(x.size() == 4);
sort(x.begin(), x.end());
int expect[4] = { 2, 4, 6, 8 };
for (int k = 0; k < 4; k++)
assert(x[k] == expect[k]);
}
int main()
{
test2();
cout
"Passed"
endl;
}
2.
Implement the removeBad function:
#include #include #include #include #include using namespace std;
vecto
int> destroyedOnes3;
class Movie3
{
public:
Movie3(int r) : m_rating(r) {}
~Movie3() { destroyedOnes3.push_back(m_rating); }
int rating() const { return m_rating; }
private:
int m_rating;
};
Remove the movies in li with a rating below 50 and
destroy them.
It is acceptable if the order of the remaining movies
is not
the same as in the original list.
void removeBad(list& li)
{
}
void test3()
{
int a[8] = { 85, 80, 30, 70, 20, 15, 90, 10 };
list x;
for (int k = 0; k < 8; k++)
x.push_back(new Movie3(a[k]));
assert(x.size() == 8 && x.front()-
ating() == 85 &&
x.back()-
ating() == 10);
emoveBad(x);
assert(x.size() == 4 && destroyedOnes3.size() == 4);
vecto
int> v;
for (list::iterator p = x.begin(); p !=
x.end(); p++)
{
Movie3* mp = *p;
v.push_back(mp-
ating());
}
sort(v.begin(), v.end());
int expect[4] = { 70, 80, 85, 90 };
for (int k = 0; k < 4; k++)
assert(v[k] == expect[k]);
sort(destroyedOnes3.begin(), destroyedOnes3.end());
int expectGone[4] = { 10, 15, 20, 30 };
for (int k = 0; k < 4; k++)
assert(destroyedOnes3[k] == expectGone[k]);
}
int main()
{
test3();
cout
"Passed"
endl;
}
3.
Implement the removeBad function:
#include #include #include #include using namespace std;
vecto
int> destroyedOnes4;
class Movie
{
public:
Movie(int r) : m_rating(r) {}
~Movie() { destroyedOnes4.push_back(m_rating); }
int rating() const { return m_rating; }
private:
int m_rating;
};
Remove the movies in v with a rating below 50 and
destroy them.
It is acceptable if the order of the remaining movies
is not
the same as in the original vector.
void removeBad(vecto
Movie*>& v)
{
}
void test4()
{
int a[8] = { 85, 80, 30, 70, 20, 15, 90, 10 };
vecto
Movie*> x;
for (int k = 0; k < 8; k++)
x.push_back(new Movie(a[k]));
assert(x.size() == 8 && x.front()-
ating() == 85 &&
x.back()-
ating() == 10);
emoveBad(x);
assert(x.size() == 4 && destroyedOnes4.size() == 4);
vecto
int> v;
for (int k = 0; k < 4; k++)
v.push_back(x[k]-
ating());
sort(v.begin(), v.end());
int expect[4] = { 70, 80, 85, 90 };
for (int k = 0; k < 4; k++)
assert(v[k] == expect[k]);
sort(destroyedOnes4.begin(), destroyedOnes4.end());
int expectGone[4] = { 10, 15, 20, 30 };
for (int k = 0; k < 4; k++)
assert(destroyedOnes4[k] == expectGone[k]);
}
int main()
{
test4();
cout
"Passed"
endl;
}
4.
2. Some word games, like Scra
le, require rea
anging a combination of letters
to make a word. This type of a
angement is generally refe
ed to as an
anagram, it's known as a permutation in mathematics.Write a C++ program
that searches for ``anagrams'' in a dictionary. An anagram is a word obtained
y scrambling the letters of some string. For example, the word ``pot'' is an
anagram of the string `"otp." A sample run of the program is given below.
Your output does not have to be formatted exactly the same as that shown in
the sample, but should be in a similar style. You can use words.txt
https:
elcamino.instructure.com/courses/20384/files/3480731/download?download_frd=1
3. download
Minimize File Preview
as your dictionary file. For this solution you must not use recursion. Instead look up
and use the std::next_permutation function in the algorithm li
ary.
Sample Runs
Here are two examples of how the program might work:
Please enter a string for an anagram: opt
Matching word opt
Matching word pot
Matching word top
Please enter a string for an anagram: blah
4. No matches found
Requirements
You must write these two functions with the exact same function signature
(include case):
int loadDictionary(istream &dictfile, vecto
string>& dict);
Places each string in dictfile into the vector dict. Returns the number of
words loaded into dict.
int permute(string word, vecto
string>& dict, vecto
string>& results);
Places all the permutations of word, which are found in dict into results.
Returns the number of matched words found.
For words with double letters you may find that different permutations match
the same word in the dictionary. For example, if you find all the permutations
of the string kloo using the algorithm we've discussed you may find that the
word look is found twice. The o's in kloo take turns in front. Your program
should ensure that matches are unique, in other words, the results a
ay
eturned from the permute function should have no dupicates.
Turn it in
What you will turn in for this assignment is a zip file containing these files:
1. A zip file which contains files named:
--A text file named containers.cpp (this should have all the code
excluding the main functions) that contains the source code for you
C++ program for question 1
https:
elcamino.instructure.com/courses/20384/files/3480731/download?download_frd=1
https:
elcamino.instructure.com/courses/20384/assignments/462887?return_to=https%3A%2F%2Felcamino.instructure.com%2Fcalendar%23view_name%3Dmonth%26view_start%3D XXXXXXXXXX#
--A text file named presumtations.cpp that contains the source
code for your C++ program for question 2.
Answered 1 days After Apr 28, 2021

Solution

Sandeep Kumar answered on Apr 29 2021
152 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here