Program kalkulator sederhana C++
Diposting oleh sam_zhoel di 06.21 0 komentar Jumat, 15 April 2011
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
class KALKULATOR{
friend ostream & operator << ( ostream &, const KALKULATOR & );
friend istream & operator >> ( istream &, KALKULATOR & );
public:
void MENU();
void ulang();
void tambah();
void kurang();
void kali();
void bagi();
void INPUT1();
void INPUT2();
void pilihan1();
void pilihan2();
void pilihan3();
void sines();
void cosines();
void tangen();
void logku();
void log10ku();
void sqrtku();
void expku();
private:
char opt;
int pilih;
float hasil0;
float hasil1;
float a;
float b;
float c;
};
void KALKULATOR::MENU(){
cout << endl;
cout << " |===================================|" << endl;
cout << " | KALKULATOR SEDERHANA |" << endl;
cout << " |===================================|" << endl;
cout << " |===================================|" << endl;
cout << " | http://samsulfti.blogspot.com/ |" << endl;
cout << " |===================================|" << endl;
cout << endl;
cout << " |==================================================================|" << endl;
cout << " [ B ] Menu Pilihan1 kalkulator Biasa ]" << endl;
cout << " [ F ] Menu Untuk Kalkulator fungsi Matematika[sin][cos][tgen][dll] ]" << endl;
cout << " [ ext ] Keluar program ]" << endl;
cout << " |==================================================================|" << endl;
cout << " Pilih Kalkulator Yang Akan Di Gunakan :";
cin >> opt;
if ( opt == 'B' ){
pilihan1();
}
else if ( opt == 'F' ){
pilihan2();
}
else if ( opt == 'ext' ){
exit(0);
}
}
void KALKULATOR::pilihan1(){
cout << "Operator Yang Akan Di Gunakan" << endl;
cout << "1. Tambah (+)" << endl;
cout << "2. Kurang (-)" << endl;
cout << "3. Kali (*)" << endl;
cout << "4. Bagi (/)" << endl;
cout << "Pilih Operator yang akan di gunakan : ";
cin >> opt;
if ( opt == '+' ){
tambah();
}
else if ( opt == '-' ){
kurang();
}
else if ( opt == '*' ){
kali();
}
else if ( opt == '/' ){
bagi();
}
else {
cout << " Maaf Operator Yang Anda Masukan Tidak Tersedia ";
}
}
void KALKULATOR::pilihan2(){
cout << "Operator fungsi matematika" << endl;
cout << "1. Sin [ S ] " << endl;
cout << "2. Cos [ C ]" << endl;
cout << "3. Tan [ T ]" << endl;
cout << "4. log [ L ]" << endl;
cout << "5. log10 [ L10]" << endl;
cout << "6. sqrt [ Sq ]" << endl;
cout << "7. exp [ Ep ]" << endl;
cout << "Pilih Operator yang akan di gunakan : ";
cin >>opt;
if ( opt == 'S' ){
sines();
}
else if ( opt == 'C' ){
cosines();
}
else if ( opt == 'Tg' ){
tangen();
}
else if ( opt == 'L' ){
logku();
}
else if ( opt == 'L10' ){
log10ku();
}
else if ( opt == 'Sq' ){
sqrtku();
}
else if ( opt == 'Ep' ){
expku();
}
else {
cout << " Maaf Operator Yang Anda Masukan Tidak Tersedia ";
}
}
void KALKULATOR::INPUT1(){
cout << "Masukkan bilangan pertama:";
cin >> a;
cout << "Masukkan bilangan kedua:";
cin >> b;
}
void KALKULATOR::tambah(){
INPUT1();
hasil0 = a + b;
cout <<"Hasilnya Adalah:"<< hasil0<<endl;
}
void KALKULATOR::kurang(){
INPUT1();
hasil0 = a - b;
cout <<"Hasilnya Adalah:"<< hasil0<<endl;
}
void KALKULATOR::kali(){
INPUT1();
hasil0 = a * b;
cout <<"Hasilnya Adalah:"<< hasil0<<endl;
}
void KALKULATOR::bagi(){
INPUT1();
hasil0 = a / b;
cout <<"Hasilnya Adalah:"<< hasil0<<endl;
}
void KALKULATOR::INPUT2(){
cout << "Masukkan bilangan:";
cin >> c;
}
void KALKULATOR::sines(){
INPUT2();
hasil1 = sin( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
void KALKULATOR::cosines(){
INPUT2();
hasil1 = cos( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
void KALKULATOR::tangen(){
INPUT2();
hasil1 = tan( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
void KALKULATOR::logku(){
INPUT2();
hasil1 = log( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
void KALKULATOR::log10ku(){
INPUT2();
hasil1 = log10( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
void KALKULATOR::sqrtku(){
INPUT2();
hasil1 = sqrt( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
void KALKULATOR::expku(){
INPUT2();
hasil1 = exp( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
main(){
KALKULATOR pheewe;
pheewe.MENU();
system("PAUSE");
return EXIT_SUCCESS;
}
#include <cstdlib>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
class KALKULATOR{
friend ostream & operator << ( ostream &, const KALKULATOR & );
friend istream & operator >> ( istream &, KALKULATOR & );
public:
void MENU();
void ulang();
void tambah();
void kurang();
void kali();
void bagi();
void INPUT1();
void INPUT2();
void pilihan1();
void pilihan2();
void pilihan3();
void sines();
void cosines();
void tangen();
void logku();
void log10ku();
void sqrtku();
void expku();
private:
char opt;
int pilih;
float hasil0;
float hasil1;
float a;
float b;
float c;
};
void KALKULATOR::MENU(){
cout << endl;
cout << " |===================================|" << endl;
cout << " | KALKULATOR SEDERHANA |" << endl;
cout << " |===================================|" << endl;
cout << " |===================================|" << endl;
cout << " | http://samsulfti.blogspot.com/ |" << endl;
cout << " |===================================|" << endl;
cout << endl;
cout << " |==================================================================|" << endl;
cout << " [ B ] Menu Pilihan1 kalkulator Biasa ]" << endl;
cout << " [ F ] Menu Untuk Kalkulator fungsi Matematika[sin][cos][tgen][dll] ]" << endl;
cout << " [ ext ] Keluar program ]" << endl;
cout << " |==================================================================|" << endl;
cout << " Pilih Kalkulator Yang Akan Di Gunakan :";
cin >> opt;
if ( opt == 'B' ){
pilihan1();
}
else if ( opt == 'F' ){
pilihan2();
}
else if ( opt == 'ext' ){
exit(0);
}
}
void KALKULATOR::pilihan1(){
cout << "Operator Yang Akan Di Gunakan" << endl;
cout << "1. Tambah (+)" << endl;
cout << "2. Kurang (-)" << endl;
cout << "3. Kali (*)" << endl;
cout << "4. Bagi (/)" << endl;
cout << "Pilih Operator yang akan di gunakan : ";
cin >> opt;
if ( opt == '+' ){
tambah();
}
else if ( opt == '-' ){
kurang();
}
else if ( opt == '*' ){
kali();
}
else if ( opt == '/' ){
bagi();
}
else {
cout << " Maaf Operator Yang Anda Masukan Tidak Tersedia ";
}
}
void KALKULATOR::pilihan2(){
cout << "Operator fungsi matematika" << endl;
cout << "1. Sin [ S ] " << endl;
cout << "2. Cos [ C ]" << endl;
cout << "3. Tan [ T ]" << endl;
cout << "4. log [ L ]" << endl;
cout << "5. log10 [ L10]" << endl;
cout << "6. sqrt [ Sq ]" << endl;
cout << "7. exp [ Ep ]" << endl;
cout << "Pilih Operator yang akan di gunakan : ";
cin >>opt;
if ( opt == 'S' ){
sines();
}
else if ( opt == 'C' ){
cosines();
}
else if ( opt == 'Tg' ){
tangen();
}
else if ( opt == 'L' ){
logku();
}
else if ( opt == 'L10' ){
log10ku();
}
else if ( opt == 'Sq' ){
sqrtku();
}
else if ( opt == 'Ep' ){
expku();
}
else {
cout << " Maaf Operator Yang Anda Masukan Tidak Tersedia ";
}
}
void KALKULATOR::INPUT1(){
cout << "Masukkan bilangan pertama:";
cin >> a;
cout << "Masukkan bilangan kedua:";
cin >> b;
}
void KALKULATOR::tambah(){
INPUT1();
hasil0 = a + b;
cout <<"Hasilnya Adalah:"<< hasil0<<endl;
}
void KALKULATOR::kurang(){
INPUT1();
hasil0 = a - b;
cout <<"Hasilnya Adalah:"<< hasil0<<endl;
}
void KALKULATOR::kali(){
INPUT1();
hasil0 = a * b;
cout <<"Hasilnya Adalah:"<< hasil0<<endl;
}
void KALKULATOR::bagi(){
INPUT1();
hasil0 = a / b;
cout <<"Hasilnya Adalah:"<< hasil0<<endl;
}
void KALKULATOR::INPUT2(){
cout << "Masukkan bilangan:";
cin >> c;
}
void KALKULATOR::sines(){
INPUT2();
hasil1 = sin( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
void KALKULATOR::cosines(){
INPUT2();
hasil1 = cos( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
void KALKULATOR::tangen(){
INPUT2();
hasil1 = tan( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
void KALKULATOR::logku(){
INPUT2();
hasil1 = log( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
void KALKULATOR::log10ku(){
INPUT2();
hasil1 = log10( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
void KALKULATOR::sqrtku(){
INPUT2();
hasil1 = sqrt( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
void KALKULATOR::expku(){
INPUT2();
hasil1 = exp( c );
cout <<"Hasilnya Adalah:"<< hasil1<<endl;
}
main(){
KALKULATOR pheewe;
pheewe.MENU();
system("PAUSE");
return EXIT_SUCCESS;
}
Program tahun kabisat ( jeliot )
Diposting oleh sam_zhoel di 08.05 0 komentar Selasa, 12 April 2011
import jeliot.io.*;
public class tahun_kabisat{
int x;
public int bil(int x){
return x;
}
public final void kabisat()
{
int bil;
bil=Input.readInt();
if(bil % 4 == 0)
{
System.out.print("Tahun kabisat.\n");
}
else
{
System.out.print("Tahun bukan kabisat.\n");
}
System.out.print(bil);
}
public tahun_kabisat()
{
System.out.print("Program untuk menampilkan tahun kabisat");
System.out.print("\n");
}
}
public class MyClass {
public static void main() {
tahun_kabisat x = new tahun_kabisat();
x.kabisat();
System.out.print("\n");
}
}
public class tahun_kabisat{
int x;
public int bil(int x){
return x;
}
public final void kabisat()
{
int bil;
bil=Input.readInt();
if(bil % 4 == 0)
{
System.out.print("Tahun kabisat.\n");
}
else
{
System.out.print("Tahun bukan kabisat.\n");
}
System.out.print(bil);
}
public tahun_kabisat()
{
System.out.print("Program untuk menampilkan tahun kabisat");
System.out.print("\n");
}
}
public class MyClass {
public static void main() {
tahun_kabisat x = new tahun_kabisat();
x.kabisat();
System.out.print("\n");
}
}
Langganan:
Postingan (Atom)