9.docx

# 9.docx - Name Aditya D Pharande STD SE Roll NO A-22 CODE...

• No School
• AA 1
• 14

This preview shows page 1 - 5 out of 14 pages.

/* Name : Aditya D. Pharande STD : SE. Roll NO. : A-22. */ // CODE /* create the ADT that impleents set concept 1. add(new element) place a value into the set 2.remove 3.contains return a true if element is in collection 4.size returns no. of values in collection 5.intersection of two sets 6.union of two sets */ #include<iostream> using namespace std; class SetADT { int set1[10]; int set2[10]; int set3[10]; public: SetADT(); void add(int); void display(); int find(int,int); int Delete(int,int); void size(); void intersection(); void Union();

Subscribe to view the full document.

}; SetADT::SetADT() { int i; for(i=0;i<10;i++) { set1[i]=-1; set2[i]=-1; set3[i]=-1; } } void SetADT::Union() { int i,j,k=0; for(i=0;i<10;i++) { if(set1[i]!=-1) { set3[k]=set1[i]; k++; } } for(i=0;i<10;i++) { for(j=0;j<10;j++) { if(set2[i]==set1[j]) { break; } }
if(j==10) { set3[k]=set2[i]; k++; } } cout<<"\n\tUnion set3 = {"; for(i=0;i<k;i++) { cout<<set3[i]<<", "; } cout<<"\b\b }"; } void SetADT::intersection() { int i,j,k=0; for(i=0;i<10;i++) { for(j=0;j<10;j++) { if(set1[i]==set2[j]) { set3[k]=set1[i]; k++; break; } } } cout<<"\n\tIntersection set3 = {"; for(i=0;i<k;i++)

Subscribe to view the full document.

{ if(set3[i]!=-1) cout<<set3[i]<<", "; } cout<<"\b\b }"; } void SetADT::size() { int cnt1=0,cnt2=0,i; for(i=0;i<10;i++) { if(set1[i]!=-1) cnt1++; if(set2[i]!=-1) cnt2++; } cout<<"\n\tSize of Set 1 is "<<cnt1; cout<<"\n\tSize of Set 2 is "<<cnt2; } int SetADT::Delete(int ch,int s) { int index=find(ch,s); if(s==1 && index!=-1) { set1[index]=-1; return index; } if(s==2 && index!=-1) { set2[index]=-1; return index;
• Fall '19
• Chemical element, Naive set theory, Empty set, Magnesium

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern