Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Ex 1 . Morale Boosters 3 5 points Overview The goal of this exercise is to make sure that you have mastered the basics of
Ex Morale Boosters
points
Overview
The goal of this exercise is to make sure that you have mastered the basics of using sets, maps, and vectors, before moving to the other exercises.
Task #
Implement function void readandreversein file vectorrev.cpp which keeps reading nonnegative integers from the user until the user enters a negative integer. When a negative integer is entered, the function prints the entered integers separated by spaces in reverse order.
For example, if the user enters the function prints
Note. You must use the STL vector.
Running Time.
On where
n is the size of the vector.
Task #
Implement function void reversestackstack& sin file stackrev.cpp which reverses the contents of the received stack.
Note. You must use the STL queue.
Running Time.
On where
n is the size of the stack.
Task #
Implement function void dedupvector& vin file dedup.cpp which removes duplicate elements from the received vector. For example, if v then calling dedupv makes the contents: Note that the first occurrence of the repeated elements is not removed and that the original order of the elements is maintained.
Note. You must use the STL set.
Running Time.
log
Onlogn where
n is the size of the vector.
Task #
Implement function string mostfrequentint nin file mostfreq.cpp which reads n strings from the user and prints the string that repeated the highest number of times. If there is more than one string that repeats the highest number of times, then the function prints the first of them in lexicographic order.
Example
Input ibrahim aboud ahmad manaf aboud ahmad ibrahim ahmad aboud
Output aboud
Explanation:
string frequency
ibrahim
aboud
ahmad
manaf
The most repeated strings are "aboud" and "ahmad".
Since "aboud" is lexicographically before "ahmad", the function prints "aboud".
Note. You must use the STL map.
Running Time.
log
Onlogn
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started