#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>
class kalkulator {
friend istream& operator >> (istream&, kalkulator&);
friend ostream& operator << (ostream&, const kalkulator&);
public :
kalkulator();
void menu();
int tambah();
int kurang();
int kali();
float bagi();
float perx();
private:
float a,b,c,hasil;
};
istream& operator>>(istream& in, kalkulator& masuk){
cout<<"\t Selamat datang di program kalkulator sederhana ini \n";
cout<<"\t Selamat mencoba \n";
cout<<"\t Semoga Bermanfaat untuk Kalian \n"<<endl;
cout<<"\t ==================================== \n";
cout<<"\t | PROGRAM KALKULATOR SEDERHANA |\n";
cout<<"\t | by ANDI FAISAL (12201398) |\n";
cout<<"\t | STIMIK ASIA |\n";
cout<<"\t ==================================== \n"<<endl;
cout<<"*********************************************\n";
cout<<"| KALKULATOR |\n";
cout<<"*********************************************\n";
cout<<"| ___ ___ ___ ___ ___ ___ |\n";
cout<<"| |x^2| | / | | + | | 7 | | 8 | | 9 | \n";
cout<<"| |___| |___| |___| |___| |___| |___| \n";
cout<<"| ___ ___ ___ ___ ___ ___ |\n";
cout<<"| |x^3| |1/x| | - | | 4 | | 5 | | 6 | \n";
cout<<"| |___| |___| |___| |___| |___| |___| \n";
cout<<"| ___ ___ ___ ___ ___ ___ |\n";
cout<<"| | n!| |x^y| | * | | 1 | | 2 | | 3 | \n";
cout<<"| |___| |___| |___| |___| |___| |___| \n";
cout<<"| ___ ___ ___ ___ ___ ___ |\n";
cout<<"| |CE | | C | | . | | 0 | |+/-| | = | \n";
cout<<"| |___| |___| |___| |___| |___| |___| \n";
cout<<"|___________________________________________|\n"<<endl;
cout<<"1. Tambah\n";
cout<<"2. Kurang\n";
cout<<"3. Kali\n";
cout<<"4. Bagi\n";
cout<<"5. Per x\n";
cout<<"6. Keluar\n"<<endl;
cout<<"Masukan pilihan anda : ";
int pilihan;
cin>>pilihan;
if (pilihan==1)
{
masuk.tambah();}
else if (pilihan==2)
{
masuk.kurang();}
else if (pilihan==3)
{
masuk.kali();}
else if (pilihan==4)
{
masuk.bagi();}
else if (pilihan==5)
{
masuk.perx();}
else if (pilihan==6)
{
cout<<"Anda telah keluar dari program"<<endl;}
else
cout<<"Inputan Anda Salah\n";
return in;
}
ostream& operator<<(ostream& out, const kalkulator& keluar){
out<<"\t Terima Kasih....:)"<<endl;
return out;}
kalkulator::kalkulator(){} //konstruktor
int kalkulator::tambah(){
cout<<"Masukan bilangan pertama : ";
cin>>a;
cout<<"Masukan bilangan kedua : ";
cin>>b;
hasil = a+b;
cout<<"Hasil tambah "<<a<<" + "<<b<<" = "<<hasil<<endl;}
int kalkulator::kurang(){
cout<<"Masukan bilangan pertama : ";
cin>>a;
cout<<"Masukan bilangan kedua : ";
cin>>b;
hasil=a-b;
cout<<"Hasil kurang "<<a<<" - "<<b<<" = "<<hasil<<endl;}
int kalkulator::kali(){
cout<<"Masukan bilangan pertama : ";
cin>>a;
cout<<"Masukan bilangan kedua : ";
cin>>b;
hasil=a*b;
cout<<"Hasil kali "<<a<<" * "<<b<<"= "<<hasil<<endl;}
float kalkulator::bagi(){
cout<<"Masukan bilangan pertama : ";
cin>>a;
cout<<"Masukan bilangan kedua : ";
cin>>b;
hasil=a/b;
cout<<"Hasil bagi "<<a<<" dan "<<b<<"= "<<hasil<<endl;}
float kalkulator::perx(){
cout<<"Masukan bilangan : ";
cin>>a;
hasil=1/a;
cout<<"Hasil 1 per x = "<<hasil<<endl;}
int main(){
kalkulator indri;
cin>>indri;
cout<<indri;
getch();
return 0;
}
Sabtu, 12 Januari 2013
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar