Here is a problem in C++: Problem: (40% of DD1; 20% of DD2) For this question: use C++20…
- User
Here is a problem in C++:
Problem:
(40% of DD1; 20% of DD2) For this question: use C++20 imports. Compile the system headers with g++20h and compile your files with g++20. In this question, you will implement a class that represents a mathematical set for integers using std::vector. The class definition and its associated method and function signatures have been given to you in the file IntSet.cc in your repository. You have also been given a test harness in a4q1.cc as the main function. Do not change it. Make sure you read and understand this code, as you will need to know what it does in order to structure your test suite. It isn’t very robust and does no error-checking. You are allowed to assume that the commands it receives are valid, so do not write test cases for it! Implement the described IntSet methods and functions. Your implementation must satisfy the following require- ments: • A set cannot contain duplicate items. Attempting to add an item already in the set does not change the set nor does it produce an error (see add and operator&). • Set intersection (operator&) returns a new set containing only the elements that are in both sets. • Set union (operator|) returns a new set containing all of the elements from both sets, without any duplicates. • Two sets A and B are equal (operator==) if and only if no element of one is not an element of the other. More precisely: (∄xs.t.x ∈A ∧x /∈B) ∧(∄xs.t.x ∈B ∧x /∈A). • i1.isSubset( const IntSet & i2 ) returns true if and only if every element in i2 is an element of the set i1: otherwise it returns false. • i.contains( int e ) returns true if e is an element of the set i: otherwise it returns false. • After i.remove( int e ) is called, e must not be in the set i. • The input operator (operator>>) adds the read-in integers to the set until a non-integer value is read. The first non-integer character is thrown away. • The output operator (operator<<) first prints a left parenthesis ’(’, then each integer in added order, delim- ited by a space, and ends with a right parenthesis ’)’. For example the set containing 3, 5, and 2 is printed as ( 3 5 2 ). An empty set is printed as ( ). (a) Due on Due Date 1: Design a test suite for this program. Submit a file called a4q1a.zip that contains the test suite you designed, called suiteq1.txt, and all of the .in and .out files.
Interface File
export module intset;
import ; import ;
export class IntSet { std::vector data;
public:
class Iterator { public: int operator*() const { return data->at(pos); } Iterator& operator++() { pos++; return *this; } bool operator!=(const Iterator & it) const { return pos != it.pos; } friend class IntSet; private: Iterator(const std::vector<int> *data, size_t pos): data{data}, pos{pos} {} const std::vector<int> *data; size_t pos; }; IntSet* operator|( const IntSet & i ) const; // Set union. IntSet* operator&( const IntSet & i ) const; // Set intersection. bool operator==( const IntSet & i ) const; // Set equality. bool isSubset( const IntSet & i ) const; // True if i is a subset of "this". bool contains( int e ) const; // True if "this" contains element e. void add( int e ); // Adds element e to "this". void remove( int e ); // Removes element e from "this". Iterator begin() const; Iterator end() const; - Assistant