Helpful Information
 
 
Category: Delphi Programming
help with set operations union,difference

Ok, I need some help i have been wracking my brain for days, and can not figure this one out. I am trying to copy the arrays from the struct into a 3rd array, where i can perform my set operations but am unable to do so. Here is my code. Any help would be greatly appreciated

#include <iostream>
#include <cctype>
using namespace std;

void readina (struct set &a);
void showita(struct set a);
void readinb (struct set &b);
void showitb (struct set b);
void showitc (struct set c);
void unions (struct set &a,struct set &b);
void swap (struct set &a, struct set &b);
void copyarray(struct set &a, struct set &b, struct set &c);

#define MAXSIZE 26

struct set{
char *start_ptr;
char *end_ptr;
int size;
char member[27];
};

int main ( ) {

struct set a;
struct set b;
struct set c;

cout << "Please input a set of lowercase letters without duplicates." << endl
<< "and then press return" << endl;

readina (a);

cout << endl << "Please input another set and then press return" << endl;
readinb (b);

cout << "Here is what you gave me for the first set :";
showita (a);

cout << "Here is what you gave me for the second :";
showitb (b);

cout << "Here is the union of the set :";
copyarray(a,b,c);showitc (c);

return 0;
}


void readina (struct set &a) {
int i = 0;
a.size = 0;
while (cin.get(a.member[i]) && (i < MAXSIZE)) { // we use cin.get because
// we don't want to skip over carriage returns
// but cin.get reads in blanks as characters als0
if (a.member[i] == '\n') {// carriage return means no more to read
break; // jump of while loop
}
// carriage return means no more to read
else if (a.member[i] == ' ') // skip any blanks - don't put them in the set
continue;
else {
i++;
a.size++;
}
}
a.start_ptr = & (a.member [0] );
a.end_ptr = & (a.member [i-1] );
return;
}

void showita (struct set a) {
int i;
for (i = 0; i < a.size; i++) {
cout << " " << a.member[i] ;
}
cout << endl;
return;
}

void readinb (struct set &b) {
int i = 0;
b.size = 0;
while (cin.get(b.member[i]) && (i < MAXSIZE)) { // we use cin.get because
// we don't want to skip over carriage returns
// but cin.get reads in blanks as characters also

if (b.member[i] == '\n') {// carriage return means no more to read
break; // jump of while loop
}
// carriage return means no more to read
else if (b.member[i] == ' ') // skip any blanks - don't put them in the set
continue;
else {
i++;
b.size++;
}
}
b.start_ptr = & (b.member [0] );
b.end_ptr = & (b.member [i-1] );
return;
}

void showitb (struct set b) {
int i;
for (i = 0; i < b.size; i++) {
cout << " " << b.member[i] ;
}
cout << endl;
return;
}


void unions(struct set &a,struct set &b){

int i;

for (i = 0; i < a.size; i++){
if(a.member[i] != b.member[i])
cout<< " "<<a.member[i];
else break;
}
for (i=0;i < b.size; i++){
if(b.member[i] != a.member[i])
cout << " "<<b.member[i];
else break;
}

cout << endl;
return;
}

void showitc (struct set c) {
int i;
for (i = 0; i < c.size; i++) {
cout << " " << c.member[i] ;
}
cout << endl;
return;
}










privacy (GDPR)