Algoritma :
Deskripsi
r : integer
volume : float
Deklarasi
volume <= 4/3*3.14*r*r*r
write (volume)
Berikut Programnya :
#include<iostream.h>
#include<conio.h>
void bola()
{
int r,volume;
cout<<"masukan nilai jari-jari : ";
cin>>r;
cout<<"volume bola = "<<4/3*3.14*r*r*r<<endl;
}
int main() {
bola();
return 0;
}
#include <iostream.h>
#include <conio.h>
class volume {
friend istream& operator >> (istream&, volume&);
friend ostream& operator << (ostream&, const volume&);
public:
volume();
void hitung_volumenya(){ volume = 4/3*3.14*r*r*r;}
private:
int r;
float volume;
};
volume::volume(){
cout << "Program mencari volume bola \n" << endl;
}
istream& operator >>(istream& cin, volume& masukan){
cout << "Masukkan jari-jari : "; cin >> masukan.r;
cout<<endl;
return cin;
}
ostream& operator << (ostream& out, const volume& keluaran)
{
out<< " Nilai jari- jari : " <<keluaran.r<<endl;
out<< " volume bola = "<<keluaran.volume<<endl;
return out;
}
void main(){
volume bola;
cin>>bola;
bola.hitung_volumenya();
cout<<bola;
getch();
}
Post a Comment