program will enter data into two single dimension arrays (do not store duplicate values in arrays)
program will find the union and intersection of the two arrays using one function
program will find the symmetric difference of two arrays
program will display the union, intersection, and symmetric difference */
short* input_data(short size); // function to dynamically allocate and array and enter data into the array
void display_data(short *data, short size); // function to display data in an array
void get_union_intersection(short *set1, short size1, short *set2, short size2, short *&union_array, short &size_union, short *&intersection, short &size_intersection);
void get_SymmetricDifference(short *set1, short size1, short *set2, short size2, short *&SD_array, short &size_SD);
int main()
{
short *set1, size1, // first data set and size
*set2, size2, // second data set and size
*union_array, size_union, // array to store the union of the two sets
*intersection, size_intersection, // array to store the intersection of the two sets
*symmetricdifference, size_SD; // array to store the symmetric difference of the two sets
cout<<"Program will find the union, intersection and symmetric difference of two sets of data\n";
cout<<"enter the number of values to store in the data set 1 \n or zero to terminate the program\n";
cin>>size1;
while(size1) // loop to permit user to test many data sets
{
cout<<"Enter "<<size1<<" values into the first set\n";
set1 = input_data(size1);
// print the contents of the array
cout<<"\nthere are "<<size1<<" values in the array set1\n";
display_data(set1, size1);
cout<<"enter the number of values to store in the data set 2\n";
cin>>size2;
cout<<"Enter "<<size1<<" values into the second set\n";
set2 = input_data(size2);
// test pointer to verify memory was allocated
cout<<"\nthere are "<<size2<<" values in the array set2\n";
display_data(set2, size2);
get_union_intersection(set1, size1, set2, size2, union_array, size_union, intersection, size_intersection);
cout<<"\nthe union array contains "<<size_union<<" values\n";
display_data(union_array, size_union);
if(size_intersection)// intersection array may be empty, must test size
{
cout<<"the intersection array contains "<<size_intersection<<" values\n";
display_data(intersection, size_intersection);
}
else
cout<<"there are no values in the intersection of the two data sets\n";
get_SymmetricDifference(set1, size1, set2, size2, symmetricdifference, size_SD);
if(size_SD)
{
cout<<"the symmetric difference array contains "<<size_SD<<" values\n";
display_data(symmetricdifference, size_SD);
}
else
cout<<"there are no values in the symmetric difference of the two data sets\n";
cout<<"\nenter the number of values to store in the data set 1 \n or zero to terminate the program\n";
cin>>size1;
// delete memory previously allocated
delete [] union_array;
delete [] intersection;
delete [] symmetricdifference;
delete [] set1;
delete [] set2;
}
// pause the program to see the results
system("pause");
return 0;
}
No subscripts are permitted in any function for this program including the inputData and displayData functions. You must use pointers to access dynamically allocated arrays and to control loop termination.
Write a function, input_data, to dynamically allocate an array of the size passed to the function. Store the data in the array from the keyboard and return the address allocated in the function to main.
Write one function to obtain the union and intersection in the same algorithm/function. Use the call statement given above to write the function definition. The union of two sets of data is all the values in set1 and all the values in set2 minus any duplicate values. Each set of data will contain no duplicate values. Dynamically allocate the union array to be the size of the two sets of data combined. Store the union of the two arrays in the union_array and assign the variable size_union a value which is the number of data values stored in the union_array. The intersection of two data sets is all the values that are found in both sets of data. Each set of data will contain no duplicate values. Dynamically allocate the intersection array to be the size of the smaller of the two data arrays passed to the function. Store the intersection of the two arrays in the intersection array and assign the variable size_intersection a value which is the number of data values stored in the intersection array. Be sure to pass each argument by the correct parameter passing mode.
Write a function, get_SymmetricDifference, to dynamically allocate an array in which to store the symmetric difference between two sets of data. This can be defined as the union of the two sets of data minus the intersection of the two data sets. However, the best solution would not be to find the union and the intersection, and then remove all values from the union that are found in the intersection. Dynamically allocate the size of the symmetric difference array to be the size of the two sets of data combined and store the address allocated in the SD_array parameter. Assign the variable size_SD a value which is the number of data values stored in the SD_array. Be sure to pass each argument by the correct parameter passing mode.
This function can be written without using any extra memory (dynamically allocated or compile time arrays). A faster algorithm would use a flag array the same size as set2 assuming that you will take each element from set1 and compare that value with the values in set2. Any local arrays used to solve this problem must be dynamically allocated and then deleted before the function terminates.
Test the following data sets: data sets of different sizes; data sets where the values in the two sets are completely different (empty intersection, the union and symmetric difference would be the same); data sets where the values in the two sets are exactly the same but in different orders (union and intersection are the same, empty symmetric difference); some combination of the previous sets.
Note – the following statement can be used at execution time to assign all values of a block of memory the same value
fill(base address, base address+ number of elements, value to assign to every element);
example: fill(data, data+size, 0);
PROGRAM:
#include <iostream>
#include <cstdlib>
using namespace std;
short* input_data(short size); // function to dynamically allocate and array and enter data into the array
void display_data(short *data, short size); // function to display data in an array
void get_union_intersection(short *set1, short size1, short *set2, short size2, short *&union_array, short &size_union, short *&intersection, short &size_intersection);
void get_SymmetricDifference(short *set1, short size1, short *set2, short size2, short *&SD_array, short &size_SD);
int main()
{
short *set1, size1, // first data set and size
*set2, size2, // second data set and size
*union_array, size_union, // array to store the union of the two sets
*intersection, size_intersection, // array to store the intersection of the two sets
*symmetricdifference, size_SD; // array to store the symmetric difference of the two sets
cout<<"Program will find the union, intersection and symmetric difference of two sets of data\n";
cout<<"enter the number of values to store in the data set 1 \n or zero to terminate the program\n";
cin>>size1;
while(size1) // loop to permit user to test many data sets
{
cout<<"Enter values"<<endl;
set1 = input_data(size1);
// print the contents of the array
cout<<"\nthere are "<<endl;
display_data(set1, size1);
cout<<"enter the number of values to store in the data set 2\n";
cin>>size2;
cout<<"Enter values"<<endl;
set2 = input_data(size2);
// test pointer to verify memory was allocated
cout<<"\nthere are "<<endl;
display_data(set2, size2);
get_union_intersection(set1, size1, set2, size2, union_array, size_union, intersection, size_intersection);
cout<<"\nthe union array contains "<<endl;
display_data(union_array, size_union);
if(size_intersection)// intersection array may be empty, must test size
{
cout<<"the intersection array contains "<<endl;
display_data(intersection, size_intersection);
}
else
cout<<"there are no values in the intersection of the two data sets\n";
get_SymmetricDifference(set1, size1, set2, size2, symmetricdifference, size_SD);
if(size_SD)
{
cout<<"the symmetric difference array contains "<<endl;
display_data(symmetricdifference, size_SD);
}
else
cout<<"there are no values in the symmetric difference of the two data sets\n";
cout<<"\nenter the number of values to store in the data set 1 \n or zero to terminate the program\n";
cin>>size1;
// delete memory previously allocated
delete [] union_array;
delete [] intersection;
delete [] symmetricdifference;
delete [] set1;
delete [] set2;
}
// pause the program to see the results
system("pause");
return 0;
}
//Define function
short* input_data(short size)
{
//Declare variable
short *set = new short[size];
//Declare variable
int kk=0;
//Loop
while((set+kk)!=(set+size))
{
//REad
cin>>*(set+kk);
//Increment value
kk++;
}
//Return
return set;
}
//Define function
void display_data(short *data, short size)
{
//Declare variable
short *ed = (data +size-1);
//Loop
for(;data<ed; data++)
{
//Display value
cout<<*(data)<<",";
}
//display last value
cout<<*data;
//new line
cout<<endl;
}
//Define function
void get_union_intersection(short *set1, short size1, short *set2, short size2, short *&union_array, short &size_union, short *&intersection, short &size_intersection)
{
//Declare variable
int kk=0;
//declare variable
size_union = 0;
//declare variable
union_array = new short[size1+size2];
//Find union
while((set1+kk)!=(set1+size1))
{
//Add values
*(union_array+ (size_union)) = *(set1+kk);
//Increment value
kk++;
//Increment value
size_union++;
}
//Declare variable
kk=0;
//Loop
while((set2+kk)!=(set2+size2))
{
//declare variable
int aa=0;
//Loop
while((set1+aa)!=(set1+size1))
{
//Check condition
if(*(set1+aa)==*(set2+kk))
{
//Break
break;
}
//Increment value
aa++;
}
//Check condition
if(aa==size1)
{
//Add value
*(union_array+size_union) = *(set2+kk);
//Increment value
size_union++;
}
//Increment value
kk++;
}
//Find intersection
int sm=0;
//Check condition
if(size1<size2)
//Set value
sm=size1;
//Else
else
//set value
sm=size2;
//declare space
intersection = new short[sm];
//Set value
size_intersection = 0;
//set value
kk=0;
//Loop
while((set2+kk)!=(set2+size2))
{
//Set value
int aa=0;
//Loop
while((set1+aa)!=(set1+size1))
{
//Check condition
if(*(set1+aa)==*(set2+kk))
{
//add value
*(intersection + size_intersection) = *(set2+kk);
//Increment value
size_intersection++;
//Break
break;
}
//Increment value
aa++;
}
//Increment value
kk++;
}
}
//define function
void get_SymmetricDifference(short *set1, short size1, short *set2, short size2, short *&SD_array, short &size_SD)
{
//Declare array
SD_array = new short[size1+size2];
//declare variable
int kk=0, jj=0;
//Declare variable
int fg=0;
//set value
size_SD = 0;
//Include elements from set1
//loop
while((set1+kk)!=(set1+size1))
{
//Set value
fg=0;
//sEt value
jj=0;
//Loop
while((set2+jj)!=(set2+size2))
{
//Check condition
if(*(set1+kk)==*(set2+jj))
{
//Set value
fg=1;
//Break
break;
}
//Increment value
jj++;
}
//Check condition
if(fg==0)
{
//Add value
*(SD_array+size_SD) = *(set1+kk);
//Increment value
size_SD ++;
}
//Increment value
kk++;
}
//Include elements from set2
jj=0;
//Loop
while((set2+jj)!=(set2+size2))
{
//Set value
fg=0;
//set value
kk=0;
//Loop
while((set1+kk)!=(set1+size1))
{
//Check condition
if(*(set1+kk)==*(set2+jj))
{
//Set value
fg=1;
//Break
break;
}
//Increment value
kk++;
}
//check condition
if(fg==0)
{
//set value
*(SD_array+size_SD) = *(set2+jj);
//Increment value
size_SD ++;
}
//Increment value
jj++;
}
}
program will enter data into two single dimension arrays (do not st...
c++ please no global varaible write a value returning function input data to dynamically allocate a short array of size elements and store the input data entered from the disk file into array.Return the base address of the array allocated.Read the data from the text file Hello.txt and store the data in reverse order in the array.the size of the data set will be in the file size 10 and the data was 1 2 3 4 5 6 7...
Program has to be in C# language Write a computer program that takes two sets (let the user determine the cardinality of each set and enter them manually) and calculates the following operations: Union Intersection Difference (set1 - set2) Cartesian product (set2 X set1) Check whether set2 is a subset of set1 or set1 is a subset of set2 Find the powerset of set1 and print out its elements and cardinality
The question exercises the union, intersection, and the intersection operations of two set of strings (names). For this type of problem, you need to preserve the original sets from being modified by some of the set method. You can used the clone( ) method to copy the sets or simply create another set using the same array contents as the original. You can find an example of the clone() for the LinkedHashSet set in the provided “skeleton” program (assign8_Q3.java) code...
I am having trouble with my C++ program.... Directions: In this lab assignment, you are to write a class IntegerSet that represents a set of integers (by definition, a set contains no duplicates). This ADT must be implemented as a singly linked list of integers (with no tail reference and no dummy head node), but it need not be sorted. The IntegerSet class should have two data fields: the cardinality (size) of the set, and the head reference to the...
Introduction: One of the most important uses of pointers is for dynamic allocation of memory. In C++ there are commands that let the user request a chunk of memory from the operating system, and use this memory to store data. There are also commands to return memory back to the O/S when the program is finished using the data. In this lab, we will explore some of the things that can go wrong when using dynamic memory and discuss how...
Complete a program In C#: some code is included, you edit the areas that have not been filled. For your C# program you will complete code that plays the War card game. In this game, the deck of cards is evenly divided among two players. The players are not allowed to look at the cards in their hand. On each round of the game, both players lay down the top card from their hand. The player with the higher value...
C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible; (2) use unique value array; (3) use flag array (flags used to avoid counting a number more than 1 time); (4) compute frequency distribution (use unique and count arrays); (5) use count array to store the frequency of a number. No global variable are permitted in this assignment. Do not change the code provided only write the missing code. Write the missing C++ statements...
I can't get my code to work on xcode and give me an output. #include <conio.h> #include <cstdlib> #include <fstream> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; // So "std::cout" may be abbreviated to "cout" //Declare global arrays int dummy1[10]; int dummy2[10]; int dummy3[10]; int universalSet[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; //Function to return statement "Empty thread" when the resultant set is empty string isEmpty(int arr[]) { string...
Write a program that works with two arrays of the same size that are related to each other in some way (or parallel arrays). Your two arrays must be of different data types. For example, one array can hold values that are used in a formula that produces the contents of the second array. Some examples might be: from a previous program, populations and the associated flowrates for those populations (an int array of populations and a double array...
Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the size of an array. Then create an integer array of that exact size. Ask the user to enter a maximum value and then write a loop to fill the array with random numbers with value in the range of 1 to the maximum value. For example, if the maximum value is 100, random numbers must have value 1 to 100 inclusive. Input size of...