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 != '*');
}
|