Aplikasi Pengolah KHS C++

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <fstream.h>
#include <iostream.h>
#include <windows.h>
#define x 100

using namespace std;

typedef struct data{
  int jum,sks[x],nilai[x][x];
  char nama[x][x],dosen[x][x],nim[x][x];    
};
data mhs,mk;

int i,j,sksn;
char huruf;
float bobot[x][x],ip;

void input();
void daftarmatkul();
void daftarnama();
void daftarnilai();
void khsmhs();
void perhitungan();
void simpan();
void baca();
void tentang();
void garis(int L,int K,int KL,char *T,int KR,int R);
void gotoxy(int H,int V);
void start();

int main(){
  int pilih;
  system("COLOR 0C");
  start();
  system("CLS");
  goto buka;
  menu:
  printf("\nTekan ENTER untuk kembali ke Menu Utama");
  getch();
  system("CLS");
  buka:
  garis(201,205,0,"",28,187);printf("\n");
  garis(186,0,9,"MENU UTAMA",9,186);printf("\n");
  garis(204,205,0,"",28,185);printf("\n");
  garis(186,0,1,"1. Input Data Akademik",5,186);printf("\n");
  garis(186,0,1,"2. Daftar Mata Kuliah",6,186);printf("\n");
  garis(186,0,1,"3. Daftar Nama Mahasiswa",3,186);printf("\n");
  garis(186,0,1,"4. Daftar Nilai Mahasiswa",2,186);printf("\n");
  garis(186,0,1,"5. Kartu Hasil Studi",7,186);printf("\n");
  garis(186,0,1,"6. Simpan Ke Database",6,186);printf("\n");
  garis(186,0,1,"7. Baca Dari Database",6,186);printf("\n");
  garis(186,0,1,"8. Tentang Program",9,186);printf("\n");
  garis(186,0,1,"9. Keluar",18,186);printf("\n");
  garis(204,205,0,"",28,185);printf("\n");
  garis(186,0,1,"Masukkan Pilihan : ",8,186);printf("\n");
  garis(200,205,0,"",28,188);printf("\n");
  gotoxy(21,13);
  scanf("%d",&pilih);
  switch(pilih){
    case 1:
      input(); goto menu;  break;
    case 2:
      daftarmatkul(); goto menu; break;
    case 3:
      daftarnama(); goto menu; break;
    case 4:
      daftarnilai(); goto menu; break;
    case 5:
      khsmhs(); goto menu; break;
    case 6:
      simpan(); goto menu; break;
    case 7:
      baca(); goto menu; break; 
    case 8:
      tentang(); goto menu; break;
    case 9:
      break;
    default:
      gotoxy(0,12); garis(204,205,0,"",28,185);printf("\n");
      garis(186,0,3,"Pilihan tidak tersedia",3,186);printf("\n");
      garis(200,205,0,"",28,188);printf("\n"); goto menu;           
  }
  return 0; 
}

void input(){
  system("CLS");
  garis(205,205,30,"",30,205);printf("\n");
  garis(0,0,20,"INPUT DATA AKADEMIK",20,0);printf("\n");
  garis(205,205,30,"",30,205);printf("\n");
  printf("Jumlah Mata Kuliah  : ");
  scanf("%d",&mk.jum);
  printf("Jumlah Mahasiswa    : ");
  scanf("%d",&mhs.jum);
  garis(205,205,30,"",30,205);printf("\n");
  for(i=0;i<mk.jum;i++){
    fflush(stdin);
    printf("%d. Nama Mata Kuliah : ",i+1);
    gets(mk.nama[i]);
    printf("   Nama Dosen       : ");
    gets(mk.dosen[i]);
    printf("   SKS              : ");
    scanf("%d",&mk.sks[i]);                  
  }
  garis(205,205,30,"",30,205);printf("\n");
  for(i=0;i<mhs.jum;i++){
    fflush(stdin);
    printf("%d. Nama Mahasiswa   : ",i+1);
    gets(mhs.nama[i]);
    printf("   NIM Mahasiswa    : ");
    gets(mhs.nim[i]);
    for(j=0;j<mk.jum;j++){
      printf("   %d. Mata Kuliah %s\n",j+1,mk.nama[j]);
      ulang:
      printf("      Nilai         : ");
      scanf("%d",&mhs.nilai[i][j]);
      if(mhs.nilai[i][j]>100){
        printf("ERROR : Di atas nilai maksimum\n");
        goto ulang;
      }
      else if(mhs.nilai[i][j]<0){
        printf("ERROR : Di bawah nilai minimum\n");
        goto ulang; 
      }                  
    }                     
  }
  garis(205,205,30,"",30,205);printf("\n"); 
}

