Problem with union and intersection of two character strings

My Professor gave us this as homework (which i am having difficulty understanding)

My textbook has nothing on union or intersect.

Write a C++ program that determines the Union and Intersection of two character strings,
S1 and S2, and the results are placed in another string S3.

The program should have the following functions:

void Union (char X1[ ], char X2[ ], char X3[ ]);
void Intersect (char X1[ ], char X2[ ], char X3[ ]);

and in the main procedure S1, S2, and S3 are declared as arrays of characters.

int main ( )
{ char S1[100], S2 [100], S3[200];

We need the null character, because “when you write the Union and Intersect functions, the null character is used as a stop point, thus the logic of you program should use the null character”.

The easy way to enter the characters for S1 and S2 is by choosing a special character to stop entering them.

For example, let say we choose the character ‘*’ , as the stopping point.

This is what I have so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  #include <iostream>
#include <string>

using namespace std;

void Union(char X1[], char X2[], char X3[])
{

}

void Intersect(char X1[], char X2[], char X3[])
{

}


int main()
{
	char S1[100], S2[100], S3[200];

	char c; // string character
	cout << endl << "please enter the characters for S1(enter '*' when stop)";
	int i = 0;
	S1[0] = ' ';

	do {
		cin >> c;
		if (c != '*') {
			S1[i] = c;
			i++;
		}
		else {
			S1[i] = '\0'; //inserting the null character
		}
	} while (c != '*');

}
Since you will need to enter two strings, I suggest that you move that code to a function that you can call. Pass the string buffer and the prompt as parameters.

I think you can solve these as follows:
1. You'll be using arrays of 256 bool. These will indicate whether a character is in a string. For example, if arr[32] is true, then character 32 (which is a space) is in the string.
2. Write 1 function that populates the array from a string. Write a second function that populates a string from the array.
3. Now you can compute the union and the intersection of the arrays. This is easy.
my main issue is not understanding what the intersection or union does. or how to code that function at all
Topic archived. No new replies allowed.