PROGRAM

January 13, 2009 at 2:38 am (Konsep pemrograman, materi perkuliahan)

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

float hitung_rata(float N1, float N2, float N3);
void cetak(char nama[20],int kelas,char nim[20],float N1,float N2,float N3,char status[20]);
void bintang ();
void penjelasan();
void masukkan (float*N1,float*N2,float*N3);

void main()
{
//deklarasi variable
char nama [20];
char nim [12], status [20];
float N1,N2,N3,NR;
int kelas;

//baca input
penjelasan();
cout<<“NAMA = “;
cin>>nama;
cout<<“KELAS = “;
cin>>kelas;
cout<<“NIM = “;
cin>>nim;

masukkan(&N1,&N2,&N3);
//proses
if(kelas ==1)
{
if((N1>75)&&(N2>75)&&(N3>75))
strcpy(status,”LULUS”);
else
strcpy(status,”TIDAK LULUS”);
}
else if((kelas ==2) ||(kelas==3))
{
NR=hitung_rata(N1,N2,N3);
if (NR>75)
strcpy(status,”LULUS”);
else
strcpy(status,”TIDAK LULUS”);
}
else
strcpy(status,”SALAH KELAS”);

//cetak output
bintang();
cetak(nama,kelas,nim,N1,N2,N3,status);
bintang();
}

float hitung_rata(float N1, float N2, float N3)
{
float hasil;
hasil = (N1+N2+N3)/3;
return(hasil);
}

void penjelasan()
{
bintang();
cout<<“PROGRAM INI MENCETAK STATUS HASIL KE-3 NILAI MAHASISWA”<<endl;
cout<<“DENGAN INPUT NAMA, KELAS, NIM, NILAI 1, NILAI 2, NILAI 3″<<endl;
cout<<“JIKA KELAS = 1, MAKA JIKA NILAI 1,NILAI 2,NILAI 3 LEBIH DARI 75 MAKA STATUSNYA LULUS”<<endl;
cout<<“JIKA KELAS = 2/3, MAKA JIKA NILAI RATA – RATANYA LEBIH DARI 70 MAKA STATUSNYA LULUS”<<endl;
cout<<“NILAI RATA-RATA = (NILAI 1+NILAI 2+ NILAI 3)/3″<<endl;
bintang();
}

void bintang()
{
cout<<“**********************************************************************”<<endl;
}
void cetak(char nama[20],int kelas,char nim[20],float N1,float N2,float N3,char status[20])
{
cout<<”                   HASIL PROGRAM  “<<endl;
bintang();
cout<<“NAMA    = “<<nama<<endl;
cout<<“KELAS   = “<<kelas<<endl;
cout<<“NIM     = “<<nim<<endl;
cout<<“NILAI 1 = “<<N1<<endl;
cout<<“NILAI 2 = “<<N2<<endl;
cout<<“NILAI 3 = “<<N3<<endl;
cout<<“STATUS  = “<<status<<endl;
bintang();

}

void masukkan (float*N1,float*N2,float*N3)
{
cout<<“MASUKKAN 3 BUAH NILAI “<<endl;
cout<<“NILAI 1 = “;
cin>>*N1;
cout<<“NILAI 2 = “;
cin>>*N2;
cout<<“NILAI 3 = “;
cin>>*N3;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: