Need help creating c++ set class?

 Dont Buy Textbooks. Rent 'EM Save 60-80%



I'm creating a new class for c++ based on Set theory. I was given Set.h and have to create Set.cpp. I need help with the cardinality function. I'm uncertain how to do it. Here is the program:

#include <iostream>

#include "Set.h"

// Constructor, sets _cardinality to zero

Set::Set(){

_cardinality=0;

}

// returns true if its argument is an element of the set

bool Set::isElement(const int num) const{

for(int i=0; i<_cardinality; i++){

if(_element[i]==num){

return true;

}

else{

return false;

}

}

}

// adds the argument to the set

void Set::add( int num){

for(int i=0; i< _cardinality; i++){

if(_element[i]==num){

return;

}

else{

_element[_cardinality]=num;

_cardinality++;

i++;

}

}

}

// removes the element from the set

void Set::remove(int num){

for(int i=0; i< _cardinality; i++){

if(_element[i]!=num){

return;

}

else if(_cardinality==1){

clear();

}

else{

_element[i]=_element[i+1];

_cardinality--;

}

}

}

// resets cardinality to zero (effectively emptying the set)

void Set::clear(){

for(int i=0; i<_cardinality-1; i++){

_element[i]=0;

}

}

// returns the cardinality of the set



More Related Questions and Answers ...
  • A.w/c set of real # includes pos.intergers bu..
  • Warm in one room with A/C on and set at 75?
  • Set A has a members and set B has b mmbers. S..
  • If set A is a proper subset of setB and set B..
  • How do I set up the 8085 microprocessor to su..
  • Chanel Double C earing and necklace set????
  • Please turn off your A/C or set it to 78F?
  • How to define a well-order in C(set of comple..
  • What&#039;s your a/c set at?
  • Who is Responcible in a Corporation C set-up?
  • The Set B,C Maths Papers of SSC06-07 were Tou..
  • Help i set my c drive to dirty.I dont know wh..
  • How to re-set P.C back in time to recover los..
  • How do I &#039;chord&#039; a song for..
  • You&#039;re given three sets A, B,and C. ..
  • How to write out all k-element subsets of n-e..
  • I have my a/c set to 15 degrees celcius and i..
  • Any tips on taking the C-SET?
  • 2001 Honda Civic A/C stays on when set to def..

  • The information post by website user , we not guarantee correctness.

    

    Dental Treatment Skin Whitening Skin Problems Skin Rashes Shoes