Program Penghitung nilai menggunakan Array berdimensi satu
PROGRAM
Penghitung nilai
# include <iostream.h>
# include <stdio.h>
# include <iomanip.h>
char lagi;
main ()
{
do {
int i,n, j,k,temp;
char nama[100] [20];
char namanew [100] [20];
int ujian [5];
int tugas [5];
int aktif [5];
int akhir [5];
int awal [5];
int ujiannew [5];
int tugasnew [5];
int aktifnew [5];
clrscr();
cout<<"Masukan jumlah siswa : ";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<"Data ke - "<<i<<endl;
cout<<"Nama Siswa : ";gets (nama [i]);
l1:cout<<"Masukkan nilai Aktif : "; cin>>aktif [i];
if ((aktif[i] >100)&&(aktif[i] <0))
{
cout<<"Maaf!!! nilai dalam Skala 0-100 \n";
cout<<"silahkan ulangi lagi \n";
goto l1;
}
l2:cout<<"Masukkan nilai Tugas : ";cin>>tugas [i];
if ((tugas[i] >100)&&(tugas[i] <0))
{
cout<<"Maaf!!! nilai dalam Skala 0-100 \n";
cout<<"silahkan ulangi lagi \n";
goto l2;
}
l3:cout<<"Masukkan nilai Ujian : ";cin>>ujian [i];
if ((ujian[i] >100)&&(ujian[i] <0))
{
cout<<"Maaf!!! nilai dalam Skala 0-100 \n";
cout<<"silahkan ulangi lagi \n";
goto l3;
}
akhir [i] = (aktif [i] * 0.20) + (tugas [i] * 0.30) + (ujian [i] * 0.50);
cout<<endl;
}
cout<<"==========================================================================="<<endl;
cout<<" DAFTAR NILAI AKHIR MAHASISWA D3 Elektro FT UM "<<endl;
cout<<"==========================================================================="<<endl;
cout<<"---------------------------------------------------------------------------"<<endl;
cout<<"No. Nama Siswa Nilai Nilai Nilai Nilai"<<endl;
cout<<" Aktif Tugas Ujian Akhir"<<endl;
cout<<"---------------------------------------------------------------------------"<<endl;
for (j=1;j<=n;j++)
{
awal[j]=akhir[j];
}
for (j=1;j<=n;j++)
{
for (k=1;k<=j;k++)
{
if (akhir[j]>akhir[k])
{
temp=akhir[j];
akhir[j]=akhir[k];
akhir[k]=temp;
}
}
}
for (j=1;j<=n;j++)
{
for (k=1;k<=n;k++)
{
if (awal[j]==akhir[k])
{
aktifnew[k]=aktif[j];
tugasnew[k]=tugas[j];
ujiannew[k]=ujian[j];
strcpy(namanew[k],nama[j]);
}
}
}
for (i=1;i<=n;i++)
{
cout<<setiosflags(ios::left)<<setw(6)<<i;
cout<<setiosflags(ios::left)<<setw(20)<<namanew [i];
cout<<setprecision(2)<<" "<<aktifnew[i];
cout<<setprecision(2)<<" "<<tugasnew[i];
cout<<setprecision(2)<<" "<<ujiannew[i];
cout<<setprecision(2)<<" "<<akhir[i]<<endl;
}
cout<<"---------------------------------------------------------------------------";
cout<<endl;
cout<<"Ulang Kembali (Y/T)?\a "; //pilihan perulangan
cin>>lagi;
}
while ((lagi=='Y')||(lagi=='y'));
}
Gambar tampilan :
Komentar
Posting Komentar