Rabu, 23 Maret 2011

 Program Mencari Total Dari 1-n

#include <iostream.h>
#include <conio.h>
class total
{
  friend istream & operator >> ( istream &, total& );
  friend ostream & operator<< ( ostream &, total& );
public:
  total();
void tambah(){jumlah = 0;
for (i = 1; i<=n; i++)
jumlah += i;
}
private:
  int n,i,jumlah;
};
total::total()
{cout<<"PROGRAM MENCARI TOTAL DARI 1 - N"<<endl;
};
istream & operator >> ( istream & in, total & msuk )
{
  cout << "masukkan bilangan  : " ;
  in >> msuk.n;
  return in;
}
ostream & operator<< ( ostream &out, total& keluar)
{
  out<<"hasilnya totalnya = "<<keluar.jumlah<<endl;
return out;
}
main()
{
  total hu;
  cin >> hu;
  hu.tambah();
  cout<<hu;
  getch();
  return 0;
}

Tidak ada komentar:

Posting Komentar