Skip to content

Mencari ranking

November 26, 2008

#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<n;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<n;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<<mhs[i].na;

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<n;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<<mhs[i].nim;

gotoxy(12,y);

cout<<mhs[i].nama;

gotoxy(28,y);

cout<<mhs[i].tgs;

gotoxy(34,y);

cout<<mhs[i].uts;

gotoxy(40,y);

cout<<mhs[i].uas;

gotoxy(46,y);

cout<<mhs[i].na;

gotoxy(55,y);

cout<<r;

gotoxy(1,(n+5));

cout<<"===========================================================\n";

y++;

r++;

}

/*for (i=0;i<n;i++)

{

cout<<"\nMahasiswa ke-"<<i+1;

cout<<"\nNim : "<<mhs[i].nim;

cout<<"\nNama : "<<mhs[i].nama;

cout<<"\nNA : " <<mhs[i].na;

}*/

getch();

}

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: