Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- #include <windows.h>
- using namespace std;
- void _ANIMATE()
- {
- int loop=0;
- while(loop<=40)
- {
- cout<<".";
- Sleep(50);
- loop++;
- }
- cout<<"100%"<<endl<<endl;
- }
- void __CHOICE_ONE()
- {
- int matrix1[200][200], matrix2[200][200], matrix3[200][200];
- int _MATRIX_TEMP[200][200],_MATRIX_RESULT[200][200];
- int row, col;
- cout<<"Masukkan Ukuran Baris : "<<endl;
- cin>>row;
- cout<<"Masukkan Ukuran Kolom : "<<endl;
- cin>>col;
- cout<<"\nMasukkan Element Matrix #1 : \n"<<endl;
- for(int loop1=0;loop1<row; loop1++)
- {
- for(int loop2=0;loop2<col;loop2++)
- {
- cout<<"Element Row["<<loop1+1<<"] Column["<<loop2+1<<"] : ";
- cin>>matrix1[loop1][loop2];
- }
- }
- cout<<"\nMasukkan Element Matrix #2 : \n"<<endl;
- for(int loop1=0;loop1<row; loop1++)
- {
- for(int loop2=0;loop2<col;loop2++)
- {
- cout<<"Element Row["<<loop1+1<<"] Column["<<loop2+1<<"] : ";
- cin>>matrix2[loop1][loop2];
- }
- }
- cout<<"\nMasukkan Element Matrix #3 : \n"<<endl;
- for(int loop1=0;loop1<row; loop1++)
- {
- for(int loop2=0;loop2<col;loop2++)
- {
- cout<<"Element Row["<<loop1+1<<"] Column["<<loop2+1<<"] : ";
- cin>>matrix3[loop1][loop2];
- }
- }
- cout<<"\n\nCalculating";
- _ANIMATE();
- //hitung matrix1 dan matrix2 dlu, kita kurangin hasilnya tampung di _MATRIX_TEMP;
- for(int loop1=0;loop1<row;loop1++)
- {
- for(int loop2=0;loop2<col;loop2++)
- {
- _MATRIX_TEMP[loop1][loop2] = matrix1[loop1][loop2] - matrix2[loop1][loop2];
- }
- }
- //kita kurangin lagi _MATRIX_TEMP dengan matrix3, hasilnya tampung di _MATRIX_RESULT, baru diprint hasilnya...
- for(int loop1=0;loop1<row;loop1++)
- {
- for(int loop2=0;loop2<col;loop2++)
- {
- _MATRIX_RESULT[loop1][loop2] = _MATRIX_TEMP[loop1][loop2] - matrix3[loop1][loop2];
- }
- }
- //tampilin hasil...
- for(int loop1=0;loop1<row;loop1++)
- {
- for(int loop2=0;loop2<col;loop2++)
- {
- cout<<_MATRIX_RESULT[loop1][loop2]<<"\t";
- }
- cout<<endl<<endl;
- }
- }
- void decimal_to_octal(int n)
- {
- int mod, result=0;
- int arg[100];
- int loop = 0;
- while (n != 0)
- {
- mod = n % 8;
- arg[loop] = mod;
- n /= 8;
- loop++;
- }
- for (int rep = loop-1; rep >= 0; rep--)
- {
- printf("%d", arg[rep]); //sama aja kaya cout<<arg[rep];
- }
- }
- void decimal_to_hex(int n)
- {
- int mod, result = 0;
- char arg[100];
- int loop = 0;
- while (n != 0)
- {
- mod = n % 16;
- if (mod == 10)
- {
- arg[loop] = 'A';
- }
- else if (mod == 11)
- {
- arg[loop] = 'B';
- }
- else if (mod == 12)
- {
- arg[loop] = 'C';
- }
- else if (mod == 13)
- {
- arg[loop] = 'D';
- }
- else if (mod == 14)
- {
- arg[loop] = 'E';
- }
- else if (mod == 15)
- {
- arg[loop] = 'F';
- }
- else
- {
- arg[loop] = mod;
- }
- n /= 16;
- loop++;
- }
- for (int rep = loop - 1; rep >= 0; rep--)
- {
- if (arg[rep] == 'A')
- {
- printf("A");
- }
- else if (arg[rep] == 'B')
- {
- printf("B");
- }
- else if (arg[rep] == 'C')
- {
- printf("C");
- }
- else if (arg[rep] == 'D')
- {
- printf("D");
- }
- else if (arg[rep] == 'E')
- {
- printf("E");
- }
- else if (arg[rep] == 'F')
- {
- printf("F");
- }
- else
- {
- printf("%d", arg[rep]); //sama aja kaya cout<<arg[rep];
- }
- }
- }
- void __CHOICE_TWO()
- {
- int decimal;
- cout<<"Input Decimal Digit : "<<endl;
- cin>>decimal;
- cout<<"\nDecimal to Octal : \n"<<endl;
- cout<<"Loading";
- _ANIMATE();
- cout<<"Result : ";
- decimal_to_octal(decimal);
- cout<<"\n\nDecimal to Hexadecimal : \n"<<endl;
- cout<<"Loading";
- _ANIMATE();
- cout<<"Result : ";
- decimal_to_hex(decimal);
- cout<<endl;
- }
- void __CHOICE_THREE()
- {
- int d1,m1,y1,d2,m2,y2,i,temp,sum=0,month[]={31,28,31,30,31,30,31,31,30,31,30,31};
- cout<<"Enter Date 1 : (DD-MM-YYYY) : "<<endl;
- cin>>d1>>m1>>y1;
- cout<<"Enter Date 2 : (DD-MM-YYYY) : "<<endl;
- cin>>d2>>m2>>y2;
- temp=d1;
- for(i=m1;i<m2+(y2-y1)*12;i++)
- {
- if(i>12)
- {
- i=1;
- y1++;
- }
- if(i==2)
- {
- if(y1%4==0 && (y1%100!=0 || y1%400==0))
- month[i-1]=29;
- else
- month[i-1]=28;
- }
- sum=sum+(month[i-1]-temp);
- temp=0;
- }
- sum=sum+d2-temp;
- char nama_bulan[12][20]= {"Januari", "Februari","Maret", "April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"};
- cout<<"Tanggal 1 = "<<d1<<" "<<nama_bulan[d1+1]<<" "<<y1<<endl;
- cout<<"Tanggal 2 = "<<d1<<" "<<nama_bulan[d2+1]<<" "<<y1<<endl;
- cout<<"Selisih = " <<sum<<endl;
- }
- int main()
- {
- system("color 0a");
- int menu;
- while(true)
- {
- cout<<"1. Operasi Pengurangan 3 Buah Matrix "<<endl;
- cout<<"2. Konversi Decimal Ke Octal dan Hexadecimal"<<endl;
- cout<<"3. Menghitung Selisih 2 Tangal "<<endl;
- cout<<"4. Exit"<<endl;
- do
- {
- cout<<"Masukkan Pilihan : "<<endl;
- cin>>menu;
- }while(menu<1 || menu>4);
- if(menu==1)
- {
- __CHOICE_ONE();
- system("echo. && pause");
- system("cls");
- }
- else if(menu==2)
- {
- __CHOICE_TWO();
- system("echo. && pause");
- system("cls");
- }
- else if(menu==3)
- {
- __CHOICE_THREE();
- system("echo. && pause");
- system("cls");
- }
- else
- {
- exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement