Pages

Kamis, 13 Desember 2012

listing latihan array fungsi pada C++


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
float rata(float na, float nt, float nut, float nas)
{
return(0.1* na+0.2* nt+0.3* nut+0.4* nas); }
judul()
{
cout<<"\t\t==========================="<<endl;
cout<<"\t\tPROGRAM NILAI MAHASISWA "<<endl;
cout<<"\t\t==========================="<<endl;
}
main()
{
int i,n;
char nama[5][30];
float nabsen[5],ntugas[5],nuts[5],nuas[5],nrata[5];
clrscr();
judul();
cout<<"Masukkan Banyaknya Data : ";cin>>n;
for (i=1; i<=n; i++)
{


cout <<"data ke- "<<i<<endl;
cout <<"Input Nama Mahasiswa\t\t : ";gets(nama[i]);
cout <<"Input Nilai Absen\t\t : ";cin>>nabsen[i];
cout <<"Input Nilai Tugas\t\t : ";cin>>ntugas[i];
cout <<"Input Nilai UTS\t\t : ";cin>>nuts[i];
cout <<"Input Nilai UAS\t\t : ";cin>>nuas[i];
}
clrscr();
judul();
cout <<"\n**********************************************************";
cout <<"\nNo. Nama Mahasiswa N.Absen N.Tugas N.UTS N.UAS N.Rata";
cout <<"\n**********************************************************";
cout<<endl;
for (i = 1; i<=n;i++)
{
cout <<setiosflags(ios::left)<<setw(4)<<i;
cout <<setiosflags(ios::left)<<setw(15)<<nama[i];
cout <<setiosflags(ios::left)<<setw(10)<<nabsen[i];
cout <<setiosflags(ios::left)<<setw(10)<<ntugas[i];
cout <<setiosflags(ios::left)<<setw(10)<<nuts[i];
cout <<setiosflags(ios::left)<<setw(10)<<nuas[i];
cout <<setiosflags(ios::left)<<setw(10)<<rata(nabsen[i],ntugas[i],nuts[i],nuas[i]);
cout<<endl;
}
cout <<"\n************************************************";
getch();
}

0 komentar:

Poskan Komentar