POST Test Praktikum #2

Bentuk Class Untuk Menghitung Volume Kerucut, Tabung, Dan Bola

#include <iostream>

using namespace std;

class kerucut{
private:
int r,t;
float phi=3.14, volume;
public:
void input();
void hitungvolume();
void output();
};

void kerucut::input(){
cout<<“Masukkan Jari – Jari Alas = “; cin>>r;
cout<<“Masukkam Tinggi Kerucut = “; cin>>t;
}
void kerucut::hitungvolume(){
volume=1/(float)3*phi*r*r*t;
}
void kerucut::output(){
cout<<“Volume Kerucut = “<<volume;
}

class tabung{
private:
int r,t;
float phi=3.14, volume;
public:
void input();
void hitungvolume();
void output();
};
void tabung::input(){
cout<<“Masukkan Jari – Jari Alas = “; cin>>r;
cout<<“Masukkan Tinggi Tabung = “; cin>>t;
}
void tabung::hitungvolume(){
volume=phi*r*r*t;
}
void tabung::output(){
cout<<“Volume Tabung = “<<volume;
}

class bola{
private:
int r;
float phi=3.14, volume;
public:
void input();
void hitungvolume();
void output();
};
void bola::input(){
cout<<“Masukkan Jari – Jari Bola = “; cin>>r;
}
void bola::hitungvolume(){
volume=4/(float)3*phi*r*r*r;
}
void bola::output(){
cout<<“Volume Bola = “<<volume;
}
main(){
int pilih;
kerucut x;
tabung y;
bola z;

cout<<“\tMasukkan Pilihan Anda”<<endl;
cout<<“1. Mencari Volume Kerucut\n2. Mencari Volume Tabung\n3. Mencari Volume Bola”<<endl;
cin>>pilih;

switch(pilih){
case 1:
x.input(); cout<<endl;
x.hitungvolume();
x.output();
break;
case 2:
y.input(); cout<<endl;
y.hitungvolume();
y.output();
break;
case 3:
z.input(); cout<<endl;
z.hitungvolume();
z.output();
break;
default:
cout<<“Pilihan tidak ditemukan”;
break;

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s