void daftarmatkul(){
  system("CLS");
  int jum_sks = 0;
  garis(201,205,0,"",68,187);printf("\n");
  garis(186,0,22,"DAFTAR NAMA MATA KULIAH",23,186);printf("\n");
  garis(204,205,0,"",4,203);garis(205,205,0,"",26,203);garis(205,205,0,"",26,203);garis(205,205,0,"",6,185);printf("\n");
  printf("%c %-2s %c %-25s %c %-25s %c %-5s %c\n",char(186),"No",char(186),"Nama Mata Kuliah",char(186),"Nama Dosen",char(186),"SKS",char(186));
  garis(204,205,0,"",4,206);garis(205,205,0,"",26,206);garis(205,205,0,"",26,206);garis(205,205,0,"",6,185);printf("\n");
  for(i=0;i<mk.jum;i++){
    printf("%c %-2d %c %-25s %c %-25s %c %-5d %c\n",char(186),i+1,char(186),mk.nama[i],char(186),mk.dosen[i],char(186),mk.sks[i],char(186));
    jum_sks += mk.sks[i];                    
  }   
garis(204,205,0,"",4,202);garis(205,205,0,"",26,202);garis(205,205,0,"",26,202);garis(205,205,0,"",6,185);printf("\n");
  printf("%c Jumlah SKS : %-53d %c\n",char(186),jum_sks,char(186));   
  garis(200,205,0,"",68,188);printf("\n");   
}

void daftarnama(){
  system("CLS");
  garis(201,205,0,"",45,187);printf("\n");
  garis(186,0,12,"DAFTAR NAMA MAHASISWA",12,186);printf("\n");
  garis(204,205,0,"",4,203);garis(205,205,0,"",26,203);garis(205,205,0,"",11,185);printf("\n");
  printf("%c %-2s %c %-25s %c %-10s %c\n",char(186),"No",char(186),"Nama Mahasiswa",char(186),"NIM",char(186));
  garis(204,205,0,"",4,206);garis(205,205,0,"",26,206);garis(205,205,0,"",11,185);printf("\n");
  for(i=0;i<mhs.jum;i++){
    printf("%c %-2d %c %-25s %c %-10s %c\n",char(186),i+1,char(186),mhs.nama[i],char(186),mhs.nim[i],char(186));                   
  }
  garis(200,205,0,"",4,202);garis(205,205,0,"",26,202);garis(205,205,0,"",11,188);printf("\n"); 
}

