Mau Tau cara ngitung volume Bola dan luas lingkaran dengan Dev C++ , ne aku kasi programnya, uuupsss... hampir lupa, ada versi javanya juga loch,di lihat ya...
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
const float phi=3.14;
class bola
{
public:
void Bola ();
void volume ();
private:
int r;
float jumlah;
};
void bola::Bola()
{
cout<<endl;
cout<<"Menghitung Luas lingkaran"<<endl;
cout<<"masukkan Jari-Jari: "; cin>>r;
jumlah = phi*r*r;
cout<<"Luas lingkaran Adalah: "<<jumlah<<endl;
}
void bola::volume ()
{
cout<<endl;
cout<<"Menghitung Volume Bola"<<endl;
cout<<"Masukkan Jari-jari bola: "; cin>>r;
jumlah=phi*r*r*r*3/4;
cout<<"Volume Bola Adalah: "<<jumlah<<endl;
}
int main(int argc, char *argv[])
{
char pilih;
bola bol;
bola vol;
label:
cout<<"Menghitung Luas Lingkaran dan volume Bola"<<endl;
cout<<" 1. Menghitung Luas Lingkaran"<<endl;
cout<<" 2. Menghitung Volume Bola "<<endl;
cout<<" Pilih Menu Yang Di inginkan: ";
cin>>pilih;
switch (pilih)
{
case '1' : bol.Bola(); break;
case '2' : vol.volume(); break;
default : cout<<"Pilih kembali"<<endl; goto label; break;
}
system("PAUSE");
return EXIT_SUCCESS;
}
setelah di compile:
Versi JAVA
import jeliot.io.*;
public class GlobalMembers
{
public static void main()
{
ling_bola x = new ling_bola();
x.masukan();
System.out.print(" hasilnya adalah \n");
x.cara();
}
}
public class ling_bola
{
public final void masukan()
{
System.out.print("masukkan nilai r :");
r = Input.readInt();
}
public final void cara()
{
phi +=3.14;
volume =(4/3)*pi*r*r*r;
luas =phi*r*r;
System.out.print("luas =");
System.out.print(luas);
System.out.print("\n");
System.out.print("volume =");
System.out.print(volume);
System.out.print("\n");
}
private int r;
private float phi ;
private float volume ;
private float luas ;
}
Selamat Mencoba ^_^

Tidak ada komentar:
Posting Komentar