Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design and write a C++ class (Also please leave comments in the code to explain

ID: 667502 • Letter: D

Question

Design and write a C++ class (Also please leave comments in the code to explain what each code does) that implements a Set abstract data type and a menu-driven program that exercises the class. A typedef statement will identify the type of Items in the class's Sets. The program will manipulate sets of integers.

The program will maintain an array of three sets, identified by the integers 0, 1, and 2, and it will call class functions to carry out operations on the sets.

INPUT

The program will be interactive; it will respond to commands entered by the user.

OUTPUT

The program will prompt for inputs and will report the contents of sets in response to the user's commands.

ERRORS

The program should ignore non-command letters.

EXAMPLE

A run of the program might look like this:

OTHER REQUIREMENTS

In a class, implement a Set abstract data type whose values are sets of Items, with member functions corresponding to the operations listed in the example's menu:

A default constructor that initializes a newly declared Set to be empty.

A function that re-initializes a Set to be empty.

A function that inserts a value into a Set. If the Set already contains that value, the Set is unchanged.

A function that removes a value from a Set. If the Set does not initially contain the value, the Set is unchanged.

A function that forms the union of two Sets. It should be possible to assign that union to one of the original Sets.

A function that reports the size of a Set.

A function that reports if a value is present in a Set.

A function that writes the contents of a Set (in any order) to the terminal.

In the client program, use a constant to set the number of sets the program will manipulate.

HINTS

In each operation, consider the empty set.

The menu will be printed by a function in the client program.

Question: How might a function work that identifies the intersection of two Sets? If you like, you can include such a function in your class and exercise it in the program.

Explanation / Answer

For impleenting the Set functions of insert ,delete ,modify etc we can use the <set> interface which is already provided in the C++. Henceforth we can modify it the same acording to our use.

Below are the list of the member functions asked :

Class Set{

Set() { //Constructor initialized with zero elements in the set

myset.clear();

}

void InsertFunc() {

}

std::cout << "myset contains:";

}

To delete the specific element from the array we have the function:

void Delete() {

int a; //We have the variable which store the value of the number to be deleted from the set

cout<<"Enter the element to be deleted";

cin>>a;

myset.erase(a); //Erase is the standarad function that delete the element from the list.

std::cout << "myset contains:";

}

To find the size of the set we have size() function that count the number of the element in the container.

void DispSize() {

}

To destroy all the element from the set we have clear() .

Void Destroy() {

myset.clear();

}

}

After the clearing the value we have print the set to check whether there are more element in the set or not.

I have declared the [std::set<int> myset] statement in each and every part of the function.Generally it should be the global set declaration because the set value will be thoroughly used in all the part of the function.

Therefore it should be declared outside and can be implemented with any number of the set variables.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote