#include <cstdlib>
#include <iostream>
#include <string.h>
#include <conio.h>
#include <math.h>
#include <windows.h>
using namespace std;
class hitung
{
private:
float num1,num2,a,b,c,d,e;
float hasil;
int pilih;
public:
void judul();
void masukan();
void proses();
void tampilan();
void pangkat();
void pangkat_n();
void akar2();
void xin();
void xos();
void xan();
};
void hitung::judul()
{
HANDLE hConsole;
hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute
(hConsole, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout<<” *=*=*=*=*=*=*=*=*=*=*=*=*=*= BY *=*=*=*=*=*=*=*=*=*=*=*=*=*=”<<endl;
cout<<” *=*=*=*=*=*=*=*=*=*=*=*=*= M. Muhafid *=*=*=*=*=*=*=*=**=*=*=*=*=”<<endl;
cout<<” *=*=*=*=*=*=*=*=*=*=*=*= 10018053 =*=*=*=*=*=*=*=*=*=*=*=*=\n”<<endl;
cout<<” *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=”<<endl;
cout<<” **=*=*=*=*=*=*=*=*= WELCOME *=*=*=*=*=*=*=*=*=*=”<<endl;
cout<<” **=*=*=*=*=*=*=*=*= KALKULATOR DIGITAL *=*=*=*=*=*=*=*=*=*=”<<endl;
cout<<” *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=\n”<<endl;
cout<<endl;
}
void hitung::masukan()
{
HANDLE hConsole;
hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
cout<<” ================================================================\n”;
cout<<” ======= SILAHKAN MEMILIH OPERATOR YANG ANDA INGINKAN =======\n”;
cout<<” ================================================================\n”;
cout<<” ====================== 1. PERKALIAN ====================”;
cout<<endl;
cout<<” ====================== 2. PEMBAGIAN ====================”;
cout<<endl;
cout<<” ====================== 3. PENJUMLAHAN ====================”;
cout<<endl;
cout<<” ====================== 4. PENGURANGAN ====================”;
cout<<endl;
cout<<” ====================== 5. PANGKAT 2 ====================”;
cout<<endl;
cout<<” ====================== 6. PANGKAT n ====================”;
cout<<endl;
cout<<” ====================== 7. PERSEN (%) ====================”;
cout<<endl;
cout<<” ====================== 8. AKAR ====================”;
cout<<endl;
cout<<” ====================== 9. SIN ====================”;
cout<<endl;
cout<<” ====================== 10. COS ====================”;
cout<<endl;
cout<<” ====================== 11. TAN ====================\n”;
cout<<” ================================================================\n”;
SetConsoleTextAttribute
(hConsole, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout<<” PILIHAN ANDA ADALAH : “ ;
cin>>pilih;
cout<<endl;
system(“cls”);
switch(pilih)
{
case 1:
HANDLE hConsole;
hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute
(hConsole, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
cout<<” *****************”<<endl;
cout<<” *** PERKALIAN ***”<<endl;
cout<<” *****************\n”<<endl;
cout<<”Masukkan nilai ke 1 :”;
cin>>num1;
cout<<”Masukkan nilai ke 2 :”;
cin>>num2;
break;
case 2:
cout<<”*****************”<<endl;
cout<<”*** PEMBAGIAN ***”<<endl;
cout<<”*****************”<<endl;
cout<<”Masukkan nilai ke 1 :”;
cin>>num1;
cout<<”Masukkan nilai ke 2 :”;
cin>>num2;
break;
case 3:
cout<<”*******************”<<endl;
cout<<”*** PENJUMLAHAN ***”<<endl;
cout<<”*******************”<<endl;
cout<<”Masukkan nilai ke 1 :”;
cin>>num1;
cout<<”Masukkan nilai ke 2 :”;
cin>>num2;
break;
case 4:
cout<<”*******************”<<endl;
cout<<”*** PENGURANGAN ***”<<endl;
cout<<”*******************”<<endl;
cout<<”Masukkan nilai ke 1 :”;
cin>>num1;
cout<<”Masukkan nilai ke 2 :”;
cin>>num2;
break;
case 5 :
cout<<”*********************”<<endl;
cout<<”***** PANGKAT 2 *****”<<endl;
cout<<”*********************”<<endl;
pangkat();
break;
case 6 :
cout<<”*********************”<<endl;
cout<<”***** PANGKAT n *****”<<endl;
cout<<”*********************”<<endl;
pangkat_n();
break;
case 7:
cout<<”*******************”<<endl;
cout<<”*** PERSEN (%) ***”<<endl;
cout<<”*******************”<<endl;
cout<<”Masukkan nilai :”;
cin>>num1;
break;
case 8:
cout<<”*******************”<<endl;
cout<<”*** AKAR ***”<<endl;
cout<<”*******************”<<endl;
akar2();
break;
case 9:
cout<<”*******************”<<endl;
cout<<”*** SIN ***”<<endl;
cout<<”*******************”<<endl;
xin();
break;
case 10:
cout<<”*******************”<<endl;
cout<<”*** COS ***”<<endl;
cout<<”*******************”<<endl;
xos();
break;
case 11:
cout<<”*******************”<<endl;
cout<<”*** TAN ***”<<endl;
cout<<”*******************”<<endl;
xan();
break;
}
}
void hitung::proses()
{
switch(pilih)
{
case 1:
a=num1*num2;
cin.ignore();
break;
case 2:
b=num1/num2;
cin.ignore();
break;
case 3:
c=num1+num2;
cin.ignore();
break;
case 4:
d=num1-num2;
cin.ignore();
break;
case 7:
e=num1/100;
cin.ignore();
break;
}
}
void hitung::tampilan()
{
switch(pilih)
{
case 1:
cout<<endl;
cout<<”Hasil Perkalian=”<<endl<<num1<<”*”<<num2<<”=”<<a<<endl;
cout<<endl;
break;
case 2:
cout<<endl;
cout<<”Hasil Pembagian=”<<endl<<num1<<”/”<<num2<<”=”<<b<<endl;
cout<<endl;
break;
case 3:
cout<<endl;
cout<<”Hasil Penjumlahan=”<<endl<<num1<<”+”<<num2<<”=”<<c<<endl;
cout<<endl;
break;
case 4:
cout<<endl;
cout<<”Hasil Pengurangan=”<<endl<<num1<<”-”<<num2<<”=”<<d<<endl;
cout<<endl;
break;
case 7:
cout<<endl;
cout<<”Nilai Persen=”<<endl<<num1<<”/”<<100<<”=”<<e<<” % “<<endl;
cout<<endl;
break;
}
}
void hitung::pangkat(){
cout<<”masukkan nilai : “;
cin>>num1;
int hasil=1;
for(int i=1;i<=2;i++)
hasil*=num1;
cout<<”hasil pangkat= “<<hasil<<endl;
}
void hitung::pangkat_n(){
cout<<”contoh a^n”;
cout<<endl;
cout<<”masukkan nilai a : “;
cin>>num1;
cout<<”masukan pangkat : “;
cin>>a;
int hasil=1;
for(int i=1;i<=a;i++)
hasil*=num1;
cout<<”hasil pangkat= “<<hasil<<endl;
}
void hitung::akar2(){
cout<<”Masukkan nilai : “;
cin>>num1;
hasil=sqrt(num1);
cout<<endl;
cout<<”Nilai dari akar =”<<hasil<<endl;
}
void hitung :: xin(){
cout<<endl;
cout<<”Masukkan nilai : “;
cin>>num1;
hasil=sin(num1);
cout<<endl;
cout<<”Nilai dari sin “<<num1 <<” =”<<hasil<<endl;
}
void hitung :: xos(){
cout<<endl;
cout<<”Masukkan nilai : “;
cin>>num1;
hasil=cos(num1);
cout<<endl;
cout<<”Nilai dari cos “<<num1<<”=”<<hasil<<endl;
}
void hitung :: xan(){
cout<<endl;
cout<<”Masukkan nilai : “;
cin>>num1;
hasil=tan(num1);
cout<<endl;
cout<<”Nilai dari tan “<<num1<<”=”<<hasil<<endl;
}
int main(int argc, char *argv[])
{
class hitung mat;
char ulang;
x:
mat.judul();
mat.masukan();
mat.proses();
mat.tampilan();
cout<<”Anda Ingin Mengulang?(Y/N)”;
cin>>ulang;
cout<<endl;
system(“cls”);
if(ulang==’y'||ulang==’Y')goto x;
else
cout<<”Program Berakhir, Tekan ENTER untuk keluar”<<endl;
system(“PAUSE”);
return EXIT_SUCCESS;
}
0 comments:
Posting Komentar