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

To design, develop and test a user defined class in the C++ programming language

ID: 3834164 • Letter: T

Question

To design, develop and test a user defined class in the C++ programming language. Procedure: Use the necessary UNIX commands to create a new directory (folder) within your CISC2000 directory which will be the parent directory for all the assignments listed below. Change directory into this new directory. Implement the Set class and write a main driver program to allow for the instantiation of multiple set objects. The driver program should show correct use of each of the implemened set operations. Your program should: Instantiate several objects of class Set. Sole that objects should be constructed using each of the constructors implemented. 2. Apply each of the set operations {+, ^, -, ", !=} on the objects created. Show that new elements can be added to existing sets using the + operator. Show that elements can be removed from existing sets using the - operator. Note that each lime the set is altered in any way, the set should be displayed to show the operation was successful. The definition of the Set class should be in an individual header (.h) file and the implementation of the class's methods should be in an individual source (.cpp) file. You can write a simple main function within the, cpp file of the class for the purpose of toting your class, however, the main driver program should be in its' own individual source (cpp) file. AW that if you write a lest main in the class cpp file, you will need to comment it out before you can link it with the main driver Challenge Allow for an array of (some number of) dynamically allocated sets to be created and provide a user interface that allows the user to: create new set, delete an existing set, add an element to an existing set, delete an clement from an existing set, and apply any of the set operations on any existing set, Allow the user to specify the set operation to apply as an equation. Example, assume three sets have been created |A, B, C}, the user should be able to input the operation to be performed as: A + B A-B C^B Note that each time an operation is performed a new set is created and should be stored as the next element of the array of sets. Due by Friday, May 5th, Create a template class definition for the Set class implemented above and w rite a main daiCI program to allow for the instantiation of objects from multipe class specializations. The driver program should show that the set operations work correctly for each class specialization.

Explanation / Answer

implementation file: Point.cpp

Test Driver: TestPoint.cpp:

  #include "Point.h"  #include <iostream>  using namespace std;     // Constructor - The default values are specified in the declaration  Point::Point(int x, int y) : x(x), y(y) { }     // Getters  int Point::getX() const { return x; }  int Point::getY() const { return y; }     // Setters  void Point::setX(int x) { this->x = x; }  void Point::setY(int y) { this->y = y; }     // Public Functions  void Point::setXY(int x, int y) { this->x = x; this->y = y; }     void Point::print() const {     cout << "Point @ (" << x << "," << y << ")";  }  

Test Driver: TestPoint.cpp:

  #include "Point.h"  #include <iostream>  using namespace std;     int main() {     // Instances (Objects)     Point p1;       // Invoke default constructor                     // OR Point p1 = Point(); NOT Point p1();     Point p2(2, 2); // Invoke constructor                     // OR Point p2 = Point(2, 2);     p1.print();     // Point @ (0,0)     cout << endl;     p2.print();     // Point @ (2,2)     cout << endl;        // Object Pointers with dynamic allocation     Point * ptrP3, * ptrP4; // Declare two Point pointers     ptrP3 = new Point();    // Dynamically allocate storage via new                             // with default constructor     ptrP4 = new Point(4, 4);     ptrP3->print();  // Point @ (0,0)                      // prtPoint1->print() is the same as (*ptrP3).print()     cout << endl;     ptrP4->print();  // Point @ (4,4)     cout << endl;        delete ptrP3;    // Remove storage via delete     delete ptrP4;        // Object Reference (Alias)     Point & p5 = p2; // Reference (alias) to an existing object     p5.print();      // Point @ (2,2)     cout << endl;        /********************      * ARRAYS           *      ********************/        // Array of Objects - Static Memory Allocation     Point ptsArray1[2];     // Array of Point objects                             // Use default constructor for all elements of the array     ptsArray1[0].print();   // Point @ (0,0)     cout << endl;     ptsArray1[1].setXY(11, 11);     (ptsArray1 + 1)->print(); // Point @ (11,11)                               // same as ptsArray1[1].print()     cout << endl;        Point ptsArray2[3] = {Point(21, 21), Point(22, 22), Point()};                             // Initialize array elements via constructor     ptsArray2[0].print();   // Point @ (21,21)     cout << endl;     (ptsArray2 + 2)->print(); // Point @ (0,0)                               // same as ptsArray2[2].print()     cout << endl;        // Array of Object Pointers - Need to allocate elements dynamically     Point * ptrPtsArray3 = new Point[2];     ptrPtsArray3[0].setXY(31, 31);     ptrPtsArray3->print();  // Point @ (31,31)                             // same as ptrPtsArray3[0].print()     cout << endl;     (ptrPtsArray3 + 1)->setXY(32, 32); // same as ptrPtsArray3[1].setXY(32, 32)     ptrPtsArray3[1].print();           // Point @ (32,32)     cout << endl;        delete[] ptrPtsArray3; // Free storage        // C++ does not support Array of References  // Point & pts[2] = {p1, p2};  // error: declaration of 'pts' as array of references  }  
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote