Question

In c++

#include <iostream > 2 #include <set> #înclude <functional» 5 using namespace std; 7 //your code 9 int main) 4 6 8 1e set <doScenario Write a program that creates two sets (the sets are given in the code below) and asks the user for a number. Next yo

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hello,

The following is the solution for this assignment.

I have added comments in the code for your easy reference. If you need more information or have queries, leave me a comment.

If this solution helps you with this assignment, do upvote this answer. Thank you.

//Code for this solution

//File: sets.cpp


#include <iostream>
#include <set>
#include <functional>
using namespace std;
//Function to find "num" in the set
void find_set(set<double, greater<double>>& values, double num) {
//Find if the num exists in the set
const int count = values.count(num);
if(count > 0) {
//If found, print the rest of the elements in the set
for (auto it = values.find(num); it != values.end(); ++it)
cout << ' ' << *it;
} else {
//If not found, print the string
cout << " Not found";
}
}
int main() {
//Test data
set<double, greater<double>> valuesA = { -1.1, 2.9, -2.3, 2.71 };
set<double, greater<double>> valuesB = { -3.14, 2.71, -3.88, 2.19 };
//Get user input
double value;
cout << "Enter a number: ";
cin >> value;
//call the method to find if value exists in the sets
find_set(valuesA, value);
find_set(valuesB, value);
return 0;
}

//Output for this solution

Add a comment
Know the answer?
Add Answer to:
In c++ #include <iostream > 2 #include <set> #înclude <functional» 5 using namespace std; 7 //your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ assignment. Please help me to complete this code: #include <string> #include <iostream> using namespace std;...

    C++ assignment. Please help me to complete this code: #include <string> #include <iostream> using namespace std; // Write your function here //////////////// STUDENT TESTING //////////////////// int run() { cout << "Student testing" << endl; strip(); return 0; } Here is the instruction: Write a filter function named strip that removes C++ comments from input, sending the uncommented portion of the program to output. Your program should work with both single line (//) comments, and multi-line (/* */) comments. + A...

  • C++. Use <iostream>, using namespace std; Please Allow a user to enter a set of one-word...

    C++. Use <iostream>, using namespace std; Please Allow a user to enter a set of one-word string and character pairs until they type "Done". For each pair, calculate how many of that character exists in that string and print out the resulting count. Write a user-defined function (not main) with two parameters. The first parameter is a one-word string, the second parameter is a character The function returns an integer specifying how many times that character is found in the...

  • #include <iostream> using namespace std; bool binarySearch(int arr[], int start, int end, int target){ //your code...

    #include <iostream> using namespace std; bool binarySearch(int arr[], int start, int end, int target){ //your code here } void fill(int arr[], int count){ for(int i = 0; i < count; i++){ cout << "Enter number: "; cin >> arr[i]; } } void display(int arr[], int count){ for(int i = 0; i < count; i++){ cout << arr[i] << endl; } } int main() { cout << "How many items: "; int count; cin >> count; int * arr = new...

  • #include <iostream> using namespace std; - // Guess the output for the below program. // Assume...

    #include <iostream> using namespace std; - // Guess the output for the below program. // Assume address of a,b,c as 4004, 4008, 4016 respectively. int main() { float a = 12.5; int b = 10; double c = 3.1412; float aptr = &a; int *bptr = &b; double *cptr = &c; cout << "value of variable a,b,c:"<< a <<""<<b<<""<<<<<endl; cout << "Address of variable a,b,c:"<<&a<<""<<&b<<""<<&c << endl; cout << "value of aptr, bptr, cptr:" << aptr <<""<<bptr <<"" << cptr...

  • #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int...

    #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int charcnt(string filename, char ch); int main() { string filename; char ch; int chant = 0; cout << "Enter the name of the input file: "; cin >> filename; cout << endl; cout << "Enter a character: "; cin.ignore(); // ignores newline left in stream after previous input statement cin.get(ch); cout << endl; chcnt = charcnt(filename, ch); cout << "# of " «< ch« "'S:...

  • c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input:...

    c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input: an int output: boolean function: Return true if the number is a prime number and return false otherwise */ //TO DO ************************************** /* Write a function checkPrime such that input: an array of int and size of array output: nothing function: Display the prime numbers of the array */ //TO DO ************************************** /* Write a function SumofPrimes such that input: an int output: nothing...

  • 4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std;...

    4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....

  • #include <iostream> using namespace std; int main() {    } Write a program that, given a...

    #include <iostream> using namespace std; int main() {    } Write a program that, given a user-specified integer, prints out the next 10 integers (in increasing order; each on its own line). For example, given an input of 3, the console content following a run of the completed program will look as follows: Enter a number: 3 4 5 6 7 8 9 10 11 12 13

  • what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...

    what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...

  • #include <iostream> using namespace std; int main() {} Write a program that produces a line comprised...

    #include <iostream> using namespace std; int main() {} Write a program that produces a line comprised of n alternating a's and b's, where n is user-specified. For example, the console content following a run of the completed program with an input of "5" is as follows: Enter a number: 5 A line of length 5: ababa

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT