Please give an answer which works to print the answer given below. Please use the necessary header .h and .cpp files. Please give the right solution. "ITS MY HUMBLE REQUEST TO GIVE THE RIGHT SOLUTION"
Question 2 – Creating and working with other Containers
A Set is a data structure which contains information on whether a value belongs to
that set or not. In this question, you have to implement an integer Set which is able
to tell whether an integer is a member of that Set or not. For this question our set
can only contain the numbers 0..9. Because our list of possible members is small we
can represent the Set by a Boolean map where we have an array, called content,
with 10 elements. If the integer i is in the set then content[i] is true, otherwise it is
false. Thus if the set contains the number 3 then content[3] is true. If the set doesn’t
contain the number 8 then content[8] is false. In this question, our set starts out
empty - it contains no members.
Create a Set class in Set.cpp and Set.h implement the following functions:
Constructor – makes the set empty by setting all elements of content to false.
add(int val) – ensures that the set contains element val by setting the
corresponding element of content to true. If val is outside the range of 0..9
then add does nothing.
remove(int val) – ensures that the set does not contain the element val. If val
is outside the range 0..9 then val does nothing.
in(int val) returns true if val is in the set and false otherwise. If val is outside
the range 0..9 then in() returns false.
With the correct implementation of the class file above the q2main.cpp file
should print:
members
1 is member
3 is member
5 is member
7 is member
members
2 is member
4 is member
7 is member
8 is member
/*
C++ program that demonstrates the Set class methods
*/
//main.c
//include header files
#include<iostream>
//include Set.h header file
#include "Set.h"
using namespace std;
int main()
{
//Create a Set class
object
Set set;
//Add 1,3,5,7 to set
set.add(1);
set.add(3);
set.add(5);
set.add(7);
cout<<"members"<<endl;
//print only set elements
for(int index=0;index<10;index++)
if(set.in(index))
cout<<index<<" is member"<<endl;
//Create a Set class object
Set set2;
cout<<"members"<<endl;
//Add2,4,7,8
set2.add(2);
set2.add(4);
set2.add(7);
set2.add(8);
//print only set elements
for(int index=0;index<10;index++)
if(set2.in(index))
cout<<index<<" is member"<<endl;
//pause program output on
console
system("pause");
return 0;
}
--------------------------------------------------------------------------------------------------
//Set.h
#ifndef SET_H
#define SET_H
//Class Set declaration
class Set
{
private:
//an array of boolean type of
size,10
bool contents[10];
public:
//constructor
Set();
//Methods
void add(int val);
void remove(int val);
bool in(int val);
};
#endif SET_H
--------------------------------------------------------------------------------------------------
//Set.cpp
//Implementation file
#include<iostream>
#include "Set.h"
//Constructor to false to all contents array
Set::Set()
{
int index=0;
for(index=0;index<10;index++)
contents[index]=false;
}
//add method to set val to the corresponding value in
contents array
void Set::add(int val)
{
if(val>=0 && val<10)
contents[val]=true;
}
//remove method to set val false to the corresponding value
in contents array
void Set::remove(int val)
{
if(val>=0 && val<10)
contents[val]=false;
}
//in method that returns true if the val is in the set
otherwise return false
bool Set::in(int val)
{
if(val>=0 && val<10)
{
if(contents[val])
return
true;
else
return
false;
}
}
--------------------------------------------------------------------------------------------------
Sample Output:
Please give an answer which works to print the answer given below. Please use the necessary...
Intro to java project template with instructions below * IntegerSet.java */ /** * * @author StudentName */ public class IntegerSet { /** * Creates a new instance of IntegerSet */ // TODO: implement the constructor /** * Return a new IntegerSet containing the union of the two IntegerSet objects * passed as arguments */ // TODO: implement the union method /** * Return a new IntegerSet containing the intersection of the two IntegerSet objects * passed...
c++ Please create Set.cpp and Set.h The following information is needed (setinterface.h) Class Set You are given an interface: SetInterfac This is a public interface and completely specifies what the Set class operations must be. SetInterface is an abstract class (it has no implementation), so your Set class must inherit from SetInterface and implement all of its methods. Set differs in the fact that it does not allow duplicates. This also means that add()must check that an element is not...
Given the Following Fucntions, Give the Space and time analysis for each function void DELETE(vector < char > myArray[90], string myLine)//deletes the specified member from the set { //compares the specified member to each member in the set for (int i = 0: i < myArray[myLine[9]].size(): i++)//if the member is found it is erased { if (myLine[7] == myArray[myLine[9]][i]) { myArray[myLine[9]].erase(myArray[myLine[9]].begin() + (i)): } } void PRINTSET(vector < char > myArray[90], string myLine, ofstream &outs)//prints the members of the specified...
//Look for** to complete this program --C+ please --please add comments // using namespace std; #include <iostream> #include <stdlib.h> #include < string> #include "queue.h" //Purpose of the program: ** Algorithm: * int main() /** "A", "B", "C" in the queue //** while loop -- indefinitely { try {//** catches } //* end of loop } |/ II II II II II //File type: ** queue.cpp using namespace std; #include <iostream> #include "queue.h" // constructor queue::queue () } //destructor queue::~queue() queue::queue...
Write the C module intSet to implement an unordered set of integers according to the specification given below. File intSet.h (downloadable off the class web pages): #ifndef INTSET_H #define INTSET_H typedef struct intsetType *intSet; intSet createSet(); // returns an intSet created at runtime using malloc void destroySet(intSet); // frees up the memory associated with its argument void clear(intSet); // clears set to empty (freeing any memory if necessary) int card(const intSet); // returns the cardinality of the set bool equals(const...
Write the C module intSet to implement an unordered set of integers according to the specification given below. File intSet.h: #ifndef INTSET_H #define INTSET_H typedef struct intsetType *intSet; intSet createSet(); // returns an intSet created at runtime using malloc void destroySet(intSet); // frees up the memory associated with its argument void clear(intSet); // clears set to empty (freeing any memory if necessary) int card(const intSet); // returns the cardinality of the set bool equals(const intSet,const intSet); // returns true if...
117% Question 1: Linked Lists Create an IntLinkedList class, much like the one presented in class. It should implement a linked list that will hold values of type int. It should use an IntNode class to implement the nodes in the linked list. The linked list must have the following methods: . A constructor with no parameters which creates an empty list. . void add (int data) -adds data to the front of the list. .A constructor IntlinkedList(int[]) which will...
Java help! Please help complete the min method below in bold. import java.util.Arrays; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /** * Provides an implementation of a binary search tree * with no balance constraints, implemented with linked nodes. * * * */ public class Bst<T extends Comparable<T>> implements Iterable<T> { ////////////////////////////////////////////////////////////////// // I M P L E M E N T T H E M I N M E T H O D B E L O W...
Complete the implementation of the LinkedStack class presented in Chapter 13. Specifically, complete the implementations of the peek, isEmpty, size, and toString methods. See Base_A06Q1.java for a starting place and a description of these methods. Here is the base given: /** * Write a description of the program here. * * @author Lewis et al., (your name) * @version (program version) */ import java.util.Iterator; public class Base_A06Q1 { /** * Program entry point for stack testing. * @param args Argument...
1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...