- Menggunakan bahasa pemograman C
- Menggunakan Struct
- Menggunakan subroutines
/*Buatlah program yang menampilkan laporan angka matakuliah Computer Programming II .
Tampilkan di text file, laporan angka yang terdiri atas nim,nama, persentase nilai quiz, persentase nilai test,
persentase lab exercise, persentase nilai final, persentase nilai project . Nilai akhir dan grade (A,A-,etc).
Mintalah user untuk input nilai quiz, test, final, lab, dan project. Nilai quiz, test, dan lab dilakukan lebih dari 1 kali.
Nilai akhir diperoleh dari : 10% quiz + 20% lab + 20% test + 20% final + 30% project.
Tampilkan pula di text file histogram yang menyatakan frekuensi kemunculan setiap nilai akhir mahasiswa.*/
#include <stdio.h>
#include <conio.h>
#include <string.h>
//Deklarasi Struct
typedef struct
{
int nim;
char nama [32];
float nilai_akhir;
}data;
typedef struct
{
float kuis;
float lab;
float tes;
float final;
float project;
}nilai;
//Deklarasi Variabel
nilai nsiswa [100];
data dsiswa [ 100];
float jlh_siswa,jlh_kuis,jlh_lab,jlh_tes;
float nkuis,nlab,ntes,nfinal,nproject;
float total_kuis,total_lab,total_tes,rata_kuis,rata_lab,rata_tes;
int i,j;
//function Input Batas
void input_batas ()
{
printf ("Input Jumlah Siswa = ");
scanf ("%f",&jlh_siswa);
printf ("Input Jumlah Kuis = ");
scanf ("%f",&jlh_kuis);
printf ("Input Jumlah Lab Exercise = ");
scanf ("%f",&jlh_lab);
printf ("Input Jumlah Test = ");
scanf ("%f",&jlh_tes);
printf("\n");
}
//function Input Nilai
void input_nilai ()
{
for (i=0;i<jlh_siswa;i++)
{
total_kuis=0;
total_lab=0;
total_tes=0;
printf ("Siswa ke %d\n",i+1);
printf ("Masukkan NIM Siswa = ");
scanf ("%d",&dsiswa[i].nim);
printf ("Masukkan Nama Siswa = ");
fflush(stdin);
gets (dsiswa[i].nama);
for (j=0;j<jlh_kuis;j++)
{
printf ("Masukkan Nilai Kuis ke %d = ", j+1);
scanf ("%f",&nkuis);
total_kuis=total_kuis+nkuis;
}
for (j=0;j<jlh_lab;j++)
{
printf ("Masukkan Nilai Lab Exercise ke %d = ", j+1);
scanf ("%f",&nlab);
total_lab=total_lab+nlab;
}
for (j=0;j<jlh_tes;j++)
{
printf ("Masukkan Nilai Tes ke %d = ",j+1);
scanf ("%f",&ntes);
total_tes=total_tes+ntes;
}
printf ("Masukkan Nilai Project = ");
scanf ("%f",& nproject);
printf ("Masukkan Nilai Final = ");
scanf ("%f",&nfinal);
rata_kuis=total_kuis/jlh_kuis;
rata_lab=total_lab/jlh_lab;
rata_tes=total_tes/jlh_tes;
nsiswa[i].kuis=0.1*rata_kuis;
nsiswa[i].lab=0.2*rata_lab;
nsiswa[i].tes=0.2*rata_tes;
nsiswa[i].final=0.2*nfinal;
nsiswa[i].project=0.3*nproject;
printf("\n");
}
}
//function Cetak di Command Prompt
void cetak_layar ()
{
printf("Data Nilai Mahasiswa Mata Kuliah Computer Programming 2\n");
printf("\n===========================================================");
printf("\n| NIM | Nama | Kuis | Lab | Tes | Final | Project |");
printf("\n===========================================================");
for (i=0;i<jlh_siswa;i++)
{
printf ("\n|%8d|%-10s|%6.2f|%5.2f|%6.2f|%7.2f|%9.2f|",dsiswa[i].nim,dsiswa[i].nama,nsiswa[i].kuis,nsiswa[i].lab,nsiswa[i].tes,nsiswa[i].final,nsiswa[i].project);
}
printf("\n===========================================================");
printf("\n\n");
printf("***********************************************************");
printf("\n\n");
printf("\n===========================================");
printf("\n| NIM | Nama | Nilai Akhir | Grade |");
printf("\n===========================================");
for (i=0;i<jlh_siswa;i++)
{
fflush (stdin);
dsiswa[i].nilai_akhir=nsiswa[i].kuis+nsiswa[i].lab+nsiswa[i].tes+nsiswa[i].project+nsiswa[i].final;
if(dsiswa[i].nilai_akhir>=91 && dsiswa[i].nilai_akhir<=100)
{
printf("\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"A");
}
if(dsiswa[i].nilai_akhir>=85 && dsiswa[i].nilai_akhir<91)
{
printf("\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"A-");
}
if(dsiswa[i].nilai_akhir>=82 && dsiswa[i].nilai_akhir<85)
{
printf("\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"B+");
}
else if(dsiswa[i].nilai_akhir>=78 && dsiswa[i].nilai_akhir<82)
{
printf("\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"B");
}
if(dsiswa[i].nilai_akhir>=75 && dsiswa[i].nilai_akhir<78)
{
printf("\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"B-");
}
if(dsiswa[i].nilai_akhir>=70 && dsiswa[i].nilai_akhir<75)
{
printf("\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"C+");
}
if(dsiswa[i].nilai_akhir>=67&& dsiswa[i].nilai_akhir<70)
{
printf("\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"C");
}
if(dsiswa[i].nilai_akhir>=60 && dsiswa[i].nilai_akhir<67)
{
printf("\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"C-");
}
if(dsiswa[i].nilai_akhir>=40 && dsiswa[i].nilai_akhir<60)
{
printf("\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"D");
}
if(dsiswa[i].nilai_akhir>=0 && dsiswa[i].nilai_akhir<40)
{
printf("\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"F");
}
}
printf("\n===========================================");
printf("\n\n\n\n");
//histogram
float max=0;
for(i=0;i<jlh_siswa;i++)
{
if(dsiswa[i].nilai_akhir>max)
{
max=dsiswa[i].nilai_akhir;
}
}
float min=max;
for(i=0;i<jlh_siswa;i++)
{
if(dsiswa[i].nilai_akhir<min)
{
min=dsiswa[i].nilai_akhir;
}
}
int f;
f=max-min+1;
int freq[f];
int index;
for(i=0;i<f;i++)
{
freq[i]=0;
}
for(i=0;i<jlh_siswa;i++)
{
index=(dsiswa[i].nilai_akhir-min);
freq[index]++;
}
//Cetak Histogram
printf("Histogram\n");
for(i=0;i<f;i++)
{
if(freq[i]!=0)
{
printf("%5.2f|",i+min);
for(j=0;j<freq[i];j++)
{
printf("*");
}
printf("\n");
}
}
}
//Function Cetak di Text File
void cetak_text ()
{
FILE *fptampilkan;
fptampilkan=fopen("laporan.txt","wt");
fprintf(fptampilkan,"Data Nilai Mahasiswa Mata Kuliah Computer Programming 2\n");
fprintf(fptampilkan,"\n===========================================================");
fprintf(fptampilkan,"\n| NIM | Nama | Kuis | Lab | Tes | Final | Project |");
fprintf(fptampilkan,"\n===========================================================");
for (i=0;i<jlh_siswa;i++)
{
fprintf (fptampilkan,"\n|%8d|%-10s|%6.2f|%5.2f|%6.2f|%7.2f|%9.2f|",dsiswa[i].nim,dsiswa[i].nama,nsiswa[i].kuis,nsiswa[i].lab,nsiswa[i].tes,nsiswa[i].final,nsiswa[i].project);
}
fprintf (fptampilkan,"\n===========================================================");
fprintf (fptampilkan,"\n\n");
fprintf (fptampilkan,"\n\n");
fprintf (fptampilkan,"\n===========================================");
fprintf (fptampilkan,"\n| NIM | Nama | Nilai Akhir | Grade |");
fprintf (fptampilkan,"\n===========================================");
for (i=0;i<jlh_siswa;i++)
{
fflush (stdin);
dsiswa[i].nilai_akhir=nsiswa[i].kuis+nsiswa[i].lab+nsiswa[i].tes+nsiswa[i].project+nsiswa[i].final;
if(dsiswa[i].nilai_akhir>=91 && dsiswa[i].nilai_akhir<=100)
{
fprintf (fptampilkan,"\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"A");
}
if(dsiswa[i].nilai_akhir>=85 && dsiswa[i].nilai_akhir<91)
{
fprintf (fptampilkan,"\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"A-");
}
if(dsiswa[i].nilai_akhir>=82 && dsiswa[i].nilai_akhir<85)
{
fprintf (fptampilkan,"\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"B+");
}
else if(dsiswa[i].nilai_akhir>=78 && dsiswa[i].nilai_akhir<82)
{
fprintf (fptampilkan,"\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"B");
}
if(dsiswa[i].nilai_akhir>=75 && dsiswa[i].nilai_akhir<78)
{
fprintf (fptampilkan,"\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"B-");
}
if(dsiswa[i].nilai_akhir>=70 && dsiswa[i].nilai_akhir<75)
{
fprintf (fptampilkan,"\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"C+");
}
if(dsiswa[i].nilai_akhir>=67&& dsiswa[i].nilai_akhir<70)
{
fprintf (fptampilkan,"\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"C");
}
if(dsiswa[i].nilai_akhir>=60 && dsiswa[i].nilai_akhir<67)
{
fprintf (fptampilkan,"\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"C-");
}
if(dsiswa[i].nilai_akhir>=40 && dsiswa[i].nilai_akhir<60)
{
fprintf (fptampilkan,"\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"D");
}
if(dsiswa[i].nilai_akhir>=0 && dsiswa[i].nilai_akhir<40)
{
fprintf (fptampilkan,"\n|%8d|%-10s|%13.2f|%-7s|",dsiswa[i].nim,dsiswa[i].nama,dsiswa[i].nilai_akhir,"F");
}
}
fprintf (fptampilkan,"\n===========================================");
fprintf (fptampilkan,"\n\n\n\n");
float max=0;
for(i=0;i<jlh_siswa;i++)
{
if(dsiswa[i].nilai_akhir>max)
{
max=dsiswa[i].nilai_akhir;
}
}
float min=max;
for(i=0;i<jlh_siswa;i++)
{
if(dsiswa[i].nilai_akhir<min)
{
min=dsiswa[i].nilai_akhir;
}
}
int f;
f=max-min+1;
int freq[f];
int index;
for(i=0;i<f;i++)
{
freq[i]=0;
}
for(i=0;i<jlh_siswa;i++)
{
index=(dsiswa[i].nilai_akhir-min);
freq[index]++;
}
fprintf (fptampilkan,"Histogram\n");
for(i=0;i<f;i++)
{
if(freq[i]!=0)
{
fprintf (fptampilkan,"%5.2f|",i+min);
for(j=0;j<freq[i];j++)
{
fprintf (fptampilkan,"*");
}
fprintf (fptampilkan,"\n");
}
}
}
//main function
int main ()
{
input_batas ();
input_nilai ();
for (i=0;i<jlh_siswa;i++)
{
dsiswa[i].nilai_akhir=nsiswa[i].kuis+nsiswa[i].lab+nsiswa[i].tes+nsiswa[i].project+nsiswa[i].final;
}
cetak_layar ();
cetak_text ();
getche ();
return 0;
}