AD (728x60)

Diberdayakan oleh Blogger.

Sabtu, 07 Mei 2016

6.1

Share & Comment
Assalamualikum w.w.
Mencari rata-rata dari n bilangan bulat dengan menggunakan array.input c++:
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
class HitungRATA {
friend ostream& operator<<(ostream&, HitungRATA&);
friend istream& operator>>(istream&, HitungRATA&);
public:
float rata();
private:
int n;
int A[20];
};

istream& operator>>(istream& in, HitungRATA& a) {
cout << "Banyaknya data : ";
in >> a.n;
for (int i = 0; i < a.n; i++) {
cout << "Masukkan data ke- : " << i+1 << " > ";
cin >> a.A[i];
}
return in;
}

float HitungRATA::rata() {
float total=0;
for (int i = 0; i<n; i++) total = total + A[i];
return(total/n);
}

ostream& operator<<(ostream& out, HitungRATA& a) {
cout << "Rata-rata dari " << a.n;
cout << " bilangan adalah : "<< a.rata();
return out;
}

main() {
HitungRATA run;
cin >> run;
cout << run;
return 0;
 }

output c++:
input raptor:
output raptor:

Waalaikumsalam w.w.
http://al-likenet.blogspot.co.id/
http://dwiharlina.blogspot.co.id/
Tags:

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 komentar:

Posting Komentar

 
Copyright © safirizky blogs | Designed by Templateism.com