Question

C++ Programming

Create a set class. Implement the set operators: u, n-Δ and boolean functions to test for OS, and C. Implement functions to add members to a set, delete members from a set, and display a set. Be sure to test all functions

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

C++ PROGRAM:

#include <iostream>
#include <set>
#include <iterator>
using namespace std;
class setClass
{
set <int> elements;
int values;
public:
setClass()
{
}
void setMethod(int val, set <int> elem)
{
values=val;
elements = elem;
}
int getMethod()
{
return values;
}
set<int> getSetMethod()
{
return elements;
}
bool addMembers()
{
set <int> ::iterator itr;
for (itr = elements.begin(); itr != elements.end(); ++itr)
{
if (*itr == values)
{
return false;
exit(0);
}
}
  
return true;
}
bool delMembers(int val)
{
set <int> ::iterator itr;
for (itr = elements.begin(); itr != elements.end(); ++itr)
{
if (*itr == val) {
return true;
exit(0);
}
}
  
return false;
}
void display(set<int>setter)
{
set <int> ::iterator itr;
cout << "\nThe set values is : ";
for (itr = setter.begin(); itr != setter.end(); ++itr)
{
cout << '\t' << *itr;
}
cout << endl;
}

};
int main()
{
set <int> setter;
setClass s;
int val,choice=1,op;
cout << " WELCOME TO SET GENERATION PROGRAM " << endl;
while (choice == 1)
{
cout << "Your options:\n1.Press 1 for 'add' elements in set\n2.Press 2 for 'Delete' elements from set\n3.Press 3 for diplay set\n4.Press 4 to exit" << endl;
cout << "please enter your option:";
cin >> op;
switch (op)
{
case 1:
cout << "enter the integer to add:";
cin >> val;
s.setMethod(val, setter);
if (s.addMembers() == 1) {
setter.insert(val);
cout << "The element is added successfully." << endl;
}
else {
cout << "The element is already present."<<endl;
}
break;
case 2:
cout << "enter the integer to delete:";
cin >> val;
s.setMethod(val, setter);
if (s.delMembers(val) == 1) {
setter.erase(val);
cout << "The element is deleted." << endl;
}
else {
cout << "The element is not present."<<endl;
}
break;

case 3:
s.display(setter);
break;
  
case 4:
choice = 0;
exit(0);
break;
}
}
  
}

OUTPUT:

WELCOME TO SET GENERATION PROGRAM our options: 1.Press 1 for add elements in set 2. Press 2 for Delete elements from set 3. Press 3 for diplay set 4. Press 4 to exit lease enter your option:1 enter the integer to add:24 e element is added successfully. our options: ●Press 1 for add elements in set 2. Press 2 for Delete elements from set 3. Press 3 for diplay set 4. Press 4 to exit lease enter your option:1 enter the integer to add: 56 e element is added successfully. our options: 1.Press 1 for add elements in set 2. Press 2 for Delete elements from set 3. Press 3 for diplay set 4. Press 4 to exit lease enter your option:1 enter the integer to add: 68 e element is added successfully.

Add a comment
Know the answer?
Add Answer to:
C++ Programming Create a set class. Implement the set operators: u, n-Δ and boolean functions to...
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
  • Programming: Create a class called City with two public variables: a string to store the name...

    Programming: Create a class called City with two public variables: a string to store the name of the city and a float to store the average temperature in Fahrenheit. Create one object of the class that you create and ask the user to enter the city name and the average temperature in Fahrenheit. Store these in the object of the class that you create. Then display the contents of the class. Once that is working, make the variables private and...

  • In C# programming. Create a fractions class that represents fractions in the form a/b Your class...

    In C# programming. Create a fractions class that represents fractions in the form a/b Your class should implement the following members: int Numerator int Denominator Fraction(int numerator, int denominator) ­ creates a new Fraction double ToDecimal() ­ returns the fraction as a double Fraction Add(Fraction f) ­ adds the fraction to the one passed in and simplifies the result Fraction Multiply(Fraction f) ­ multiplies the fraction by the one passed in and simplifies the result Fraction Simplify() ­ simplifies the...

  • JAVA Programming MagicSet. Write a class that represents a set. Recall that a set has the...

    JAVA Programming MagicSet. Write a class that represents a set. Recall that a set has the following properties it does not contain duplicates and order is not important. If you are unable to make a class that can use any type (generics), make your set handle whole numbers. You must implement your set using an array. The amount of storage used should grow and shrink as needed: it should be halved if the array is 25% full and doubled when...

  • Java programming 1. (Triangle class) Design a new Triangle class that extends the abstract GeometricObject class....

    Java programming 1. (Triangle class) Design a new Triangle class that extends the abstract GeometricObject class. Draw the UML diagram for the classes Triangle and GeometricObject and then implement the Triangle class. Write a test program that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate whether the triangle is filled. The program should create a Triangle object with these sides and set the color and filled properties using the input....

  • C++: Create a class called "HashTable" This class will implement hashing on an array of integers...

    C++: Create a class called "HashTable" This class will implement hashing on an array of integers Make the table size 11 Implement with linear probing. The hash function should be: h(x) = x % 11 Create search(), insert() and delete() member functions. Search should return the index of where the target is located, insert should allow the user to insert a value, and delete removes the desired value from the table. In main perform the following: 1. Insert: 17 11...

  • OBJECT ORIENTED PROGRAMMING C++ B- The programming section has 2 parts: Part 1 - Create a...

    OBJECT ORIENTED PROGRAMMING C++ B- The programming section has 2 parts: Part 1 - Create a class - (35 points) Create a class called CustomDressInvoice. It should have 5 data members: designTime (int), designRate (int), sewing Time (int), sewingRate (int), and materialsCost. The invoice amount is calculated with this formula: Invoice Amount = (designTime * designRate) + (sewingTime * sewing Rate) + materialCost All times are charged by the hours, and rates are charged by the dollars (no cents). The...

  • Write a program in C++ that uses a class template to create a set of items....

    Write a program in C++ that uses a class template to create a set of items. . . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of...

  • C PROGRAMMING Create two void functions that 1) delete a specific value in a linked list...

    C PROGRAMMING Create two void functions that 1) delete a specific value in a linked list and 2) delete all instances of that value. Both functions' only parameter is the number that will be erased.

  • 4.a) 4.b> 4.c) C++ Programming Lab Exercise 09 Inheritance. Friend Functions, and Polymorphism (virtual functions) 4.a)...

    4.a) 4.b> 4.c) C++ Programming Lab Exercise 09 Inheritance. Friend Functions, and Polymorphism (virtual functions) 4.a) Run the following code and observe the output. #include <iostream> #include <string> using namespace std; class Vehicle public: void print() { cout << "Print: I am a vehicle. \n"; } void display() { cout << "Display: I am a vehicle. \n"; } }; class Car: public Vehicle { public: void print() { cout << "Print: I am a car.\n"; } void display() { cout...

  • In C++ - Learn how to implement linked lists Part 1 Node and Linked List Class...

    In C++ - Learn how to implement linked lists Part 1 Node and Linked List Class (50 pts): Create node with public properties: Block type block and block ptr next. Create a linked list class that uses the node you generated without an add or delete method with a head and optional tail and counter. Make a driver that generates a node to test your implementation. Part 2 Add Method (30 pts): Create an add method in your linked list...

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