[Source Code Pemrograman C++] : Menghitung Nilai Akhir Mahasiswa Dengan Menggunakan Structure Dan Function
Tampilan Masukan:
Tampilan Keluaran:
Source Code: (copy below or download here)
#include <iostream.h>#include <conio.h>
#include <iomanip.h>
#include <stdio.h>
struct nilai
{
char nama [20], grade;
int uts, uas;
float akhir;
}nilai [10];
bintang()
{
cout<<"\t***********************************************"<<endl;
}
garis()
{
cout<<"\t------------------------------------------------"<<endl;
}
float hasil (int uts1, int uas1)
{
return (uts1 * 0.4 + uas1 * 0.6);
}
char grade1 (float nil)
{
if (nil >= 80)
return 'A';
else if (nil >= 70)
return 'B';
else if (nil >= 56)
return 'C';
else if (nil >= 47)
return 'D';
else
return 'E';
}
main()
{
int i, n;
bintang();
cout<<"\t\tMENGHITUNG NILAI AKHIR MAHASISWA"<<endl;
bintang();
cout<<"\n\tMasukkan Jumlah Data Yang Akan Diinput : "; cin>>n;
for (i = 1; i <= n; i++)
{
cout<<"\n\tData ke - " <<i<<endl;
cout<<"\t-----------"<<endl;
cout<<"\t\tNama Mahasiswa : "; cin>>nilai[i].nama;
cout<<"\t\tNilai UTS : "; cin>>nilai[i].uts;
cout<<"\t\tNilai UAS : "; cin>>nilai[i].uas;
nilai[i].akhir = hasil (nilai[i].uas, nilai[i].uts);
nilai[i].grade = grade1 (nilai[i].akhir);
}
clrscr();
garis();
cout<<"\t\tDaftar Nilai Mata Kuliah C++"<<endl;
garis();
cout<<endl;
garis();
cout<<"\t| No. | Nama | Nilai | Nilai | Grade |"<<endl;
cout<<"\t| | Mahasiswa | UTS | UAS | Akhir | |"<<endl;
garis();
for (i = 1; i <= n; i++)
{
cout<<setw(4)<<"\t| "<<i;
cout<<setw(4)<<" | "<<nilai[i].nama;
cout<<setw(7)<<" | "<<nilai[i].uts;
cout<<setw(4)<<" | "<<nilai[i].uas;
cout<<setw(5)<<" | "<<nilai[i].akhir;
cout<<setw(4)<<" | "<<nilai[i].grade<<" |"<<endl;
}
garis();
cout<<"\tJumlah Mahasiswa : "<<n<<" orang"<<endl;
garis();
getch();
}
terimakasih banyak, sangat bermanfaat
ReplyDelete