void daftarnilai(){
  char cari[x];
  int ketemu = 0,k,jum_nilai = 0;
  float rata,jum; fflush(stdin); system("CLS");
  garis(201,205,0,"",50,187);printf("\n");
  garis(186,0,13,"MENCARI DATA MATA KULIAH",13,186);printf("\n");
  garis(204,205,0,"",50,185);printf("\n");
  garis(186,0,1,"Nama Mata Kuliah : ",30,186);printf("\n");
  garis(200,205,0,"",50,188);printf("\n");
  gotoxy(21,3);  gets(cari);
  i = 0;
  while(i<mk.jum){
    if(stricmp(mk.nama[i],cari)==0){
      ketemu = 1;  k = i; system("CLS");
      garis(201,205,26,"",27,187);printf("\n");
      garis(186,0,12,"DAFTAR NILAI PER MATA KULIAH",13,186);printf("\n");
      garis(204,205,26,"",27,185);printf("\n");
      printf("%c Mata Kuliah : %-37s %c\n",char(186),mk.nama[i],char(186));
      printf("%c Nama Dosen  : %-37s %c\n",char(186),mk.dosen[i],char(186));
      printf("%c SKS         : %-37d %c\n",char(186),mk.sks[i],char(186)); garis(204,205,0,"",4,203);garis(205,205,0,"",26,203);garis(205,205,0,"",11,203);garis(205,205,0,"",6,185);printf("\n");
      i++;                            
    }
    else i++;             
  }
  if(!ketemu){
    gotoxy(0,4);
    garis(204,205,0,"",50,185);printf("\n");
    garis(186,0,9,"Data Mata Kuliah tidak ditemukan",9,186);printf("\n");
    garis(200,205,0,"",50,188);printf("\n");         
  }
  else{
    printf("%c %-2s %c %-25s %c %-10s %c %-5s %c\n",char(186),"No",char(186),"Nama Mahasiswa",char(186),"NIM",char(186),"Nilai",char(186));
    garis(204,205,0,"",4,206);garis(205,205,0,"",26,206);garis(205,205,0,"",11,206);garis(205,205,0,"",6,185);printf("\n");
    for(i=0;i<mhs.jum;i++){
      for(j=0;j<1;j++){                   
        printf("%c %-2d %c %-25s %c %-10s %c %-5d %c\n",char(186),i+1,char(186),mhs.nama[i],char(186),mhs.nim[i],char(186),mhs.nilai[i][k],char(186));
        jum_nilai += mhs.nilai[i][k];
      }                     
    }
    jum = i + 0.0;
    rata = jum_nilai / jum;
    garis(204,205,0,"",4,202);garis(205,205,0,"",26,202);garis(205,205,0,"",11,202);garis(205,205,0,"",6,185);printf("\n");
    printf("%c Nilai Rata-Rata : %-33.1f %c\n",char(186),rata,char(186));
    garis(200,205,26,"",27,188);printf("\n\n");
    for(i=0;i<mhs.jum;i++){
      for(j=0;j<1;j++){
        printf("%25s ",mhs.nama[i]);
        for(int c=0;c<mhs.nilai[i][k]/10;c++)
          printf("%c",char(254));
        printf("\n");             
      }                     
    } 
  }   
}

