Jumat, 15 April 2011

Program C++ mencari bilangan terbesar dari 2 bilangan yang diinputkan


Algoritma :
Deskripsi
a,b      : integer

Deklarasi
    if ( a > b )
       then
              write(a)
else
then
              write(b)
endif

Berikut programnya :

#include <iostream.h>
#include <conio.h>

class terbesar{
friend istream& operator >> (istream&, terbesar&);
friend ostream& operator << (ostream&, const terbesar&);

public:
terbesar();
void bandingkan(){
     if (a > b)
        cout<< " Bilangan terbesar : "<<a;
     else
        cout<< " Bilangan terbesar : "<<b<<endl;
};
private:
     int a,b;
};

terbesar::terbesar(){
cout << "menentukan bilangan terbesar dari yang diinputkan\n" << endl;
}

istream& operator >>(istream& cin, terbesar& masukan){
     cout<<"masukan bilangan pertama : ";
     cin>>masukan.a;
     cout<<"masukan bilangan kedua : ";
     cin>>masukan.b;
     cout<<endl;

return cin;
}

ostream& operator << (ostream& out, const terbesar& keluaran){
     out<< " inilah yang terbesar "<<endl;

return out;
}

void main(){
terbesar bilangan;
cin>>bilangan;
bilangan.bandingkan();
cout<<bilangan;

getch();
}
Explanation:
At this time I wanted to try the program to find the largest number of 2 numbers are entered. Which of these programs use the election if ... else that is a> b. Seletah user input values ​​a and b values​​, the program will work by using the election to seek the greatest value of these two numbers are entered.

0 komentar:

Posting Komentar

Template by:

Free Blog Templates