Algoritma :
Deskripsi
r : integer
luas : float
Deklarasi
luas ß 3.14*r*r
write (luas)
Berikut programnya :
#include<iostream.h>
#include<conio.h>
void lingkaran()
{
int r;
cout<<"masukan nilai jari-jari : ";
cin>>r;
cout<<"Luas lingkaran = "<< 3.14*r*r<<endl;
}
int main() {
lingkaran();
return 0;
}
Program classnya :
#include <iostream.h>
#include <conio.h>
class luas {
friend istream& operator >> (istream&, luas&);
friend ostream& operator << (ostream&, const luas&);
public:
luas();
void hitung_luasnya(){ luas = 3.14*r*r;}
private:
int r;
float luas;
};
luas::luas(){
cout << "Program mencari luas lingkaran \n" << endl;
}
istream& operator >>(istream& cin, luas& masukan){
cout << "Masukkan jari-jari : "; cin >> masukan.r;
cout<<endl;
return cin;
}
ostream& operator << (ostream& out, const luas& keluaran)
{
out<< " Nilai jari- jari : " <<keluaran.r<<endl;
out<< " Luas lingkaran = "<<keluaran.luas<<endl;
return out;
}
void main(){
luas lingkaran;
cin>>lingkaran;
lingkaran.hitung_luasnya();
cout<<lingkaran;
getch();
}
Teman-teman juga bisa mendemokannya ke jeliot ,, check it out ....
Demo ke jeliot :
Fungsi Menghitung Luas Lingkaran
import jeliot.io.*;
public class luas {
public static void main()
{
int r ;
float luas;
System.out.print("Masukan jari-jari : ");
r = Input.readInt();
luas = (float)3.14*r*r;
System.out.print("Luas lingkaran = ");
System.out.print(luas);
}
}
Explanation:
The above program is a program to calculate the area of a circle by using the function. Which program would invoke the functionality. In this program using a variable r and spacious. The program will do the counting process with a predetermined formula. After users input the value of r the area of a circle will appear.
The above program is a program to calculate the area of a circle by using the function. Which program would invoke the functionality. In this program using a variable r and spacious. The program will do the counting process with a predetermined formula. After users input the value of r the area of a circle will appear.
0 komentar:
Posting Komentar