Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 18th, 2003, 08:41 AM
reap76 reap76 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 3 reap76 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 58 sec
Reputation Power: 0
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;
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > help with set operations union,difference

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap