Menghitung Volume Bola


#include <cstdlib>
#include <iostream>
#include <conio.h>

using namespace std;

class Volume {
 friend ostream& operator<<(ostream&, const Volume&);
 friend istream& operator>>(istream&, Volume&);

 public:
 void proses();

private:
 int r;
 double hasil;
 };
 istream& operator>>(istream& in, Volume& masukan){
 cout<<"Menghitung Volume Bola\n";
 cout<<"Masukkan nilai r : ";
 cin>>masukan.r;

 return in;
 }

ostream& operator<<(ostream& out, const Volume& keluaran){
 out<<endl;
 out<<"Nilai r: "<<keluaran.r<<endl;
 out<<"Hasil Volume Bola adalah : "<<keluaran.hasil<<endl;
 return out;
 }
 void Volume::proses(){
 hasil=(4/3*3.14*r*r*r);
 }

main(){
Volume x;
cin>>x;
x.proses();
cout<<x;

system("PAUSE");
getch();
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s