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

// -*- mode: c++ -*- #ifndef _WCSET_H_ #define _WCSET_H_ #include namespace cs25

ID: 3591840 • Letter: #

Question

// -*- mode: c++ -*-

#ifndef _WCSET_H_

#define _WCSET_H_

#include

namespace cs251 {

template

class wcset{

public: // constructor -- makes an empty wcset

wcset(std::size_t initial_capacity=30);

// big 5

wcset(const wcset& other);

wcset(wcset&& other);

wcset& operator=(const wcset& other);

wcset& operator=(wcset&& other);

virtual ~wcset();

// Return the number of items in this wcset

std::size_t size() const;

// Return true if item is in wcset, false otherwise

bool contains(ValueType item) const;

// Insert a new item into this wcset, if it is not already there

// Precondition: used < CAPACITY

void insert(ValueType item);

// Remove an item from this wcset (if it is present), return true if

// the item was in this wcset and false otherwise.

bool remove(ValueType item);

// If item is in this wcset and replacement is not, replace item

// with replacement. If both item and replacement are in this

// wcset, remove item (since we can't have two copies of

// replacement in this wcset). Otherwise do nothing to this wcset.

// Return true if this wcset was modified, false otherwise.

bool replace(ValueType item, ValueType replacement);

// Wcset union, see +

void operator +=(const wcset& other);

// Two wcsets are equal if and only if they contain the same

// elements. Note: This is a member function!

bool operator ==(const wcset& other);

private:

ValueType *data;// The array to store items

std::size_t used; // How much of array is used

std::size_t capacity; // current array capacity

};

// Wcset union. x is in s1 + s2 if and only if x is in s1 or x is in

// s2. Note: not a member function!

template

wcset operator +(const wcset& s1, const wcset& s2); }

#include "wcset_impl.hpp" #endif /* _WCSET_H_ */

Explanation / Answer

ifndef _WCSET_H_

#define _WCSET_H_

#include

namespace cs251 {

template

class wcset{

public: // constructor -- makes an empty wcset

wcset(std::size_t initial_capacity=30);

// big 5

wcset(const wcset& other);

wcset(wcset&& other);

wcset& operator=(const wcset& other);

wcset& operator=(wcset&& other);

virtual ~wcset();

// Return the number of items in this wcset

std::size_t size() const;

// Return true if item is in wcset, false otherwise

bool contains(ValueType item) const;

// Insert a new item into this wcset, if it is not already there

// Precondition: used < CAPACITY

void insert(ValueType item);

// Remove an item from this wcset (if it is present), return true if

// the item was in this wcset and false otherwise.

bool remove(ValueType item);

// If item is in this wcset and replacement is not, replace item

// with replacement. If both item and replacement are in this

// wcset, remove item (since we can't have two copies of

// replacement in this wcset). Otherwise do nothing to this wcset.

// Return true if this wcset was modified, false otherwise.

bool replace(ValueType item, ValueType replacement);

// Wcset union, see +

void operator +=(const wcset& other);

// Two wcsets are equal if and only if they contain the same

// elements. Note: This is a member function!

bool operator ==(const wcset& other);

private:

ValueType *data;// The array to store items

std::size_t used; // How much of array is used

std::size_t capacity; // current array capacity

};

// Wcset union. x is in s1 + s2 if and only if x is in s1 or x is in

// s2. Note: not a member function!

template

wcset operator +(const wcset& s1, const wcset& s2); }

#include "wcset_impl.hpp" #endif /* _WCSET_H_ */