Overloading Volume
Bola
#include <cstdlib>
#include <iostream>
using namespace std;
class bilangan{
friend
istream& operator>>(istream&, bilangan&);
friend
ostream& operator<<(ostream&, bilangan&);
public :
bilangan();
void proses(int
x);
private :
double r,V;
};
bilangan::bilangan(){
cout<<"menghitung volume bola"<<endl;
}
void bilangan::proses(int x){
V=(4/3)*(3.14)*r*r*r;
}
istream& operator>>(istream& in, bilangan&
x){
cout<<"masukkan
jari-jari=";
in>>x.r;
}
ostream& operator<<(ostream& out,
bilangan& z){
out<<"volume=";
out<<z.V;
}
int main(int argc, char *argv[])
{
int z;
bilangan a;
cin>>a;
a.proses(z);
cout<<a<<endl;
system("PAUSE");
return
EXIT_SUCCESS;
}
Jika
diinputkan 3, maka hasilnya:
Tidak ada komentar:
Posting Komentar