#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
class Nilai{
friend ostream&operator<<(ostream&,Nilai&);
friend istream&operator>>(istream&,Nilai&);
public:
Nilai(){};
void konversikan(){
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;
}
int main(int argc, char** argv) {
Nilai angka;
cin>>angka;
angka.konversikan();
cout<<angka;
return 0;
}
Tidak ada komentar:
Posting Komentar