Mencetak Join 2 Himpunan

Join adalah perkalian 2 himpunan dengan inputan berupa karakter atau bertipe char. Berikut code selengkapnya :

 

#include <cstdlib>
#include <iostream>

using namespace std;
class himpunan{
      public:
             void input();
             void kali();
             himpunan();
      private:
              char a[100][100];
              char b[100][100];
              int n,m;
              };
himpunan::himpunan(){
                     cout<<"Program Menhitung Join 2 Himpunan"<<endl<<endl;
                     }
void himpunan::input(){
     cout<<"Masukkan banyak jumlah anggota Himpunan A : ";
     cin>>n;
     cout<<"Masukkan banyak jumlah anggota Himpunan B : ";
     cin>>m;
     cout<<endl;
                     
     for(int i=0; i<n; i++){
             cout<<"Masukkan data Himpunan A ke-"<<i+1<<" : ";
             cin>>a[i];
             }
             cout<<endl;
     for(int i=0; i<m; i++){
             cout<<"Masukkan data Himpunan B ke-"<<i+1<<" : ";
             cin>>b[i];
             }
             cout<<endl<<endl;
     cout<<"Himpunan A = {";
     for(int i=0; i<n; i++){
             cout<<a[i]<<",";
             }
             
     cout<<"}"<<endl;
     cout<<"Himpunan B = {";
     for(int i=0; i<m; i++){
             cout<<b[i]<<",";}
             
     cout<<"}"<<endl;
     }
     
void himpunan::kali(){
     cout<<"\nJoin : "<<endl;
     for(int i=0;i<n;i++){
     for(int j=0;j<m;j++){
     cout <<"{"<<a[i]<<","<<b[j]<<"}"<<" ";
          }
     cout<<endl<<endl;
     }
     }
     
int main(int argc, char *argv[])
{
    himpunan dyas;
    dyas.input();
    dyas.kali();
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

 

Hasil running :

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: