Sabtu, 16 April 2016

kasus 6.3

assalamualaikum wr.wb

c++ :
#include <iostream>
#include <math.h>

using namespace std;

class HitungStatistik {
friend ostream& operator<<(ostream&, HitungStatistik&);
friend istream& operator>>(istream&, HitungStatistik&);
public:
int maksimum();
private:
int maksimum2(int, int);
int n;
int A[20];
};

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

int HitungStatistik::maksimum2(int a, int b)
{ if (a>b) return(a);
else return(b);
}

int HitungStatistik::maksimum()
{ int temp = A[0];
for (int i = 1; i<n; i++)
temp = maksimum2(temp, A[i]);
return(temp);
}

ostream& operator<<(ostream& out, HitungStatistik& a) {
cout << "Nilai terbesar: " << a.maksimum();
return out;
}

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



0 komentar:

Posting Komentar