Array Dimensi Satu (Nilai Ujian Mahasiswa) |
/*filename = Array Berdimensi Satu */
/*Oleh : fk_seven */
/*Date : 13 September 2011 */
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdio.h>
main()
{
//Deklarasi Variabel dan Konstanta
int i,n;
char nama[5][20];
float nilai1[5];
float nilai2[5];
float hasil[5];
//Input
cout<<"Data yang akan diinput : ";cin>>n;
cout<<endl<<endl;
for(i=0;i<n;i++)
{
cout<<"Data Ke - "<<i+1<<endl;
cout<<"Nama Siswa : "; gets(nama[i]);
cout<<"Nilai MidTest : "; cin>>nilai1[i];
cout<<"Nilai Akhir : "; cin>>nilai2[i];
hasil[i] = (nilai1[i] * 0.4) + (nilai2[i] * 0.6);
cout<<endl;
}
//Output
cout<<"-------------------------------------------------------"<<endl;
cout<<"No Nama Siswa Nilai Nilai Hasil "<<endl;
cout<<" MidTest Akhir Ujian "<<endl;
cout<<"-------------------------------------------------------"<<endl;
for(i=0;i<n;i++)
{
cout<<setiosflags(ios::left)<<setw(4)<<i+1;
cout<<setiosflags(ios::left)<<setw(20)<<nama[i];
cout<<setprecision(2)<<" "<<nilai1[i];
cout<<setprecision(2)<<" "<<nilai2[i];
cout<<setprecision(2)<<" "<<hasil[i]<<endl;
}
cout<<"-------------------------------------------------------"<<endl;
getch();
}
0 komentar:
Posting Komentar