( Only answer this if you can help me get a fully working program of everything
ID: 667576 • Letter: #
Question
( Only answer this if you can help me get a fully working program of everything here if not then don't bother my questions are very low and limited so I don't want to waste them. If you can produce a fully workign program then please read everything and explain all code) write a C++ class that implements a Set abstract data type and a menu-driven program that exercises the class. A typedef statement will identify the type of Items in the class's Sets. The program will manipulate sets of integers.
The program will maintain an array of three sets, identified by the integers 0, 1, and 2, and it will call class functions to carry out operations on the sets.
INPUT
The program will be interactive; it will respond to commands entered by the user.
OUTPUT
The program will prompt for inputs and will report the contents of sets in response to the user's commands.
ERRORS
The program should ignore non-command letters.
OTHER REQUIREMENTS
In a class, implement a Set abstract data type whose values are sets of Items, with member functions corresponding to the operations listed in the example's menu:
A default constructor that initializes a newly declared Set to be empty.
A function that re-initializes a Set to be empty.
A function that inserts a value into a Set. If the Set already contains that value, the Set is unchanged.
A function that removes a value from a Set. If the Set does not initially contain the value, the Set is unchanged.
A function that forms the union of two Sets. It should be possible to assign that union to one of the original Sets.
A function that reports the size of a Set.
A function that reports if a value is present in a Set.
A function that writes the contents of a Set (in any order) to the terminal.
In the client program, use a constant to set the number of sets the program will manipulate.
HINTS
In each operation, consider the empty set.
The menu will be printed by a function in the client program.
EXAMPLE
A run of the program might look like this:
csci2> sets
Enter a command according to this menu:
e n - Make set n empty.
i v n - Insert the value v in set n.
r v n - Remove the value v from set n.
u n1 n2 n3 - Assign the union of sets n1 and n2 to set n3.
s n - Report the size of set n.
p v n - Is value v present in set n?
w n - Write the contents of set n to the terminal.
h - See this menu.
q - Quit.
-> i 5 0
-> i 8 0
-> i 256 0
-> p 0
Set 0 = { 5, 8, 256 }
-> r 8 0
-> w 0
Set 0 = { 5, 256 }
-> w 2
Set 2 = { }
-> i 10 1
-> i 5 1
-> i 7 1
-> w 1
Set 1 = { 10, 5, 7 }
-> u 0 1 2
-> w 2
Set 2 = { 5, 256, 10, 7 }
-> s 2
Set 2 contains 4 values.
-> p 18 2
Set 2 does not contain 18.
-> q
Explanation / Answer
Array classclass array{
int arrA[MAX],location,item,nA;
int arrB[MAX],nB;
public:
array(){
location=0;item=0;nA=0;
nB=0;nM=0;
}
void init(); //initial data assignmentvoid traverse(); //process is display
void insert();
void del();
void search();
void sort();
void merge();
};
void array :: init()
{
clrscr();
cout<<" *****Initialize Array***** ";
int choice,i;
while(1){
cout<<" 1) Array A ";
cout<<"2) Array B ";
cout<<"3) Return ";
cout<<"Enter your choice : ";
cin>>choice;
switch(choice){
case 1 : cout<<" --Array A-- ";
cout<<"Total elements to be inserted : ";
cin>>nA;
for(i=0;i<nA;i++)
cin>>arrA[i];
break;
case 2 : cout<<" --Array B-- ";
cout<<"Total elements to be inserted : ";
cin>>nB;
for(i=0;i<nB;i++)
cin>>arrB[i];
break;
case 3 : goto end;
default : cout<<" Invalid Position ";
}
}
end:
}
void array :: traverse(){
clrscr();
cout<<" Display Process during traversing ";
int choice,i;
while(1){
cout<<" 1) Array A ";
cout<<"2) Array B ";
cout<<"3) Return ";
cout<<"Enter your choice : ";
cin>>choice;
switch(choice){
case 1 : cout<<" --Array A-- ";
for(i=0;i<nA;i++)
cout<<setw(5)<<arrA[i];
break;
case 2 : cout<<" --Array B-- ";
for(i=0;i<nB;i++)
cout<<setw(5)<<arrB[i];
break;
case 3 : goto end;
default : cout<<" Invalid Position ";
}
getch();
}
end:
}
/*All Operations Except Merging are performed on arrA*/void array :: insert(){
clrscr();
int i;
cout<<" *****Inserting Element***** ";
if(nA >= MAX){
cout<<" Array is Full Insertion Not Possible ";
goto end;
}
cout<<" Enter Location of insertion : ";
cin>>location;
location--;
if(location<0 || location>=nA)
{
cout<<" Invalid Position ";
goto end;
}
cout<<"Enter Item value to be inserted : ";
cin>>item;
for(i=nA-1;i>=location;i--){
arrA[i+1] = arrA[i];
}
arrA[location]=item;
nA++;
cout<<" Item is Inserted ";
end:
getch();
}
void array :: del(){
clrscr();
int i;
cout<<" *****Deleting Element***** ";
if(nA < 0){
cout<<" Array is Empty Deletion Not Possible ";
goto end;
}
cout<<" Enter Location of deletion : ";
cin>>location;
location--;
if(location<0 || location>=nA)
{
cout<<" Invalid Position ";
goto end;
}
cout<<" Item deleted is : "<<arrA[location];
for(i=location;i<nA;i++){
arrA[i] = arrA[i+1];
}
arrA[nA-1]=0;
nA--;
end:
getch();
}
void array :: search(){
clrscr();
int i,found=-1;
cout<<" *****Searching Element***** ";
cout<<" Enter Item value to be search : ";
cin>>item;
for(i=0;i<nA;i++){
if(arrA[i] == item){
found=i+1;
break;
}
}
if(found==-1)
cout<<" Search NOT FOUND ";
else
cout<<" Search is FOUND at "<<found<<" location ";
getch();
}
void array :: sort(){
clrscr();
int i,j,temp;
cout<<" *****Sorting Element***** ";
for(i=0;i<nA;i++){
for(j=i;j<nA;j++){
if(arrA[i] > arrA[j]){
temp = arrA[i];
arrA[i] = arrA[j];
arrA[j] = temp;
}
}
}
cout<<" Data are Sorted ";
getch();
}
array class and displays result.
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#define MAX 10
#include "array.cpp"void main()
{
int choice;
array obj;
while(1){
clrscr();
cout<<" ALL ARRAY OPERATIONS ";
cout<<" 1) Initialise Data ";
cout<<" 2) Traverse (Display Process) ";
cout<<" 3) Insert ";
cout<<" 4) Delete ";
cout<<" 5) Search ";
cout<<" 6) Sort ";
cout<<" 7) Exit ";
cout<<" Enter your Choice : ";
cin>>choice;
switch(choice){
case 1 : obj.init();
break;
case 2 : obj.traverse();
break;
case 3 : obj.insert();
break;
case 4 : obj.del();
break;
case 5 : obj.search();
break;
case 6 : obj.sort();
break;
case 7 : goout;
default: cout<<" Invalid Choice ";
getch();
break;
}
}
out:
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.