langsung saja
#include <conio.h>
#include <iostream.h>
#include <stdio.h> //Agar Bisa Memasukkan Nama tidak hanya dengan huruf
#include <iomanip.h> //Untuk Memanggil Fungsi Setw
main ()
{
char nama[10][30],ulangi; //Array Identik dengan penggunaan
int i,b ; //"[i]" contoh : mid[i]
float mid[10],uas[10],akhir[10] ;
do
{
clrscr();
cout<<"\n===================================================================";
cout<<"\n PROGRAM PENGINPUTAN NILAI MAHASISWA ";
cout<<"\n===================================================================";
cout<<"\nMasukkan Banyak Data Yang Ingin Di Input =";
cin>>b;
for (i=1;i<=b;i++){
cout<<"\nData ke "<<i;
cout<<"\nMasukkan Nama Mahasiswa=";
gets(nama[i]);
cout<<"\nMasukkan Nilai MID =";
cin>>mid[i];
cout<<"\nMasukkan Nilai UAS =";
cin>>uas[i];
akhir[i] = (mid[i]*0.5)+(uas[i]*0.5); //Nilai Akhir = 50% Nilai Uas+50% Nilai MID
}
cout<<"\n===================================================================";
cout<<"\n No. Nama N.MID N.UAS N.Akhir ";
cout<<"\n==================================================================="<<endl;
for ( i=1;i<=b;i++){
cout<<"\n "<<setiosflags(ios::left)<<setw(4)<<i; //Penggunaan setw(4)
cout<<" "<<setiosflags(ios::left)<<setw(30)<<nama[i];//arti 4 adalah
cout<<setprecision(2)<<" "<<mid[i]; //Batas maksimal karakter
cout<<setprecision(2)<<" "<<uas[i];
cout<<setprecision(2)<<" "<<akhir[i];
}
cout<<"\n===================================================================";
cout<<"\nMasih Adakah Proses Lain [Y/N] =";
cin>>ulangi ;
cout<<"\n===================================================================";
}
while (ulangi=='Y');
cout<<"\nTerima Kasih";
getche();
}
Keluaran nya akan seperti gambar diatas.
Semoga ilmu kali ini bermanfaat , terima kasih.
0 Response to "Program Sederhana C++ Dengan Array dan Fungsi Setw (Tabel)"
Posting Komentar