Advertisement
prprice16

Set_Classwork

Nov 17th, 2021
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #pragma once
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class DSet
  6. {
  7. private:
  8.     double* list;   //a pointer for the array
  9.     int size;       //number of values stored
  10. public:
  11.     DSet();         //default constructor
  12.     int getSize();  //return the number of elements
  13.  
  14.     void add(double);   //adds a value to list
  15.     ~DSet();
  16.     friend ostream& operator<<(ostream&, DSet);
  17.  
  18.     bool contains(double);
  19. };
  20.  
  21. //FUNCTION DEFINITIONS
  22.  
  23. //Code default constructor
  24. DSet::DSet()
  25. {
  26.     //what code goes here?
  27.     //list is initially empty
  28.  
  29.  
  30.  
  31. }
  32.  
  33. int DSet::getSize()
  34. {
  35.     //return the number of elements in the set
  36.  
  37.  
  38. }
  39.  
  40. void DSet::add(double val)
  41. {
  42.     //add val as the next element of list
  43.     //need to allocate memory 1 bigger than current size
  44.     double* newlist =     ; //???
  45.  
  46.     //copy values from list to newlist
  47.  
  48.  
  49.     //add val as last value
  50.  
  51.  
  52.     //update size
  53.  
  54.  
  55.     //delete old list
  56.  
  57.  
  58.     //make new list the list
  59.  
  60.  
  61. }
  62.  
  63. //destructor
  64. DSet::~DSet()
  65. {
  66.     //release memory
  67. }
  68.  
  69. ostream& operator<<(ostream& out, DSet obj)
  70. {
  71.     //print each value separated by a space
  72.  
  73.  
  74.    
  75.  
  76. }
  77.  
  78.  
  79. bool DSet::contains(double val)
  80. {
  81.     //return true if val is in the list
  82.     //otherwise return false
  83.  
  84.  
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement