You are on page 1of 2

Program berikut adalah pengisian nilai mahasiswa dengan menggunakan struct pointer

sebagai array.
#include <iostream.h>
#include <conio.h>
void Input(Mahasiswa *mhs, int jumData);
void ProsesData(Mahasiswa *mhs, int jumData);
void main()
{
int jumData;
Mahasiswa*mhs;
cout<<"Masukkanjumlah data : ";
cin>>jumData;
mhs=new Mahasiswa[jumData];
Input(mhs, jumData);
ProsesData(mhs, jumData);
Cetak(mhs, jumData);
}
struct Mahasiswa
{
int No;
char Nama[20], Nim[15], Nilai;
float Tugas, UTS, UAS;
};
void Input(Mahasiswa *mhs, int jumData)
{
cout<<endl;
for(int i=0; i<jumData; i++)
{
cout<<"No\t\t: "<<(i+1)<<endl;
mhs[i].No=i+1;
cout<<"Nama\t\t: ";
cin>>mhs[i].Nama;
cout<<"Nim\t\t: ";
cin>>mhs[i].Nim;
cout<<"Nilai Tugas\t: ";
cin>>mhs[i].Tugas;
cout<<"Nilai UTS\t: ";
cin>>mhs[i].UTS;
cout<<"Nilai UAS\t: ";
cin>>mhs[i].UAS;
mhs[i].Nilai='\0';
cout<<endl;
}
}
void ProsesData(Mahasiswa *mhs, int jumData)
{
float nilai;
for(int i=0; i<jumData; i++)
{
nilai=(mhs[i].Tugas*0.3)+(mhs[i].UTS*0.3)+(mhs[i].UAS*0.4);
if(nilai>85)
{
mhs[i].Nilai='\A';
}
else if (nilai<85 && nilai>=75)
{
mhs[i].Nilai='\B';
}
else if (nilai<75 && nilai>=60)
{
mhs[i].Nilai='\C';
}
else if (nilai<60 && nilai>=50)
{
mhs[i].Nilai='\D';
}
else if (nilai<50)
{
mhs[i].Nilai='\E';
}
}
}
void Cetak(Mahasiswa *mhs, int jumData)
{
clrscr();
cout<<"----------------------------------------------------
----\n";
cout<<"No Nim Nama Tugas UTS UAS Nilai\n";
cout<<"----------------------------------------------------
----\n";
int y=4;
for(int i=0; i<jumData; i++)
{
cout<<mhs[i].No;
gotoxy(5,y);
cout<<mhs[i].Nim;
gotoxy(15,y);
cout<<mhs[i].Nama;
gotoxy(30,y);
cout<<mhs[i].Tugas;
gotoxy(38,y);
cout<<mhs[i].UTS;
gotoxy(46,y);
cout<<mhs[i].UAS;
gotoxy(54,y);
cout<<mhs[i].Nilai<<endl;
y++;
}
cout<<"----------------------------------------------------
----\n";
}