Selasa, 17 April 2012

Konversi Nilai Menjadi Huruf

algoritma Konversi_nilai
mengkonversikan nilai angka menjadi nilai huruf
deklarasi
nilai :integer
nilai_huruf: char
deskripsi:
read nilai
if (nlai >0) and (nilai <=20) then nilai E
if (nlai >20) and (nilai <=40) then nilai D
if (nlai >40) and (nilai <=60) then nilai C
if (nlai >60) and (nilai <=80) then nilaiB
else nilai_huruf A
endif
write (nilai_huruf)


#include <cstdlib>
#include <iostream>

using namespace std;
class Nilai{
      friend ostream& operator<<(ostream&, Nilai&);
      friend istream& operator>>(istream&, Nilai&);
      public:
      Nilai(){
              if ((nilai>0) &&(nilai <=20))
              nilai_huruf ='E';
              else if((nilai>20) &&(nilai <=40))
              nilai_huruf='D';
              else if((nilai>40) &&(nilai <=60))
              nilai_huruf='C';
              else if((nilai>60) &&(nilai <=80))
              nilai_huruf='B';
              else nilai_huruf ='A';
              }
              private:
             int nilai;
             char nilai_huruf;
             };
             istream& operator>>(istream& in, Nilai& masukan){
                      cout<<"masukkan nilai angka=";
                      in>>masukan.nilai;
                      return in;
                      };
                      ostream& operator<<(ostream& out, Nilai& keluaran){
                               out<<"Nilai angka:"<<keluaran.nilai<<endl;
                               out<<"Nilai huruf:"<<keluaran.nilai_huruf;
                               return out;
                               }
                             
                               int main(){
                                    Nilai angka;
                                    cin>>angka;
                                    angka.konversikan();
                                    cout<<angka;
                                    }
                                                


    system("PAUSE");
    return EXIT_SUCCESS;
}

Tidak ada komentar:

Posting Komentar