Assalamualaikum
wr wb..
Selamat malam,
ketemu lagiiii..
Kali in kembali lagi
saya akan berbagi sedikit source kode yang saya pelajari, program ini berisi
tentang peringkat mahasiswa tertinggi menggunakan compiler code block
#include
<stdio.h>
#include
<conio.h>
#include
<windows.h>
#include
<string.h>
#include
<stdlib.h>
#include
<time.h>
void
gotoxy(int x, int y){
HANDLE o;COORD
i;
i.X = x;i.Y =
y;
o =
GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(o,i);
}
int i=0,
h,j,k,l,m,p;
FILE *pf;
char temp[10];
struct
mahasiswa{
char nama[10];
int a,b,c,d, g;
}mhs[100];
void fileo(){
pf =
fopen("SitiMuliaSari.TXT", "a+");
if(pf!=NULL) {
for(i=0;i!=5;i++){
fprintf(pf,
"%s \t - %d\n", mhs[i].nama, mhs[i].g);
} fprintf(pf, "\n");
} else {
printf("File
Tidak Dapat Diakses");
} fclose(pf);
}
void sorting()
{
for(p=0;p!=5;p++)
{
for(i=0;i!=5;i++){
h = mhs[i].g;
j = mhs[i].a;
k = mhs[i].b;
l = mhs[i].c;
m = mhs[i].d;
strcpy(temp,mhs[i].nama);
while(h<mhs[i+1].g){
mhs[i].g =
mhs[i+1].g;
mhs[i+1].g
= h;
mhs[i].a =
mhs[i+1].a;
mhs[i+1].a
= j;
mhs[i].b =
mhs[i+1].b;
mhs[i+1].b
= k;
mhs[i].c =
mhs[i+1].c;
mhs[i+1].c
= l;
mhs[j+i].d
= mhs[i+1].d;
mhs[i+1].d
= m;
strcpy(mhs[i].nama,mhs[i+1].nama);
strcpy(mhs[i+1].nama,temp);
}
}
}
}
void
selection()
{
for(i=0;i!=5;i++)
{
if(mhs[i].a==2)
mhs[i].g
+= 6;
if(mhs[i].a==3)
mhs[i].g
+= 24;
if(mhs[i].a>=4)
mhs[i].g
+= 30;
}
//Penghargaan
for(i=0;i!=5;i++)
{
if(mhs[i].d==2)
mhs[i].g
+= 6;
if(mhs[i].d==3)
mhs[i].g
+= 24;
if(mhs[i].d>=4)
mhs[i].g
+= 30;
}
for(i=0;i!=5;i++)
{
if(mhs[i].b==2)
mhs[i].g
+= 4;
if(mhs[i].b==3)
mhs[i].g
+= 16;
if(mhs[i].b>=4)
mhs[i].g
+= 20;
}
for(i=0;i!=5;i++){
if(mhs[i].b==1)
mhs[i].g
+= 4;
if(mhs[i].b==2)
mhs[i].g
+= 12;
if(mhs[i].b>=3)
mhs[i].g
+= 20;
}
sorting();
}
int main ()
{
do
{
gotoxy(0,0); printf("Nama
Mahasiswa : ");
gotoxy(0,1); printf("Bahasa
Asing : ");
gotoxy(0,2);
printf("Organisasi : ");
gotoxy(0,3); printf("IPK : ");
gotoxy(0,4);
printf("Penghargaan :
");
gotoxy(19,0);
scanf("%s", &mhs[i].nama);
gotoxy(19,1);
scanf("%d", &mhs[i].a);
gotoxy(19,2);
scanf("%d", &mhs[i].b);
gotoxy(19,3);
scanf("%d", &mhs[i].c);
gotoxy(19,4);
scanf("%d", &mhs[i].d);
i++;
system("cls");
}while(i!=5);
selection();
fileo();
print(); getch();
}
print(){
printf(" Tiga Mahasiswa Terbaik\n\n");
for(i=0;i!=3;i++){
printf(" Mahasiswa Peringkat [%d] : %s\t",
i+1, mhs[i].nama);
printf(" = Score
: %d\n", mhs[i].g);
}
}
|
Dan yang kedua
adalah program pembayaran UKT :
#include<stdio.h>
#include<conio.h>
struct Data
{
int nim;
char
nama[100];
int semester;
};
FILE *fp;
void daftar()
{
clrscr();
printf("\t\t\tProgram Pembayaran Uang
Kuliah Tunggal\n\n");
printf("\t[1] Buat File\n");
printf("\t[2] Input Data \n");
printf("\t[3] Pencarian Nim Mahasiswa
dan Pembayaran Uang UKT \n");
printf("\t[4] Pengurutan Nim Mahasiswa
\n");
printf("\t[5] Hapus File \n");
printf("\t[0] Keluar \n");
}
main()
{
int i, a, j, b;
int temp;
int cari;
int menu;
do
{
daftar();
printf("\n\tPilih Menu : ");
scanf("%d", &menu);
switch(menu)
{
case 1 : if
((fp=fopen("UKT.txt","rb"))!=NULL)
{
printf("\n\t ~ File sudah
dibuat dengan nama UKT ~ tekan Enter !");
getche();fclose(fp);
}
else
{
fp=fopen("UKT.txt","wb");
printf("\n\tFile sudah
dibuat, tekan Enter !");
getche();fclose(fp);
}
break;
case 2 :
clrscr();
printf(" Masukkan Jumlah
Data : "); scanf("%d", &a);
printf("\n");
if( (fp=fopen("UKT.txt","wb"))==NULL
)
{
puts("File tak dapat
diciptakan !\r\n");
}
Data data[100];
for(i=0;i<a;i++)
{
printf("Masukkan Nim
Mahasiswa : ");
scanf("%d",
&data[i].nim);
printf("Masukkan Nama : ");
scanf("%s",
&data[i].nama);
printf("Jumlah
Semester : ");
scanf("%d",
&data[i].semester);
printf("\n");
}
fwrite(&data,sizeof(data),1,fp);
printf("\n");
getche();
break;
case 3 : clrscr();
int total, bayar, kembalian;
if(
(fp=fopen("UKT.txt","rb"))==NULL )
{
puts("File tak dapat dibuka
!\r\n");
}
while(fread(&data,sizeof(data),1,fp)==1)
printf("Cari Nim Mahasiswa :
"); scanf("%d", &cari);
for(i=0;i<a;i++) {
if(data[i].nim==cari) {
printf("\nData Ditemukan\n\n");
printf("Nim mahasiswa : %d\n", data[i].nim);
printf("Nama : %s\n",
data[i].nama);
printf("Jumlah
semester : %d\n",
data[i].semester);
total=4000000*data[i].semester;
printf("Total : %d\n", total);
printf("Pembayaran : ");
scanf("%d",
&bayar);
kembalian=bayar-total;
printf("Kembalian : %d\n", kembalian);
}
printf("\n");
getche(); fclose(fp);
}
break;
case 4 :
clrscr();
printf("\nsebelum sorting:
");
for(i=0;i<a;i++)
{
printf("%d ",data[i].nim);
}
for(i=a-2;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if(data[j].nim>data[j+1].nim)
{
temp=data[j].nim;
data[j].nim=data[j+1].nim;
data[j+1].nim=temp;
}
}
}
printf("\n\nsetelah sorting: ");
for(i=0;i<a;i++)
{
printf("%d ",data[i].nim);
}
printf("\n");
getche();
break;
case 5 : remove("UKT.txt");
printf("\n ~ Data
terhapus... tekan Enter !! ~ ");
getche();
break;
case 0 : break;
}
}
while(menu!=0);
getche();
}
|
Mungkin sampai
disini dulu.. semoga bermanfaat ..
0 komentar:
Posting Komentar