Senin, 11 April 2011

Program Menghitung Luas Lingkaran dan Volume Bola

Algoritma :

DEKLARASI
r         : integer
l,v    : real 
DESKRIPSI :
read ( r )
l  =  (4/3)*3.14*(r*r);
v =  (4/3)*3.14*(r*r*r);
write(luas, volume)

Listing Program

#include <iostream.h>
#include <conio.h>
class bola {
    friend istream& operator>>(istream&, bola&);
    friend ostream& operator << (ostream&, bola&);
public:
    bola(){};
    float hitung();
private:
    int r;
    int l,v;
};
istream& operator>>(istream& in, bola& m){
    cout << "Masukkan Jari-jari : ";
    in >> m.r;
    return in;
}
ostream& operator << (ostream& out,bola& m){
m.hitung();
out << "Luas bola = " << m.l << endl;
out << "Volume bola = " << m.v << endl;
return out;
}
float bola::hitung(){
l=(4/3)*3.14*(r*r);
v=(4/3)*3.14*(r*r*r);
    return 0;
}
void main(){
bola x;
cin >> x;
cout << x;
    return;
}

Tidak ada komentar:

Posting Komentar