Sabtu, 16 Oktober 2010

Contoh Program C++

#include <iostream.h>
#include <conio.h>
int n,b,c,d,jnh,x,jnt,nh,jt,mid,final;
float na,nt,NA,totalna,totalnt,totalmid,totalfinal;
float ratana,ratant,ratamid,ratafinal;
char nama[30], nim[16];
void main()
{
 int max=0; int min=100;
 cout<<"Berapa data yang akan diinput : ";cin>>n;
 clrscr();
 int a=1;
 while (a<=n)

 {
  cout<<"Data ke "<<a<<endl;
  cout<<"Masukkan Nama Anda    : ";cin>>nama;
  cout<<"Masukkan Nim Anda     : ";cin>>nim;
  cout<<"Masukkan nilai kehadiran "<<endl;
  cout<<"(1=hadir & 0=tdk hadir)"<<endl;
  b =1; jnh =0;
  do
  {
    cout<<"Kehadiran ke "<<b<<" : ";cin>>nh;
    jnh = jnh + nh;
    b++;
  }
  while (b <= 15);
  if (nh = 1)
    na = (jnh * 100)/15;
  cout<<"Masukkan nilai tugas"<<endl;
  c = 1; jnt = 0;
  do
  {
    cout<<"Tugas ke "<<c<<" : ";cin>>jt;
    jnt = jnt + jt;
    c++;
  }
  while (c <=5);
  nt = jnt / 5;
  clrscr();
  cout<<"Nilai kehadiran         : "<<na<<endl;
  cout<<"Nilai tugas             : "<<nt<<endl;
  cout<<"Masukkan nilai MID      : ";cin>>mid;
  cout<<"Masukkan nilai Final    : ";cin>>final;
  NA = 0.1 * na + 0.2 * nt + 0.3 * mid + 0.4 * final;
  cout<<"NIlai akhir anda adalah "<<NA<<endl;
  a++;
 }
 clrscr();
 totalna +=na;
 totalnt += nt;
 totalmid += mid;
 totalfinal += final;
 ratana = totalna / n;
 ratant = totalnt / n;
 ratamid = totalmid / n;
 ratafinal = totalfinal / n;
 if (NA > max)
  {
    max = NA;
  }
 if (NA < min)
  {
    min = NA;
  }
 cout<<"nilai maximal yaitu         : "<<max<<endl;
 cout<<"nilai minimum yaitu         : "<<min<<endl;
 cout<<"Rata - rata nilai kehadiran : "<<ratana<<endl;
 cout<<"Rata - rata nilai tugas     : "<<ratant<<endl;
 cout<<"Rata - rata nilai mid       : "<<ratamid<<endl;
 cout<<"Rata - rata nilai final     : "<<ratafinal<<endl;
}

0 komentar:

Posting Komentar

 
Design by Akhmad Maknur | Bloggerized by Kajang Kab. Bulukumba