void khsmhs(){
  char cari[x];
  int ketemu = 0;
  float hasil[x][x];
  int jum_sks = 0;
  float jum_hasil = 0;
  fflush(stdin);
  system("CLS");
  garis(201,205,0,"",50,187);printf("\n");
  garis(186,0,14,"MENCARI DATA MAHASISWA",14,186);printf("\n");
  garis(204,205,0,"",50,185);printf("\n");
  garis(186,0,1,"Nama Mahasiswa : ",32,186);printf("\n");
  garis(200,205,0,"",50,188);printf("\n");
  gotoxy(19,3);
  gets(cari);
  i = 0;
  while(i<mhs.jum){
    if(stricmp(mhs.nama[i],cari)==0){
      ketemu = 1;
      system("CLS");
      garis(201,205,0,"",72,187);printf("\n");
      garis(186,0,23,"KARTU HASIL STUDI MAHASISWA",22,186);printf("\n");
      garis(204,205,0,"",72,185);printf("\n");
      printf("%c Nama : %-63s %c\n",char(186),mhs.nama[i],char(186));
      printf("%c NIM  : %-63s %c\n",char(186),mhs.nim[i],char(186));
      garis(204,205,0,"",4,203);garis(205,205,0,"",26,203);garis(205,205,0,"",6,203);garis(205,205,0,"",6,203);garis(205,205,0,"",6,203);garis(205,205,0,"",6,203);garis(205,205,0,"",6,185);printf("\n");
      printf("%c %-2s %c %-25s %c %-5s %c %-5s %c %-5s %c %-5s %c %-5s %c\n",char(186),"No",char(186),"Nama Mata Kuliah",char(186),"SKS",char(186),"Nilai",char(186),"Huruf",char(186),"Bobot",char(186),"Hasil",char(186));
      garis(204,205,0,"",4,206);garis(205,205,0,"",26,206);garis(205,205,0,"",6,206);garis(205,205,0,"",6,206);garis(205,205,0,"",6,206);garis(205,205,0,"",6,206);garis(205,205,0,"",6,185);printf("\n");
      for(j=0;j<mk.jum;j++){
        perhitungan();
        hasil[i][j] = mk.sks[j] * bobot[i][j];
        printf("%c %-2d %c %-25s %c %-5d %c %-5d %c %-5c %c %-5.2f %c %-5.2f %c\n",char(186),j+1,char(186),mk.nama[j],char(186),mk.sks[j],char(186),mhs.nilai[i][j],char(186),huruf,char(186),bobot[i][j],char(186),hasil[i][j],char(186));                   
        jum_sks += mk.sks[j];
        jum_hasil += hasil[i][j];
      }
      ip = jum_hasil / jum_sks;
      perhitungan();
      garis(204,205,0,"",4,202);garis(205,205,0,"",26,202);garis(205,205,0,"",6,202);garis(205,205,0,"",6,202);garis(205,205,0,"",6,202);garis(205,205,0,"",6,202);garis(205,205,0,"",6,185);printf("\n");
      printf("%c Indeks Prestasi : %-53.2f%c\n",char(186),ip,char(186));
      printf("%c Berhak mengambil %-2d SKS pada semester berikutnya                       %c\n",char(186),sksn,char(186));
      garis(200,205,0,"",72,188);printf("\n\n");
      for(j=0;j<mk.jum;j++){
        printf("%25s ",mk.nama[j]);
        for(int c=0;c<mhs.nilai[i][j]/10;c++)
          printf("%c",char(254));
        printf("\n");                    
      }
      i++;
    }
    else i++;             
  }
  if(!ketemu){
    gotoxy(0,4);
    garis(204,205,0,"",50,185);printf("\n");
    garis(186,0,10,"Data Mahasiswa tidak ditemukan",10,186);printf("\n");
    garis(200,205,0,"",50,188);printf("\n");         
  }   
}

void perhitungan(){
  // Sumber : http://fmipa.unmul.ac.id/index.php/page/show/pedoman/
  if(mhs.nilai[i][j]==100){huruf = 'A'; bobot[i][j] = 4.00;}
  else if(mhs.nilai[i][j]>=90){huruf = 'A'; bobot[i][j] = 4.00;}
  else if(mhs.nilai[i][j]>=80){huruf = 'A'; bobot[i][j] = 4.00;}
  else if(mhs.nilai[i][j]>75){huruf = 'B'; bobot[i][j] =3.75;}
  else if(mhs.nilai[i][j]==75){huruf = 'B'; bobot[i][j] =3.50;}
  else if(mhs.nilai[i][j]>70){huruf = 'B'; bobot[i][j] =3.25;}
  else if(mhs.nilai[i][j]==70){huruf = 'B'; bobot[i][j] =3.00;}
  else if(mhs.nilai[i][j]>65){huruf = 'C'; bobot[i][j] =2.75;}
  else if(mhs.nilai[i][j]==65){huruf = 'C'; bobot[i][j] =2.50;}
  else if(mhs.nilai[i][j]>60){huruf = 'C'; bobot[i][j] =2.25;}
  else if(mhs.nilai[i][j]==60){huruf = 'C'; bobot[i][j] =2.00;}
  else if(mhs.nilai[i][j]>50){huruf = 'D'; bobot[i][j] =1.75;}
  else if(mhs.nilai[i][j]==50){huruf = 'D'; bobot[i][j] =1.50;}
  else if(mhs.nilai[i][j]>40){huruf = 'E'; bobot[i][j] =1.25;}
  else if(mhs.nilai[i][j]==40){huruf = 'E'; bobot[i][j] =1.00;}
  else{huruf = 'E'; bobot[i][j] =0.00;}
 
  if(ip>3.00) sksn = 24;
  else if(ip>=2.82) sksn = 21;
  else if(ip>=2.66) sksn = 20;
  else if(ip>=2.50) sksn = 19;
  else if(ip>=2.32) sksn = 18;
  else if(ip>=2.16) sksn = 17;
  else if(ip>=2.00) sksn = 16;
  else if(ip>=1.82) sksn = 15;
  else if(ip>=1.66) sksn = 14;
  else if(ip>=1.50) sksn = 13;
  else sksn = 12;              
}

