Kamis, 21 April 2011

Program C++ Konversi Nilai Angka menjadi Nilai Huruf


Algoritma :
Deklarasi
nilai          : integer
nilai_huruf   : char

Deskripsi
    if ((nilai>0) && (nilai <=20))
       then nilai huruf = ’E’
else if ((nilai>20) && (nilai <=40))
then nilai huruf = ’D’
else if ((nilai>40) && (nilai <=60))
then nilai huruf = ’C’
else if ((nilai>60) && (nilai <=80))
then nilai huruf = ’B’
else if ((nilai>80) && (nilai <=100))
then nilai huruf = ’A’
else
write(nilai huruf tidak ada)
endif

Berikut programnya :

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

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

public:
konversi();
void huruf(){
     if ((nilai>0) && (nilai <=20))
        cout<<"nilai huruf : 'E'"<<endl;
     else if ((nilai>20) && (nilai <=40))
        cout<<"nilai huruf : 'D'"<<endl;
     else if ((nilai>40) && (nilai <=60))
        cout<<"nilai huruf : 'C'"<<endl;
     else if ((nilai>60) && (nilai <=80))
        cout<<"nilai huruf : 'B'"<<endl;
     else if ((nilai>80) && (nilai <=100))
        cout<<"nilai huruf : 'A'"<<endl;
        else
          cout<<"nilai huruf tidak ada"<<endl;
};
private:
     int nilai;
     char nilai_huruf;
};

konversi::konversi(){
cout << "Konversi dari nilai huruf menjadi nilai angka\n" << endl;
}

istream& operator >>(istream& cin, konversi& masukan){
     cout<<"masukan nilai angka : ";
     cin>>masukan.nilai;
     cout<<endl;

return cin;
}

ostream& operator << (ostream& out, const konversi& keluaran){
     out<< " terima kasih "<<endl;

return out;
}

void main(){
konversi bilangan;
cin>>bilangan;
bilangan.huruf();
cout<<bilangan;

getch();
}

Explanation:
In this program used to convert a numeric value into the value of the letters by using a selection / conditional if ... else. Which program algorithm described above. Using integer data types as input the numerical value and data type char to the output value of the letter.

2 komentar:

Unknown mengatakan...

makasih kk

Adhi Saputra mengatakan...

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


Apakah program ini bisa dijalankan ?

Posting Komentar

Template by:

Free Blog Templates