Assalamualaikum, selamat pagi teman-teman semua.. kali ini saya akan posting program menentukan nilai dengan menggunakan class.. script programnya tidak terlalu panjang kok teman-teman..
Langsung saja ke contoh programnya yah :
Hasil program setelah di compile :
Script program :
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#using namespace std;
class Nilai{
public():
Nilai();
void input();
void output();
private():
int a,b,c,n;
};
Nilai::Nilai(){
cout<<"Nama : Dedy Saputra"<<endl;
cout<<"Prodi : Teknik Informatika";
cout<<endl<<endl;
}
void Nilai::input(){
cout<<"Masukkan nilai a : ";cin>>a;
cout<<"Masukkan nilai b : ";cin>>b;
cout<<"Masukkan nilai c : ";cin>>c;
}
void Nilai::output(){
n=(a+b+c)/3;
if(a>=80 && n<=100){
cout<<"Nilai A";}
else if(n>=65 && n<80){
cout<<"Nilai B";}
else if(n>=55 && n<65){
cout<<"Nilai C";}
else if(n>=30 && n<55){
cout<<"Nilai D";}
else{
cout<<"Gak Lulus";}
cout<<endl;
}
int main(int argc, char *argv[]) {
Nilai n;
n.input();
n.output();
return 0;}
}}}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#using namespace std;
class Nilai{
public():
Nilai();
void input();
void output();
private():
int a,b,c,n;
};
Nilai::Nilai(){
cout<<"Nama : Dedy Saputra"<<endl;
cout<<"Prodi : Teknik Informatika";
cout<<endl<<endl;
}
void Nilai::input(){
cout<<"Masukkan nilai a : ";cin>>a;
cout<<"Masukkan nilai b : ";cin>>b;
cout<<"Masukkan nilai c : ";cin>>c;
}
void Nilai::output(){
n=(a+b+c)/3;
if(a>=80 && n<=100){
cout<<"Nilai A";}
else if(n>=65 && n<80){
cout<<"Nilai B";}
else if(n>=55 && n<65){
cout<<"Nilai C";}
else if(n>=30 && n<55){
cout<<"Nilai D";}
else{
cout<<"Gak Lulus";}
cout<<endl;
}
int main(int argc, char *argv[]) {
Nilai n;
n.input();
n.output();
return 0;}
}}}
Selamat mencoba dan semoga sukses :)
Salam Anak IT (y)
0 Response to "Nilai (class) || Dev c++"
Post a Comment