void tentang(){
  system("CLS");
  garis(201,205,0,"",43,187);printf("\n");
  garis(186,0,14,"TENTANG PROGRAM",14,186);printf("\n");
  garis(204,205,0,"",43,185);printf("\n");
  garis(186,0,2,"Program sederhana ini dibuat oleh Ahmad",2,186);printf("\n");
  garis(186,0,10,"Samarinda, 20 Juni 2010",10,186);printf("\n");
  garis(200,205,0,"",43,188);printf("\n");
}

void simpan(){
  ofstream data;
  data.open("data.dbs",ios::out|ios::trunc|ios::binary);
  data.write((char *)&mk,sizeof(mk));
  data.write((char *)&mhs,sizeof(mhs));
  if(!data){
    gotoxy(0,12);
    garis(204,205,0,"",28,185);printf("\n");
    garis(186,0,4,"Data gagal disimpan",5,186);printf("\n");
    garis(200,205,0,"",28,188);printf("\n");
  }
  else{
    gotoxy(0,12);
    garis(204,205,0,"",28,185);printf("\n");
    garis(186,0,4,"Data telah disimpan",5,186);printf("\n");
    garis(200,205,0,"",28,188);printf("\n"); 
  }
  data.close();   
}

void baca(){
  ifstream data("data.dbs",ios::in|ios::binary);
  data.read((char *)&mk,sizeof(mk));
  data.read((char *)&mhs,sizeof(mhs));
  if(!data){
    gotoxy(0,12);
    garis(204,205,0,"",28,185);printf("\n");
    garis(186,0,5,"Data gagal dibaca",6,186);printf("\n");
    garis(200,205,0,"",28,188);printf("\n");
  }
  else{
    gotoxy(0,12);
    garis(204,205,0,"",28,185);printf("\n");
    garis(186,0,5,"Data telah dibaca",6,186);printf("\n");
    garis(200,205,0,"",28,188);printf("\n"); 
  }
  data.close();
}

void garis(int L,int K,int KL,char *T,int KR,int R){
  printf("%c",char(L)); for(int c=0;c<KL;c++) printf("%c",char(K));
  printf("%s",T);  for(int c=0;c<KR;c++) printf("%c",char(K)); printf("%c",char(R)); 
}

void gotoxy(int H,int V){
  COORD pos = {H,V}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}

void start(){
  for(i=0;i<11;i++){
    Sleep(100);
    garis(176,176,78,"",0,176);
  }
  garis(176,176,27,"                        ",27,176);
  garis(176,176,27,"     SELAMAT DATANG     ",27,176);
  garis(176,176,27,"                        ",27,176);
  for(i=0;i<10;i++){
    Sleep(100);
    garis(176,176,78,"",0,176);
  }
  for(i=0;i<80;i++){
    Sleep(50);
    printf("%c",char(219));
  } 
}

Previous
Next Post »