-->
当前位置:首页 > 题库

PROGRAMMING:Simulation Implementation of set (class template)

Luz5年前 (2021-05-10)题库371
We can use a class to simulate set and set operation, add operation to increase set elements, delete operation to delete set elements, and find operation to find set elements. However, the type of set elements is unknown, which can be basic data types such as int, char, double, or object types such as string, time, student, etc, Class template is required to realize set and set operation, including the basic functions of adding, deleting and searching set elements.
The collection template class myset includes the following data:
T data[100];// Use the array to store all the collection elements, up to 100 elements
int count;// Represents how many elements are in the current collection
The member functions are as follows:
There are several constructors, and the set operation functions are as follows:
int addSet( T elem)
int deleSet(T elem)
int findElem(T elem)
Among them, addset adds an element to the collection, deleset removes an element from the collection, findelement judges whether element is a member of the collection, and three functions return the insertion position, deletion position and existence position of the element respectively.
The main function has the following data members:
MySet<\int>\ intSet;( Backslashes are escape characters, which are removed when used.)
MySet<\double>\ douSet;
MySet<\string>\ strSet;
They are the collection of int type, double type and string.
According to the input information, the main function establishes three different types of initial empty set objects, calls the member functions to perform corresponding operations on intset, douset and strset, and outputs the corresponding set information.
Input format:
Each line has a set operation. The first number of each line is set element type, 1 is integer element, 2 is floating point element, 3 is string type. The second number is set operation type, 1 is insert, 2 is delete, 3 is search, and the third is set element. The set element type depends on the set element type given by the first number. Enter 0 to mark the end of input.
Output format:
Output the execution position (insert position, delete position and exist position) of the current operation
When deleting, if element X does not exist, output "x is not exist!".
When inserting, if the set is full, output "full set." if the element already exists, output "x is already exist!"
If the element cannot be found in the lookup operation, the output "x is not exist!".
Input:
1 1 1
1 1 2
1 3 1
1 2 1
1 2 3
1 3 1
2 1 1.1
2 1 2.2
2 1 3.3
2 3 1.1
2 2 2.2
2 2 2.2
3 1 abc
3 1 bcd
3 3 abc
3 2 abc
3 3 abc
0
Output:
0
one
0
0
3 is not exist!
1 is not exist!
0
one
two
0
one
2.2 is not exist!
0
one
0
0
abc is not exist!< br>





answer:If there is no answer, please comment