
Below are the screenshots of code & output:



Below is the C++ code for same. Besides implementing the set class with the required methods, it is also tested for the given data types as well as with simple class objects.
1.) set.h
#include<iostream>
using namespace std;
/**sample test class for testing set**/
class testClass{
public:
string data;
testClass(){
}
testClass(string name){
data =
name;
}
void operator=(const testClass
&t){
data=t.data;
}
bool operator==(const testClass
&t){
return
(data==t.data);
}
};
/**templated set class**/
template<typename T>
class set{
int size;/**storeds size of set**/
T* elements;/**dynamic pointer to set items**/
public:
set(){
size=0;/**initializing size**/
}
/**method to add item to
set**/
void add(T element){
for(int i = 0 ;
i < size ; i++)/**if this element is duplicate return**/
if(elements[i]==element)
return;
T
temp[size];/**temporary array to store previous values**/
for(int i = 0 ;
i < size; i++)
temp[i]=elements[i];
elements=new
T[++size];/**reallocating new array of incremented size**/
for(int i = 0 ;
i < size-1; i++)
elements[i]=temp[i];/**recopying the previous elements
back**/
elements[size-1]=element;/**adding new element**/
}
/**method to get size of
set**/
int getNumberOfElements(){
return
size;
}
/**method to get dynamic pointer to
set**/
T* getItemSet(){
return
elements;
}
};
2.) main.cpp
#include"set.h"
int main(){
/**Test case 1: testing for integers**/
cout<<"---Example 1: Set of
integers---\n";
cout<<"================================\n";
set<int> integerSet = set<int>();
cout<<" "<<" Adding:
10\n";integerSet.add(10);
cout<<" "<<" Adding:
5\n";integerSet.add(5);
cout<<" "<<" Adding:
15\n";integerSet.add(15);
cout<<" "<<" Adding:
25\n";integerSet.add(25);
cout<<" "<<" Adding:
15\n";integerSet.add(15);
cout<<"--------------------------------\n\n";
int integerSetSize =
integerSet.getNumberOfElements();
int* integerSetPtr = integerSet.getItemSet();
cout<<"The first set has
"<<integerSetSize<<" items\nThey are:\n";
for(int i =0; i < integerSetSize; i++)
cout<<"\t"<<integerSetPtr[i]<<"\n";
delete integerSetPtr;
cout<<"\n================================\n";
/**Test case 2: testing for doubles**/
cout<<"---Example 2: Set of doubles---\n";
cout<<"================================\n";
set<double> doubleSet =
set<double>();
cout<<" "<<" Adding:
1.5\n";doubleSet.add(1.5);
cout<<" "<<" Adding:
5.6\n";doubleSet.add(5.6);
cout<<" "<<" Adding:
12.8\n";doubleSet.add(12.8);
cout<<" "<<" Adding:
1.5\n";doubleSet.add(1.5);
cout<<" "<<" Adding:
12.8\n";doubleSet.add(12.8);
cout<<"--------------------------------\n\n";
int doubleSetSize =
doubleSet.getNumberOfElements();
double* doubleSetPtr = doubleSet.getItemSet();
cout<<"The second set has
"<<doubleSetSize<<" items\nThey are:\n";
for(int i =0; i < doubleSetSize; i++)
cout<<"\t"<<doubleSetPtr[i]<<"\n";
delete doubleSetPtr;
cout<<"\n================================\n";
/**Test case 3: testing for strings**/
cout<<"---Example 3: Set of strings---\n";
cout<<"================================\n";
set<string> stringSet =
set<string>();
cout<<" "<<" Adding: John
Smith\n";stringSet.add("John Smith");
cout<<" "<<" Adding: John
doe\n";stringSet.add("John doe");
cout<<" "<<" Adding: John
Smith\n";stringSet.add("John Smith");
cout<<" "<<" Adding: John
black\n";stringSet.add("John black");
cout<<"--------------------------------\n\n";
int stringSetSize =
stringSet.getNumberOfElements();
string* stringSetPtr = stringSet.getItemSet();
cout<<"The third set has
"<<stringSetSize<<" items\nThey are:\n";
for(int i =0; i < stringSetSize; i++)
cout<<"\t"<<stringSetPtr[i]<<"\n";
delete stringSetPtr;
cout<<"\n================================\n";
/**Test case 1: testing for class objects**/
cout<<"---Example 4: Set of test class
objects---\n";
cout<<"================================\n";
set<testClass> testClassSet =
set<testClass>();
cout<<" "<<" Adding:
testclass(\"object1\")\n";testClassSet.add(testClass(string("object1")));
cout<<" "<<" Adding:
testclass(\"object2\")\n";testClassSet.add(testClass(string("object2")));
cout<<" "<<" Adding:
testclass(\"object2\")\n";testClassSet.add(testClass(string("object2")));
cout<<" "<<" Adding:
testclass(\"object1\")\n";testClassSet.add(testClass(string("object1")));
cout<<"--------------------------------\n\n";
int testClassSetSize =
testClassSet.getNumberOfElements();
testClass* testClassSetPtr =
testClassSet.getItemSet();
cout<<"The fourth set has
"<<testClassSetSize<<" items\nThey are:\n";
for(int i =0; i < testClassSetSize; i++)
cout<<"\t"<<testClassSetPtr[i].data<<"\n";
delete testClassSetPtr;
cout<<"\n================================\n";
}
what would be the solution code to this problem in c++? The Problem Write program that...
Please write below code in C++ using Visual
Studio.
Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) • Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 • Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the...
How to solve this Problem in C++
. The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the set...
Write a program in C++ that uses a class template to create a
set of items.
. . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of...
Question: C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to prov... C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to provide practice programming using structs and pointers. Your program will accept user input and store it in a dynamic array of structs. First, you will define a structure to describe a item to be bought. Your program will prompt the user for the initial size of the array. It will...
C ++ 1. Write down the missing code according to the comments. #include <cstdlib> #include <iostream> using namespace std; void fun1(int radius) { /* dynamic memory management */ double * dmptr; double circumference; /* add the code below to: - allocate a memory location for a double and nameless variable in heap and assign its address to the pointer - assign 3.14 to the variable in heap via the pointer....
In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....
Help in JAVA please Write a program that reads a list of students (first names only) from a file. It is possible for the names to be in unsorted order in the file but they have to be placed in sorted order within the linked list. The program should use a doubly linked list. Each node in the doubly linked list should have the student’s name, a pointer to the next student, and a pointer to the previous student. Here...
Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to...
In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation. Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature...
Using Visual Studio 2015, how would I code the following
Uodate button event handler in c#?
then displayed in the student list box. Create an interface as follows The initial form for the application should appear as follows Student Scores Students dd New. Lpdate Delete Ext To update, delete or add student information create the following form Enter Student Information Name Student ID MdtemRna Cancel Note: the Control Box property is set to false