Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DO NOT DELETE ANY SECTIONS OF THIS PROGRAM. SIMPLY ADD YOUR CODE IN THE APPROPRIATE SECTIONS REWRITE WHOLE THING IN C + + * /

DO NOT DELETE ANY SECTIONS OF THIS PROGRAM. SIMPLY ADD YOUR CODE IN THE
APPROPRIATE SECTIONS REWRITE WHOLE THING IN C++
*/
#include
#include
#include
#include
using namespace std;
void displayMenu();
int getChoice();
void STL_Algorithms();
void functionObjectsLambda();
void doubleNumbers(int &num);
bool outOfRange(int num);
class Sum
{
public:
int operator ()(int num1, int num2){ return num1+ num2; }
};
int main()
{
const int SELECTION =3;
int choice;
do{
displayMenu();
choice = getChoice();
if(choice != SELECTION)
{
switch(choice)
{
case 1: STL_Algorithms(); break;
case 2: functionObjectsLambda(); break;
}
}
}while(choice != SELECTION);
// current date and time on the current system
time_t dateTime = time(NULL);
cout <<"
Thank you for using this tutorial. I hope you enjoyed
"
<< "learning.
"
<< "Date : "<<(char *)(ctime(&dateTime))<< endl
<< "Author: Prof. Mathieu KOKOLY Kourouma, PhD
"
<<" All Rights Reserved
";
return 0;
}
void displayMenu()
{
cout << endl;
cout <<"***********************************************
";
cout << setw(45)<<"CMPS 201B - Data Structures - Spring 2024
";
cout << setw(30)<< "Project 1
"
<< "Due: Friday, March 22,2024, @ 11:55 PM, in Moodle
";
cout << "The topics to be discussed are:
"
<<"1. More on STL Algortihms
"
<<"2. Function Objects and Lambda Expressions
"
<<"3. Quit the tutorial program
";
cout <<"***********************************************
";
}
int getChoice()
{
int choice;
cout <<"
Enter your selection: ";
cin >> choice;
while(choice <1|| choice >3)
{
cout <<"
+++++++++++++++++++++++++++++++++++++++++
";
cout << "Invalid input. Valid choices are 1 to 3.
";
cout <<"+++++++++++++++++++++++++++++++++++++++++
";
cout << "Please enter again your selection: ";
cin >> choice;
}
return choice;
}
void STL_Algorithms()
{
cout <<"
------------------------------------------------------------";
cout <<"
More on STL Algortihms Tutorial
"
<< "You have already learned and programmed some STL algorithms,
"
<< "such as the sort, binary_search, set_union, set_intersection,
"
<< "set_difference, set_symmetric, and includes functions.
"
<<"In this tutorial, you will learn about is_permutation, for_each,
"
<< "and count_if functions.
";
cout <<"1. Using the is_permutation function
"
<<"------------------------------------
";
cout << "Given the following vectors:
";
cout << "vector winningNumbers ={23,45,56,12,10},
"
<< "vector playerOneNumbers ={27,45,65,12,10}, and
"
<< "vector playerTwoNumbers ={12,10,56,23,45}
";
cout << "The program determines which player's numbers are a permutation
"
<< "the winning numbers, as in a lottery.
";
vector winningNumbers ={23,45,56,12,10};
vector playerOneNumbers ={27,45,65,12,10};
vector playerTwoNumbers ={12,10,56,23,45};
if(is_permutation(winningNumbers.begin(), winningNumbers.end(),
playerOneNumbers.begin()))
cout << "Player 1 won the lottery!
";
else
cout << "Sorry player 1. You did not win the lottery.
";
if(is_permutation(winningNumbers.begin(), winningNumbers.end(),
playerTwoNumbers.begin()))
cout << "Player 2 won the lottery!
";
else
cout << "Sorry player 2. You did not win the lottery.
";
cout <<"
2. Using the for_each function
"
<<"------------------------------
";
cout << "Given the following vector:
";
cout << "vector numbers ={1,2,3,4,5}
";
cout << "The program doubles every element in the vector numbers.
";
vector numbers ={1,2,3,4,5};
for_each(numbers.begin(), numbers.end(), doubleNumbers);
cout << "Now, the numbers vector elements are:
";
cout << "vector numbers ={";
for(int element =0; element < numbers.size(); element++)
{
if(element <(numbers.size()-1))
cout << numbers[element]<<",";
else cout << numbers[element];
}
cout <<"}
";
cout <"
3. Using the count_if function
"
<<"------------------------------
";
cout << "Given the following vector:
";
cout << "vector integers ={0,99,100,-2,130,-34,110}
";
cout << "The program counts the

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

7. Define cultural space.

Answered: 1 week ago

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago