source code :
#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>
#include <string.h>
#include <math.h>
#include <conio.h>
//#include <cstdlib>
//#include <iostream>
//#include <math.h>
//#include <string>
using namespace std;
class calc
{
friend ostream & operator << ( ostream &, const calc & );
friend istream & operator >> ( istream &, calc & );
public:
void menu();
void tambah();
void kurang();
void kali();
void bagi();
void input();
void input1();
void pilihan1();
void pilihan2();
void sines();
void cosines();
void tangen();
void logku();
void sqrtku();
void expku();
private:
int pilih, pilih1, pilih2, pilih4;
char pilih3, pilih5;
float a;
float b;
float c;
float hasil;
float hasil1;
};
void calc::menu()
{
cout << endl;
cout << " \t\t\t+================================+ " << endl;
cout << " \t\t\t| CALCULATOR SEDERHANA | " << endl;
cout << " \t\t\t| | " << endl;
cout << " \t\t\t| Wisnu.Nugroho | " << endl;
cout << " \t\t\t| 10018134 | " << endl;
cout << " \t\t\t| C | " << endl;
cout << " \t\t\t+================================+ " << endl;
cout << endl;
cout << endl;
cout << " +-----------------------------------------------------+ " << endl;
cout << " | [ 1 ] Menu Pilihan operator Matematika | " << endl;
cout << " | --> [+][-][:][*] | " << endl;
cout << " | [ 2 ] Menu Pilihan fungsi-fungsi matematika | " << endl;
cout << " | --> [Sin][Cos][Tan][log][Sqrt][exp] | " << endl;
cout << " | [ 0 ] Keluar program | " << endl;
cout << " +-----------------------------------------------------+ " << endl;
cout << endl;
cout << "Masukan pilihan : ";
cin >> pilih1;
cout << endl;
if ( pilih1 == 1 )
{
pilihan1();
}
else if ( pilih1 == 2 )
{
pilihan2();
}
else if ( pilih1 == 0 )
{
exit( 0 );
}
}
void calc::pilihan1()
{
cout << "Oparator Matematika" << endl;
cout << "1. Tambah (+)" << endl;
cout << "2. Kurang (-)" << endl;
cout << "3. Kali (*)" << endl;
cout << "4. Bagi (:)" << endl;
cout << endl;
cout << "Masukkan No Oparator yang anda inginkan : ";
cin >> pilih2;
if ( pilih2 == 1 )
{
tambah();
}
else if ( pilih2 == 2 )
{
kurang();
}
else if ( pilih2 == 3 )
{
kali();
}
else if ( pilih2 == 4 )
{
bagi();
}
else
{
cout << "Oparator yang anda masukkan salah ";
}
}
void calc::pilihan2()
{
cout << "Oparator fungsi-fungsi matematika" << endl;
cout << "1. Sin " << endl;
cout << "2. Cos " << endl;
cout << "3. Tan " << endl;
cout << "4. log " << endl;
cout << "5. sqrt " << endl;
cout << "6. exp " << endl;
cout << endl;
cout << "Masukkan No Oparator yang anda inginkan : ";
cin >> pilih4;
if ( pilih4 == 1 )
{
sines();
}
else if ( pilih4 == 2 )
{
cosines();
}
else if ( pilih4 == 3 )
{
tangen();
}
else if ( pilih4 == 4 )
{
logku();
}
else if ( pilih4 == 5 )
{
sqrtku();
}
else if ( pilih4 == 6 )
{
expku();
}
else
{
cout << "Operator yang anda masukkan salah " << endl;
}
}
void calc::input()
{
cout << "Masukkan bilangan pertama :";
cin >> a;
cout << "Masukkan bilangan kedua :";
cin >> b;
}
void calc::tambah()
{
input();
hasil = a + b;
cout << "Hasilnya adalah : " << hasil << endl;
cout << endl;
}
void calc::kurang()
{
input();
hasil = a - b;
cout << "Hasilnya adalah : " << hasil << endl;
cout << endl;
}
void calc::kali()
{
input();
hasil = a * b;
cout << "Hasilnya adalah : " << hasil << endl;
cout << endl;
}
void calc::bagi()
{
input();
hasil = a / b;
cout << "Hasilnya adalah : " << hasil << endl;
cout << endl;
}
void calc::input1()
{
cout << "Masukkan bilangan:";
cin >> c;
}
void calc::sines()
{
input1();
hasil1 = sin( c );
cout << "Hasilnya adalah : " << hasil << endl;
cout << endl;
}
void calc::cosines()
{
input1();
hasil1 = cos( c );
cout << "Hasilnya adalah : " << hasil << endl;
cout << endl;
}
void calc::tangen()
{
input1();
hasil1 = tan( c );
cout << "Hasilnya adalah : " << hasil << endl;
cout << endl;
}
void calc::logku()
{
input1();
hasil1 = log( c );
cout << "Hasilnya adalah : " << hasil << endl;
cout << endl;
}
void calc::sqrtku()
{
input1();
hasil1 = sqrt( c );
cout << "Hasilnya adalah : " << hasil << endl;
cout << endl;
}
void calc::expku()
{
input1();
hasil1 = exp( c );
cout << "Hasilnya adalah : " << hasil << endl;
cout << endl;
}
main()
{
calc wisnu;
wisnu.menu();
system("PAUSE");
return EXIT_SUCCESS;
}
Minggu, 30 Oktober 2011
Langganan:
Posting Komentar (Atom)