KALKULATOR (DENGAN FUNGSI)
#include
#include
using namespace std;
class KALKULATOR
{
private:
float nilai1,nilai2,a,b,c,d,e;
float hasil;
int pilih;
public:
void judul();
void masukan();
void proses();
void tampilan();
};
void KALKULATOR::judul()
{
cout<<" "<
cout<<" WELCOME!!! "<
cout<<" Kalkulator Digital "<
cout<<" Tugas Mata Kuliah Algoritma dan Pemrograman \n"<
cout<<" By: Patricia Dianita Wijaya "<
cout<<" "<
cout<
}
void KALKULATOR::masukan()
{
cout<<"-------------------------------------------------------------------------\n";
cout<<" SILAHKAN MEMILIH OPERASI PENGHITUNGAN \n";
cout<<" \n";
cout<<" 1. Perkalian \n";
cout<
cout<<" 2. Pembagian \n";
cout<
cout<<" 3. Penjumlahan \n";
cout<
cout<<" 4. Pengurangan \n";
cout<
cout<<"_________________________________________________________________________\n\n\n";
cout<<"KETIK PILIHAN : " ;
cin>>pilih;
cout<
system("cls");
switch(pilih)
{
case 1:
cout<<"__________________"<
cout<<"___ PERKALIAN ____"<
cout<<"__________________\n\n"<
cout<<"Nilai 1:";
cin>>nilai1;
cout<<"Nilai 2 :";
cin>>nilai2;
break;
case 2:
cout<<"_________________"<
cout<<"___ PEMBAGIAN ___"<
cout<<"_________________\n\n"<
cout<<"Nilai 1 :";
cin>>nilai1;
cout<<"Nilai 2 :";
cin>>nilai2;
break;
case 3:
cout<<"__________________"<
cout<<"___ PENJUMLAHAN __"<
cout<<"__________________\n\n"<
cout<<"Nilai 1 :";
cin>>nilai1;
cout<<"Nilai 2 :";
cin>>nilai2;
break;
case 4:
cout<<"__________________"<
cout<<"___ PENGURANGAN __"<
cout<<"__________________\n\n"<
cout<<"Nilai 1 :";
cin>>nilai1;
cout<<"Nilai 2 :";
cin>>nilai2;
break;
}
}
void KALKULATOR::proses()
{
switch(pilih)
{
case 1:
a = nilai1*nilai2;
cin.ignore();
break;
case 2:
b = nilai1/nilai2;
cin.ignore();
break;
case 3:
c = nilai1+nilai2;
cin.ignore();
break;
case 4:
d = nilai1-nilai2;
cin.ignore();
break;
}
}
void KALKULATOR::tampilan()
{
switch(pilih)
{
case 1:
cout<
cout<<"Hasil Perkalian:"<<<<" * "<<<" = "<<
cout<
break;
case 2:
cout<
cout<<"Hasil Pembagian:"<<<<"/"<<<" = "<<
cout<
break;
case 3:
cout<
cout<<"Hasil Penjumlahan:"<<<<" + "<<<" = "<<
cout<
break;
case 4:
cout<
cout<<"Hasil Pengurangan:"<<<<" - "<<<" = "<<
cout<
break;
}
}
int main(int argc, char *argv[])
{
class KALKULATOR mat;
char ulang;
x:
mat.judul();
mat.masukan();
mat.proses();
mat.tampilan();
cout<<"\n\n\n\n"<
cout<<" MAU ULANG?\n\n "<
cout<<" (Kalo mau ulang, ketik 'y' atau 'Y') ";
cin>>ulang;
cout<
system("cls");
if(ulang=='y'||ulang=='Y')goto x;
else
cout<<"\n\n\n\n\n"<
cout<<" Bzzz.. END!\n\n"<
cout<<" ..BYE..BYE..BYE..BYE..BYE..\n\n\n\n"<
system("PAUSE");
return EXIT_SUCCESS;
}
No comments:
Post a Comment