saling berbagi ya gan,,,,
low ada soal pemrograman gini...
.....
Buatlah class Volume yang memiliki public function untuk menghitung
Volume tabung, volume kubus, volume bola
inputan dari keyboard
Output yang diharapkan
Program untuk menghitung Volume
1. voulume tabung
masukan jari-jari :
masukan tinggi :
Volume Bola :
2. Volume kubus
masukan sisi :
volume kubus :
3. volume bola :
masukan jari-jari :
volume bola :
ne jawaban nya....
#include <cstdlib>
#include <iostream>
using namespace std;
class Volume {
public :
Volume(){
cout<<"class Volume dibangun"<<endl;
}
~Volume(){
cout<<"class Volume dihancurkan"<<endl;
}
void input(){
int input;
cout<<"Masukan jari-jari :";cin>>input;
cout<<"Masukan tinggi :";cin>>input;
cout<<"Masukan sisi :";cin>>input;
r = input;
h = input;
s = input;
}
void tabung()
{
vol = 3.14*r*r*h;
}
void kubus()
{
vlm = s*s*s;
}
void bola ()
{
volume = 4/3*3.14*r*r*r;
}
void output()
{
cout<<"Volume tabung= "<<vol<<endl;
cout<<"Volume kubus= "<<vlm<<endl;
cout<<"Volume bola= "<<volume<<endl;
}
private :int vol;
int vlm;
int volume;
int r;
int h;
int s;
};
int main()
{
Volume a;
a.input();
a.tabung();
a.kubus();
a.bola ();
a.output();
system("PAUSE");
return EXIT_SUCCESS;
}
ne output nya dari C++...
0 komentar:
Posting Komentar