Posts

Showing posts from February, 2015

Program C++ Menghitung Volume Bola

Image
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; } Program Classnya : #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 >>(is

Program C++ menghitung jarak titik A(x1,y1) dan B(x2,y2)

Image
Algoritma : Deskripsi AB : float x1,x2,y1,y2 : float Deklarasi AB = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) write (a,b) Berikut Programnya : #include <iostream.h> #include <conio.h> #include <math.h> class jarak { friend istream& operator >> (istream&, jarak&); friend ostream& operator << (ostream&, const jarak&); public: jarak(); void hitung(){      AB = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); }; private:     float x1,y1,x2,y2;     float AB; }; jarak::jarak(){ cout << "mencari jarak antara titik A(x1,y1) dan B(x2,y2)\n" << endl; } istream& operator >>(istream& cin, jarak& masukan){    cout << "Nilai titik A " <<endl;    cout << "Masukkan nilai x1 : ";   cin >> masukan.x1;    cout << "Masukkan nilai y1 : ";   cin >> masukan.y1;    cout << "