Selasa, 25 November 2008

Mencari ranking

#include iostream.h>

#include conio.h>



void main()

{

typedef struct {

char nim[10];

char nama[30];

int tgs, uts, uas;

double na;

}idmhs;

idmhs mhs[50];

int i,n;

cout<<"Masukkan banyak mahasiswa : ";
cin>>n;

cout<<"\n==================================================";
cout<<"\n| NIM | Nama | TGS | UTS | UAS | NA |";
cout<<"\n--------------------------------------------------";
int y=6;

for (i=0;i {

gotoxy(1,y); cout<<"|";
gotoxy(11,y); cout<<"|";
gotoxy(27,y); cout<<"|";
gotoxy(33,y); cout<<"|";
gotoxy(39,y); cout<<"|";
gotoxy(45,y); cout<<"|";
gotoxy(50,y); cout<<"|";
gotoxy(1,(n+6));

cout<<"==================================================\n";
y++;

}

y=6;

for (i=0;i {

gotoxy(2,y);

cin>>mhs[i].nim;

gotoxy(12,y);

cin>>mhs[i].nama;

gotoxy(28,y);

cin>>mhs[i].tgs;

gotoxy(34,y);

cin>>mhs[i].uts;

gotoxy(40,y);

cin>>mhs[i].uas;

mhs[i].na = (mhs[i].tgs + 2*mhs[i].uts + 4*mhs[i].uas)/7;

gotoxy(46,y);

cout< y++;

}

idmhs temp;

int j;

for (i=1;i<=n;i++)
{

for (j=n;j>=1;j--)

{

if (mhs[j].na > mhs[j-1].na)

{

//Menukar nilai

temp=mhs[j];

mhs[j]=mhs[j-1];

mhs[j-1]=temp;

}

}

}

clrscr();

cout<<"\n===========================================================";
cout<<"\n| NIM | Nama | TGS | UTS | UAS | NA |Rangking|";
cout<<"\n-----------------------------------------------------------";
int r =1;

y=5;

for (i=0;i {

gotoxy(1,y); cout<<"|";
gotoxy(11,y); cout<<"|";
gotoxy(27,y); cout<<"|";
gotoxy(33,y); cout<<"|";
gotoxy(39,y); cout<<"|";
gotoxy(45,y); cout<<"|";
gotoxy(50,y); cout<<"|";
gotoxy(59,y); cout<<"|";
gotoxy(2,y);

cout< gotoxy(12,y);

cout< gotoxy(28,y);

cout< gotoxy(34,y);

cout< gotoxy(40,y);

cout< gotoxy(46,y);

cout< gotoxy(55,y);

cout< gotoxy(1,(n+5));

cout<<"===========================================================\n";
y++;

r++;

}



/*for (i=0;i {

cout<<"\nMahasiswa ke-"< cout<<"\nNim : "< cout<<"\nNama : "< cout<<"\nNA : " < }*/

getch();

}

0 komentar:

Template by : kendhin x-template.blogspot.com