Senin, 27 Agustus 2012

MENGHITUNG IPK (indek prestasi kumulatif)


#include<stdio.h>

int i=1,p;
int sks1=0;
int total1=0;
float ipk;
char nama[30];
char nim[15];
char input;

struct simpul
{

char kode_mk[8];
char nama_mk[30];
int nilai;
int sks;
int bobot;
int total;

   struct simpul *kiri,*kanan;
} *baru,*awal=NULL,*bantu,*bantu1;


void buat_baru()
{
   baru=(struct simpul*) malloc(sizeof(struct simpul));

baru->kiri=NULL;
baru->kanan=NULL;

gotoxy (1,7+i);scanf ("%s",& baru->kode_mk);
gotoxy (16,7+i);scanf("%s",& baru->nama_mk);
gotoxy (33,7+i);scanf("%d",& baru->sks);
gotoxy (40,7+i);scanf("%d",& baru->nilai);

if((baru->nilai<=100)&&(baru->nilai>=85))
{
baru->bobot=4;
gotoxy (50,7+i);printf ("A");
}
else
if((baru->nilai<=84)&&(baru->nilai>=70))
{
baru->bobot=3;
gotoxy (50,7+i);printf ("B");
}
else
if((baru->nilai<=69)&&(baru->nilai>=60))
{
baru->bobot=2;
gotoxy (50,7+i);printf ("C");
}
else
if((baru->nilai<=59)&&(baru->nilai>=50))
{
baru->bobot=1;
gotoxy (50,7+i);printf ("D");
}
else
if((baru->nilai<=49)&&(baru->nilai>=0))
{
baru->bobot=0;
gotoxy (50,7+i);printf ("E");
}
else
{ }


baru->total=baru->sks * baru->bobot;
gotoxy (61,7+i);printf("%d",baru->total);


i++;


}

void tampil()
{
total1=0;
sks1=0;
bantu=awal;
clrscr();
printf("Nama   : %s ",nama);
printf("\nNim : %s",nim);

printf("\n--------------------DAFTAR NILAI MAHASISWA-------------------------------------");
printf("\n===============================================================================");
printf("\nKODE MK          MATAKULIAH          SKS        NILAI       BOBOT      TOTAL   ");
printf("\n===============================================================================");
printf("\n");
i=1;
while(bantu!=NULL)
{
gotoxy (1,7+i);printf("%s",bantu->kode_mk);
gotoxy (16,7+i);printf("%s",bantu->nama_mk);
gotoxy (33,7+i);printf("%d",bantu->sks);
gotoxy (40,7+i);printf("%d",bantu->nilai);

if(bantu->bobot==4)
{
gotoxy (50,7+i);printf("A");
}else
if(bantu->bobot==3)
{
gotoxy (50,7+i);printf("B");
}else
if(bantu->bobot==2)
{
gotoxy (50,7+i);printf("C");
}else
if(bantu->bobot==1)
{
gotoxy (50,7+i);printf("D");
}else
if(bantu->bobot==0)
{
gotoxy (50,7+i);printf("E");
}
gotoxy (60,7+i);printf("%d",bantu->total);

i++;
bantu=bantu->kanan;
total1=total1+bantu->total;
sks1=sks1+bantu->sks;

}

ipk=total1 / sks1;
gotoxy(10,20);printf("ipk=%0.2f",ipk);
   getch();
}

void tambah()
{
   bantu=awal;
   if(awal==NULL)
   {
 awal=baru;
   }
else if(strcmp(baru->kode_mk,awal->kode_mk)<0)
   {
  baru->kanan=awal;
  bantu->kiri=baru;
  awal=baru;
   }
   else
   {

 while(bantu->kanan!=NULL && strcmp(baru->kode_mk,bantu->kanan->kode_mk)>0)
  bantu=bantu->kanan;
 baru->kanan=bantu->kanan;
 baru->kanan->kiri=baru;
 bantu->kanan=baru;
 baru->kiri=bantu;
   }

}




int main()
{
clrscr();
printf("Nama   : ");fflush(stdin);gets(nama);
printf("nim :");scanf("%s",&nim);

printf("\n--------------------DAFTAR NILAI MAHASISWA-------------------------------------");
printf("\n===============================================================================");
printf("\nKODE MK          MATAKULIAH          SKS        NILAI       BOBOT      TOTAL   ");
printf("\n===============================================================================");
printf("\n");
do
{
p=1;
buat_baru();
sks1=sks1 + baru->sks;

if(sks1>24)
{
sks1=sks1 - baru->sks;
gotoxy(1,6+i);printf("                                                                              ");
i--;
free(baru);
p=0;

}
if(p==1)
{
tambah();
}
gotoxy(10,20);printf("Input Lagi: ");scanf("%s",&input);
gotoxy(10,20);printf("             ");

}
while((input=='Y')||(input=='y'));


tampil();


}



Tidak ada komentar:

Poskan Komentar