Advertisement
Asking2211

asdasd

Dec 6th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.75 KB | None | 0 0
  1.    
  2.  
  3.     #include <iostream>
  4.     #include <cstdlib>
  5.     #include <cstdio>
  6.     #include <windows.h>
  7.     using namespace std;
  8.      
  9.      
  10.     void _ANIMATE()
  11.     {
  12.             int loop=0;
  13.             while(loop<=40)
  14.             {
  15.                     cout<<".";
  16.                     Sleep(50);
  17.                     loop++;
  18.             }
  19.             cout<<"100%"<<endl<<endl;
  20.            
  21.     }
  22.      
  23.      
  24.     void __CHOICE_ONE()
  25.     {
  26.             int matrix1[200][200], matrix2[200][200], matrix3[200][200];
  27.             int _MATRIX_TEMP[200][200],_MATRIX_RESULT[200][200];
  28.             int row, col;
  29.             cout<<"Masukkan Ukuran Baris : "<<endl;
  30.             cin>>row;
  31.             cout<<"Masukkan Ukuran Kolom : "<<endl;
  32.             cin>>col;
  33.             cout<<"\nMasukkan Element Matrix #1 : \n"<<endl;
  34.             for(int loop1=0;loop1<row; loop1++)
  35.             {
  36.                     for(int loop2=0;loop2<col;loop2++)
  37.                     {
  38.                             cout<<"Element Row["<<loop1+1<<"]  Column["<<loop2+1<<"]  : ";
  39.                             cin>>matrix1[loop1][loop2];
  40.                     }
  41.             }
  42.            
  43.             cout<<"\nMasukkan Element Matrix #2 : \n"<<endl;
  44.             for(int loop1=0;loop1<row; loop1++)
  45.             {
  46.                     for(int loop2=0;loop2<col;loop2++)
  47.                     {
  48.                             cout<<"Element Row["<<loop1+1<<"]  Column["<<loop2+1<<"]  : ";
  49.                             cin>>matrix2[loop1][loop2];
  50.                     }
  51.             }
  52.            
  53.             cout<<"\nMasukkan Element Matrix #3 : \n"<<endl;
  54.             for(int loop1=0;loop1<row; loop1++)
  55.             {
  56.                     for(int loop2=0;loop2<col;loop2++)
  57.                     {
  58.                             cout<<"Element Row["<<loop1+1<<"]  Column["<<loop2+1<<"]  : ";
  59.                             cin>>matrix3[loop1][loop2];
  60.                     }
  61.             }
  62.            
  63.             cout<<"\n\nCalculating";
  64.             _ANIMATE();
  65.             //hitung matrix1 dan matrix2 dlu, kita kurangin hasilnya tampung di _MATRIX_TEMP;
  66.            
  67.             for(int loop1=0;loop1<row;loop1++)
  68.             {
  69.                     for(int loop2=0;loop2<col;loop2++)
  70.                     {
  71.                             _MATRIX_TEMP[loop1][loop2] = matrix1[loop1][loop2] - matrix2[loop1][loop2];
  72.                     }
  73.             }
  74.            
  75.             //kita kurangin lagi _MATRIX_TEMP dengan matrix3, hasilnya tampung di _MATRIX_RESULT, baru diprint hasilnya...
  76.             for(int loop1=0;loop1<row;loop1++)
  77.             {
  78.                     for(int loop2=0;loop2<col;loop2++)
  79.                     {
  80.                             _MATRIX_RESULT[loop1][loop2] = _MATRIX_TEMP[loop1][loop2] - matrix3[loop1][loop2];
  81.                     }
  82.             }
  83.            
  84.             //tampilin hasil...
  85.             for(int loop1=0;loop1<row;loop1++)
  86.             {
  87.                     for(int loop2=0;loop2<col;loop2++)
  88.                     {
  89.                             cout<<_MATRIX_RESULT[loop1][loop2]<<"\t";
  90.                     }
  91.                     cout<<endl<<endl;
  92.             }
  93.      
  94.            
  95.     }
  96.            
  97.      
  98.      
  99.      
  100.     void  decimal_to_octal(int n)
  101.             {
  102.                    
  103.                     int mod, result=0;
  104.                     int arg[100];
  105.                     int loop = 0;
  106.                     while (n != 0)
  107.                     {
  108.                             mod = n % 8;
  109.                             arg[loop] = mod;
  110.                             n /= 8;
  111.      
  112.                             loop++;
  113.                     }
  114.      
  115.                     for (int rep = loop-1; rep >= 0; rep--)
  116.                     {
  117.                             printf("%d", arg[rep]); //sama aja kaya cout<<arg[rep];
  118.                     }
  119.                    
  120.             }
  121.     void decimal_to_hex(int n)
  122.             {
  123.            
  124.                     int mod, result = 0;
  125.                     char arg[100];
  126.                     int loop = 0;
  127.                     while (n != 0)
  128.                     {
  129.                             mod = n % 16;
  130.                             if (mod == 10)
  131.                             {
  132.      
  133.                                     arg[loop] = 'A';
  134.                             }
  135.                             else if (mod == 11)
  136.                             {
  137.      
  138.                                     arg[loop] = 'B';
  139.                             }
  140.                             else if (mod == 12)
  141.                             {
  142.      
  143.                                     arg[loop] = 'C';
  144.                             }
  145.                             else if (mod == 13)
  146.                             {
  147.      
  148.                                     arg[loop] = 'D';
  149.                             }
  150.                             else if (mod == 14)
  151.                             {
  152.      
  153.                                     arg[loop] = 'E';
  154.                             }
  155.                             else if (mod == 15)
  156.                             {
  157.      
  158.                                     arg[loop] = 'F';
  159.                             }
  160.                             else
  161.                             {
  162.      
  163.                                     arg[loop] = mod;
  164.                             }
  165.                            
  166.                             n /= 16;
  167.      
  168.                             loop++;
  169.                     }
  170.      
  171.                     for (int rep = loop - 1; rep >= 0; rep--)
  172.                     {
  173.                             if (arg[rep] == 'A')
  174.                             {
  175.                                     printf("A");
  176.                             }
  177.                             else if (arg[rep] == 'B')
  178.                             {
  179.                                     printf("B");
  180.                             }
  181.                             else if (arg[rep] == 'C')
  182.                             {
  183.                                     printf("C");
  184.                             }
  185.                             else if (arg[rep] == 'D')
  186.                             {
  187.                                     printf("D");
  188.                             }
  189.                             else if (arg[rep] == 'E')
  190.                             {
  191.                                     printf("E");
  192.                             }
  193.                             else if (arg[rep] == 'F')
  194.                             {
  195.                                     printf("F");
  196.                             }
  197.                             else
  198.                             {
  199.                                     printf("%d", arg[rep]); //sama aja kaya cout<<arg[rep];
  200.                             }
  201.      
  202.      
  203.      
  204.                     }
  205.      
  206.             }
  207.     void __CHOICE_TWO()
  208.     {
  209.             int decimal;
  210.             cout<<"Input Decimal Digit : "<<endl;
  211.             cin>>decimal;
  212.            
  213.             cout<<"\nDecimal to Octal : \n"<<endl;
  214.             cout<<"Loading";
  215.             _ANIMATE();
  216.             cout<<"Result : ";
  217.             decimal_to_octal(decimal);
  218.             cout<<"\n\nDecimal to Hexadecimal : \n"<<endl;
  219.             cout<<"Loading";
  220.             _ANIMATE();
  221.             cout<<"Result : ";
  222.             decimal_to_hex(decimal);
  223.             cout<<endl;
  224.            
  225.     }
  226.      
  227.     void __CHOICE_THREE()
  228.     {
  229.              int d1,m1,y1,d2,m2,y2,i,temp,sum=0,month[]={31,28,31,30,31,30,31,31,30,31,30,31};
  230.              cout<<"Enter Date 1 : (DD-MM-YYYY) : "<<endl;
  231.              cin>>d1>>m1>>y1;
  232.             cout<<"Enter Date 2 : (DD-MM-YYYY) : "<<endl;
  233.              cin>>d2>>m2>>y2;
  234.       temp=d1;
  235.      
  236.       for(i=m1;i<m2+(y2-y1)*12;i++)
  237.      {
  238.       if(i>12)
  239.       {
  240.        i=1;
  241.        y1++;
  242.       }
  243.      
  244.        if(i==2)
  245.       {
  246.        if(y1%4==0 && (y1%100!=0 || y1%400==0))
  247.         month[i-1]=29;
  248.        else
  249.         month[i-1]=28;
  250.       }
  251.      
  252.        sum=sum+(month[i-1]-temp);
  253.       temp=0;
  254.      
  255.              
  256.        
  257.      
  258.       }
  259.      
  260.       sum=sum+d2-temp;
  261.      
  262.       char nama_bulan[12][20]= {"Januari", "Februari","Maret", "April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"};
  263.       cout<<"Tanggal 1 = "<<d1<<" "<<nama_bulan[d1+1]<<" "<<y1<<endl;
  264.       cout<<"Tanggal 2 = "<<d1<<" "<<nama_bulan[d2+1]<<" "<<y1<<endl;
  265.      
  266.       cout<<"Selisih = " <<sum<<endl;
  267.     }
  268.     int main()
  269.     {
  270.             system("color 0a");
  271.             int menu;
  272.             while(true)
  273.             {
  274.                     cout<<"1. Operasi Pengurangan 3 Buah Matrix "<<endl;
  275.                     cout<<"2. Konversi Decimal Ke Octal dan Hexadecimal"<<endl;
  276.                     cout<<"3. Menghitung Selisih 2 Tangal "<<endl;
  277.                     cout<<"4. Exit"<<endl;
  278.                     do
  279.                     {
  280.                             cout<<"Masukkan Pilihan : "<<endl;
  281.                             cin>>menu;
  282.                     }while(menu<1 || menu>4);
  283.                    
  284.                     if(menu==1)
  285.                     {
  286.                             __CHOICE_ONE();
  287.                             system("echo. &&  pause");
  288.                             system("cls");
  289.                     }
  290.                     else if(menu==2)
  291.                     {
  292.                             __CHOICE_TWO();
  293.                             system("echo. &&  pause");
  294.                             system("cls");
  295.                     }
  296.                     else if(menu==3)
  297.                     {
  298.                             __CHOICE_THREE();
  299.                             system("echo. &&  pause");
  300.                             system("cls");
  301.                     }
  302.                     else
  303.                     {
  304.                             exit(0);
  305.                            
  306.                     }
  307.                    
  308.             }
  309.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement