Program Kalkulator dengan Dev C++

#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
class kalkulator{
private:
int pilihan;
float a,b,hasil;
public:
kalkulator();
void menu();
void tambah();
void kurang();
void kali();
void bagi();
void pangkat();
void akar2();
void sinus();
void cosinus();
void tangen();
};
kalkulator::kalkulator (){a=0;b=0;}
void kalkulator::menu(){
cout<<endl;
cout<<“********MENU UTAMA********”<<endl;
cout<<“1=PENJUMLAAN”<<endl;
cout<<“2=PENGURANGAN” <<endl;
cout<<“3=PERKALIAN”<<endl;
cout<<“4=PEMBAGIAN” <<endl;
cout<<“5=PANGKAT” <<endl;
cout<<“6=AKAR” <<endl;
cout<<“7=SIN”<<endl;
cout<<“8=COS”<<endl;
cout<<“9=TAN”<<endl<<endl;
cout<<“Pilihan anda: “;
cin>>pilihan;
switch(pilihan){
case 1: kalkulator::tambah();break;
case 2: kalkulator::kurang();break;
case 3: kalkulator::kali();break;
case 4: kalkulator::bagi();break;
case 5: kalkulator::pangkat();break;
case 6: kalkulator::akar2();break;
case 7: kalkulator::sinus();break;
case 8:kalkulator::cosinus();break;
case 9:kalkulator::tangen();break;
default: cout<<“pilihan anda tidak benar”;break;
}
}
void kalkulator::tambah(){
cout<<“Masukkan angka: “<<endl;
cin>>a;  cout<<“+”<<endl;
cin>>b;
cout<<“=”<<a+b<<endl;
}
void kalkulator::kurang(){
cout<<“Masukkan angka: “<<endl;
cin>>a;
cout<<“-“<<endl;
cin>>b;
cout<<“=”<<a-b<<endl;
}
void kalkulator::kali(){
cout<<“Masukkan angka: “<<endl;
cin>>a;
cout<<“x”<<endl;
cin>>b;
cout<<“=”<<a*b<<endl;
}
void kalkulator::bagi(){
cout<<“Masukkan angka: “<<endl;
cin>>a;
cout<<“:”;
cin>>b;
cout<<“=”<<a/b<<endl;
}
void kalkulator::pangkat(){
cout<<“masukan angka: “<<endl;
cin>>a;
cout<<“pangkatnya: “;
cin>>b;
hasil=pow(a,b);
cout<<hasil<<endl;
}
void kalkulator::akar2(){
cout<<“akar dari: “;
cin>>a;
hasil=sqrt(a);
cout<<hasil<<endl;
}
void kalkulator::sinus(){
cout<<“sin dari: “;
cin>>a;
hasil=sin(a*3.14159265/180);
cout<<hasil<<endl;
}
void kalkulator::cosinus(){
cout<<“cos dari: “;
cin>>a;
hasil=cos(a*3.14159265/180);
cout<<hasil<<endl;  }
void kalkulator::tangen(){
cout<<“tan dari: “;
cin>>a;
hasil=tan(a*3.14159265/180);
cout<<hasil<<endl;
}
int main(int argc, char *argv[])
{
a1:
kalkulator x;
x.menu();
int lanjutkan;
cout<<endl<<“1= lanjutkan “;
cout<<endl<<“0= quit “;
cin>>lanjutkan;
if(lanjutkan==1){
goto a1;}
else
return EXIT_SUCCESS;
}
This entry was posted in Tugas sdata. Bookmark the permalink.

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