slices are members of the same owned by the two sets. If A then B slices irisanya Amember of the same is with members of the B. it also applies vice versa. Here's more about the program:
#include <cstdlib>
#include <iostream>
using namespace std;
class tp{
public :
tp();
void pilihan();
void angka();
void huruf();
void kata();
void exit();
private:
int a[10],b[10],pil,pil2,n,m,e[10];
char x[10][10],y[10][10],u[10][10],c[10],d[10],f[10];
};
tp::tp(){
cout<<"PROGRAM MENCETAK IRISAN PADA SUATU HIMPUNAN"<<endl;
}
void tp::pilihan(){
cout<<"Pilihan Pemasukan Data Dengan :"<<endl;
cout<<"\t 1. Angka "<<endl;
cout<<"\t 2. Huruf "<<endl;
cout<<"\t 3. Kata "<<endl;
cout<<"\t 0. keluar "<<endl;
cout<<"Masukkan pilihan anda :";
cin>>pil;
switch(pil){
case 1 : angka ();break;
case 2 : huruf ();break;
//case 3 : kata (); break;
case 0 : exit (); break;
default :
cout<<"Sorry Bro Keliru "<<endl;
cout<<"Please try again "<<endl;
pilihan();
break;
}
}
void tp::angka(){
cout<<"Masukkan Banyak data Pertama :"; cin>>n;
cout<<"Masukkan Banyak data Kedua :"; cin>>m;
for(int i=0; i<n; i++){
cout<<"Masukkan Pertama ke -"<<i+1<<":";
cin>>a[i];}
for(int j=0; j<m; j++){
cout<<"Masukkan Kedua ke -"<<j+1<<":";
cin>>b[j];
}
cout<<"Himpunan A :";
for(int i=0; i<n; i++){
cout<<a[i]<<",";}
cout<<endl;
cout<<"Himpunan B :";
for(int j=0; j<m; j++){
cout<<b[j]<<",";}
cout<<endl;
cout<<"Masukkan Pilihan :"<<endl;
cout<<" 1. A irisan B "<<endl;
cout<<" 2. B irisan A "<<endl;
cin>>pil2;
if(pil2==1){
cout<<"A irisan B = ";
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(a[i]==b[j]) cout<<a[i]<<",";}
}}
else{
cout<<"B irisan A = ";
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
if(b[i]==a[j]) cout<<b[i]<<",";}
}}
cout<<endl;
pilihan();
}
void tp::huruf(){
cout<<"Masukkan Banyak data Pertama :"; cin>>n;
cout<<"Masukkan Banyak data Kedua :"; cin>>m;
for(int i=0; i<n; i++){
cout<<"Masukkan Pertama ke -"<<i+1<<":";
cin>>c[i];}
for(int j=0; j<m; j++){
cout<<"Masukkan Kedua ke -"<<j+1<<":";
cin>>d[j];
}
cout<<"Himpunan A :";
for(int i=0; i<n; i++){
cout<<c[i]<<",";}
cout<<endl;
cout<<"Himpunan B :";
for(int j=0; j<m; j++){
cout<<d[j]<<",";}
cout<<endl;
cout<<"Masukkan Pilihan :"<<endl;
cout<<" 1. A irisan B "<<endl;
cout<<" 2. B irisan A "<<endl;
cin>>pil2;
if(pil2==1){
cout<<"A irisan B = ";
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(c[i]==d[j]) cout<<c[i]<<",";}
}}
else{
cout<<"B irisan A = ";
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
if(d[i]==c[j]) cout<<d[i]<<",";}
}}
cout<<endl;
pilihan();
}
void tp::kata(){
cout<<"Masukkan Banyak data Pertama :"; cin>>n;
cout<<"Masukkan Banyak data Kedua :"; cin>>m;
for(int i=0; i<n; i++){
cout<<"Masukkan Pertama ke -"<<i+1<<":";
cin>>x[i];}
for(int j=0; j<m; j++){
cout<<"Masukkan Kedua ke -"<<j+1<<":";
cin>>y[j];
}
cout<<"Himpunan A :";
for(int i=0; i<n; i++){
cout<<x[i]<<",";}
cout<<endl;
cout<<"Himpunan B :";
for(int j=0; j<m; j++){
cout<<y[j]<<",";}
cout<<endl;
cout<<"Masukkan Pilihan :"<<endl;
cout<<" 1. A irisan B "<<endl;
cout<<" 2. B irisan A "<<endl;
cin>>pil2;
if(pil2==1){
cout<<"A irisan B = ";
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(x[i]==y[j]) cout<<x[i]<<",";}
}}
else{
cout<<"B irisan A = ";
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
if(y[i]==x[j]) cout<<y[i]<<",";}
}}
cout<<endl;
pilihan();
}
void tp::exit(){
cout<<"\t Terima Kasih "<<endl;
}
int main(int argc, char *argv[])
{
tp test;
test.pilihan();
system("PAUSE");
return EXIT_SUCCESS;
}
Runiing Result :
#include <cstdlib>
#include <iostream>
using namespace std;
class tp{
public :
tp();
void pilihan();
void angka();
void huruf();
void kata();
void exit();
private:
int a[10],b[10],pil,pil2,n,m,e[10];
char x[10][10],y[10][10],u[10][10],c[10],d[10],f[10];
};
tp::tp(){
cout<<"PROGRAM MENCETAK IRISAN PADA SUATU HIMPUNAN"<<endl;
}
void tp::pilihan(){
cout<<"Pilihan Pemasukan Data Dengan :"<<endl;
cout<<"\t 1. Angka "<<endl;
cout<<"\t 2. Huruf "<<endl;
cout<<"\t 3. Kata "<<endl;
cout<<"\t 0. keluar "<<endl;
cout<<"Masukkan pilihan anda :";
cin>>pil;
switch(pil){
case 1 : angka ();break;
case 2 : huruf ();break;
//case 3 : kata (); break;
case 0 : exit (); break;
default :
cout<<"Sorry Bro Keliru "<<endl;
cout<<"Please try again "<<endl;
pilihan();
break;
}
}
void tp::angka(){
cout<<"Masukkan Banyak data Pertama :"; cin>>n;
cout<<"Masukkan Banyak data Kedua :"; cin>>m;
for(int i=0; i<n; i++){
cout<<"Masukkan Pertama ke -"<<i+1<<":";
cin>>a[i];}
for(int j=0; j<m; j++){
cout<<"Masukkan Kedua ke -"<<j+1<<":";
cin>>b[j];
}
cout<<"Himpunan A :";
for(int i=0; i<n; i++){
cout<<a[i]<<",";}
cout<<endl;
cout<<"Himpunan B :";
for(int j=0; j<m; j++){
cout<<b[j]<<",";}
cout<<endl;
cout<<"Masukkan Pilihan :"<<endl;
cout<<" 1. A irisan B "<<endl;
cout<<" 2. B irisan A "<<endl;
cin>>pil2;
if(pil2==1){
cout<<"A irisan B = ";
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(a[i]==b[j]) cout<<a[i]<<",";}
}}
else{
cout<<"B irisan A = ";
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
if(b[i]==a[j]) cout<<b[i]<<",";}
}}
cout<<endl;
pilihan();
}
void tp::huruf(){
cout<<"Masukkan Banyak data Pertama :"; cin>>n;
cout<<"Masukkan Banyak data Kedua :"; cin>>m;
for(int i=0; i<n; i++){
cout<<"Masukkan Pertama ke -"<<i+1<<":";
cin>>c[i];}
for(int j=0; j<m; j++){
cout<<"Masukkan Kedua ke -"<<j+1<<":";
cin>>d[j];
}
cout<<"Himpunan A :";
for(int i=0; i<n; i++){
cout<<c[i]<<",";}
cout<<endl;
cout<<"Himpunan B :";
for(int j=0; j<m; j++){
cout<<d[j]<<",";}
cout<<endl;
cout<<"Masukkan Pilihan :"<<endl;
cout<<" 1. A irisan B "<<endl;
cout<<" 2. B irisan A "<<endl;
cin>>pil2;
if(pil2==1){
cout<<"A irisan B = ";
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(c[i]==d[j]) cout<<c[i]<<",";}
}}
else{
cout<<"B irisan A = ";
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
if(d[i]==c[j]) cout<<d[i]<<",";}
}}
cout<<endl;
pilihan();
}
void tp::kata(){
cout<<"Masukkan Banyak data Pertama :"; cin>>n;
cout<<"Masukkan Banyak data Kedua :"; cin>>m;
for(int i=0; i<n; i++){
cout<<"Masukkan Pertama ke -"<<i+1<<":";
cin>>x[i];}
for(int j=0; j<m; j++){
cout<<"Masukkan Kedua ke -"<<j+1<<":";
cin>>y[j];
}
cout<<"Himpunan A :";
for(int i=0; i<n; i++){
cout<<x[i]<<",";}
cout<<endl;
cout<<"Himpunan B :";
for(int j=0; j<m; j++){
cout<<y[j]<<",";}
cout<<endl;
cout<<"Masukkan Pilihan :"<<endl;
cout<<" 1. A irisan B "<<endl;
cout<<" 2. B irisan A "<<endl;
cin>>pil2;
if(pil2==1){
cout<<"A irisan B = ";
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(x[i]==y[j]) cout<<x[i]<<",";}
}}
else{
cout<<"B irisan A = ";
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
if(y[i]==x[j]) cout<<y[i]<<",";}
}}
cout<<endl;
pilihan();
}
void tp::exit(){
cout<<"\t Terima Kasih "<<endl;
}
int main(int argc, char *argv[])
{
tp test;
test.pilihan();
system("PAUSE");
return EXIT_SUCCESS;
}
Runiing Result :