Dalam kuliah pemrograman pasti kita akan di suruh untuk membuat sebuah kalkulator. Untuk itu maka penulis akan membagikan sourcecode program kalkulator yang penulis buat saat semester satu (mohon maaf masih sangat sederhna), semoga bermanfaat :).
#include <conio.h>
#include <iostream>
#include <math.h>
class kalkulator{
public :
void start();
void pilih1();
void pilih2();
void hitung();
void akar2();
void kin();
void kos();
void kan();
private :
float a,b,c;
int d;
char e,proses;
float hasil;
};
void kalkulator::start(){
cout<<"---------------------------------------------------------\n";
cout<<"- PROGRAM KALKULATOR B-IOZ v.1.0.1 -\n";
cout<<"---------------------------------------------------------\n";
cout<<"- -\n";
cout<<"- Ada dua pilihan : -\n";
cout<<"- -\n";
cout<<"- 1. Perhitungan biasa : -\n";
cout<<"- ( +, -, *, /, ^) -\n";
cout<<"- 2. Perhitungan siencetific : -\n";
cout<<"- (akar, sin, cos, tan) -\n";
cout<<"- -\n";
cout<<"- -\n";
cout<<"- ***** BY EFA-ONE as REZZHAI **** -\n";
cout<<"---------------------------------------------------------\n";
cout <<endl;
}
void kalkulator::pilih1(){
int pilih;
cout<<"Pilih biasa atau siencetific : ";
cin>>pilih;
switch(pilih)
{
case 1:
hitung();
break;
case 2:
pilih2();
break;
}
}
void kalkulator::pilih2(){
int pilih;
cout<<endl;
cout<<"1. Perhitungan akar bilangan\n";
cout<<"2. Perhitungan sin \n";
cout<<"3. Perhitungan cos \n";
cout<<"4. Perhitungan tan \n\n";
cout<<"Masukkan Piihan Anda : ";
cin>>pilih;
switch(pilih)
{
case 1:
akar2();
break;
case 2:
kin();
break;
case 3:
kos();
break;
case 4:
kan();
break;
}
}
void kalkulator::hitung(){
cout<<endl;
cout<<" Masukkan Dua buah bilagan saja \n";
cout<<" Fungsi Operator : \n";
cout<<" + = tambah (ex= 5+5) * = kali (ex= 5*5) \n";
cout<<" - = kurang (ex= 5-5) / = bagi (ex= 5+5) \n";
cout<<" ^ = pangkat (ex= 5^5) \n";
cout<<endl;
while(cin>>a>>proses>>b) {
switch(proses)
{
case '+':
hasil=a+b;
cout<<"Hasil "<<a<<" + " <<b<<" = "<<hasil<<endl;
cout<<endl;
break;
case '-':
hasil=a-b;
cout<<"Hasil "<<a<<" - " <<b<<" = "<<hasil<<endl;
cout<<endl;
break;
case '*':
hasil=a*b;
cout<<"Hasil "<<a<<" * " <<b<<" = "<<hasil<<endl;
cout<<endl;
break;
case '/':
hasil=a/b;
cout<<"Hasil "<<a<<" / " <<b<<" = "<<hasil<<endl;
cout<<endl;
break;
case '^':
int c;
hasil=1;
for(c=1; c<=b; c++){
hasil=hasil*a;
}
cout<<"Hasil "<<a<<"^" <<b<<" = "<<hasil<<endl;
cout<<endl;
break;
default:
break;
}
}
}
void kalkulator::akar2(){
cout<<endl;
cout<<"Masukkan nilai : ";
cin>>a;
hasil=sqrt(a);
cout<<endl;
cout<<"Nilai dari akar "<<a<<" = "<<hasil;
getch;
}
void kalkulator::kin(){
cout<<endl;
cout<<"Masukkan nilai : ";
cin>>d;
hasil=sin(d);
cout<<endl;
cout<<"Nilai dari sin "<<d<<" = "<<hasil;
getch;
}
void kalkulator::kos(){
cout<<endl;
cout<<"Masukkan nilai : ";
cin>>d;
hasil=cos(d);
cout<<endl;
cout<<"Nilai dari cos "<<d<<" = "<<hasil;
getch;
}
void kalkulator::kan(){
cout<<endl;
cout<<"Masukkan nilai : ";
cin>>d;
hasil=tan(d);
cout<<endl;
cout<<"Nilai dari tan "<<d<<" = "<<hasil;
getch;
}
int main()
{
kalkulator x;
x.start();
x:
x.pilih1();
char e;
cout<<"\nAnda Ingin Mengulang?(Y/N) ";
cin>>e;
cout<<endl;
if(e=='y'||e=='Y')goto x;
else
cout<<"Tekan X untuk keluar"<<endl;
return 0;
}
output:
0 komentar:
Posting Komentar