Skip to content

Instantly share code, notes, and snippets.

@cameronmoreau
Created April 29, 2015 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronmoreau/c751abbe673df92cfb09 to your computer and use it in GitHub Desktop.
Save cameronmoreau/c751abbe673df92cfb09 to your computer and use it in GitHub Desktop.
Coty's CPP Program
/* CSCI 152 Spring 2015 - Program 6
Your Name
program will enter data into two single dimension arrays (no duplicate values in arrays)
program will find the union and intersection of the two arrays
program will display the union and intersection */
#include<iostream>
#include<new>
using namespace std;
void input_data(short *data, short size); // function to enter data into the array
void display_data(short *data, short size); // function to display data in an array
void get_union(short *set1, short size1, short *set2, short size2, short *union_array, short size_union); // look at call statement to assist in completing this statement
short get_intersection(short *set1, short size1, short *set2, short size2, short *intersection); // look at call statement to assist in completing this statement
void get_union_intersection(short *set1, short size1, short *set2, short size2, short *union_array, short size_union, short *intersection, short size_intersection); // look at call statement to assist in completing this statement
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
cout << "Program will find the union and intersection 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
{
set1 = new(nothrow)short[size1];
// test pointer to verify memory was allocated
if(!set1) { cout<<"Memory allocation error, program will terminate\n"; system("pause"); exit(0); }
input_data(set1, 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;
set2 = new(nothrow)short[size2];
// test pointer to verify memory was allocated
if(!set2) { cout<<"Memory allocation error, program will terminate\n"; system("pause"); exit(0); }
input_data(set2, size2);
cout<<"\nthere are "<<size2<<" values in the array set2\n";
display_data(set2, size2);
// comment out the next two lines to compute union and intersection in one function
get_union(set1, size1, set2, size2, union_array, size_union);
size_intersection = get_intersection(set1, size1, set2, size2, intersection);
// uncomment following line if you want to write 1 function to get the union and intersection
get_union_intersection(set1, size1, set2, size2, union_array, size_union, intersection, size_intersection);
cout<<"the 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";
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 [] set1;
delete [] set2;
}
// pause the program to see the results
system("pause");
return 0;
}
void input_data(short *data, short size) {
}
void display_data(short *data, short size) {
for(int i = 0; i < size; i++) {
cout << *data << endl;
}
}
void get_union(short *set1, short size1, short *set2, short size2, short *union_array, short size_union) {
}
short get_intersection(short *set1, short size1, short *set2, short size2, short *intersection) {
return 1;
}
void get_union_intersection(short *set1, short size1, short *set2, short size2, short *union_array, short size_union, short *intersection, short size_intersection) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment