Menghitung Luas dan Volume Bola dengan C++
Diketahui sebuah bola dengan diameter (x), buatlah aplikasi untuk menghitung Luas dan Volume bola tersebut.
rumus luas bola adalah : 4*phi*r*r
rumus volume bola adalah : 4/3*phi*r*r*r
Kode aplikasi aplikasi.app
#include <iostream.h>
#include <conio.h>
#include “rumus.h”
int d;
void main()
{
cout<<”PROGRAM MENGHITUNG VOLUME DAN LUAS BOLA”;
cout<<endl;
cout<<”—————————————–”;
cout<<endl;
cout<<”Masukkan nilai Diameter bola : “;
cin>>d;
cout<<endl;
cout<<”Volume bola : “<<volume(d)<<” cm”;
cout<<endl;
cout<<”Luas bola : “<<luas(d)<<” cm”;
getch();
}
Kode Header rumus.h (disimpan dengan file type header)
#include <iostream.h>
#include <math.h>
const float phi = 3.14;
float r;
float volume (int d);
float volume (int d)
{
r = d/2;
return (4/3)*phi*pow(r,3);
}
float luas (int d);
float luas (int d)
{
r = d/2;
return 4*phi*pow(r,2);
}


Recent Comments