#include
#include
#include
#include
#include
#include
#include
int i,n;
class mahasiswa
{
private:
char nim[20];
char nama[40];
char alamat[40];
char tanggal[20];
float ipk;
public:
void tambah();
void tampil();
void edit(mahasiswa y);
int banding_nama(mahasiswa y);
int banding_nim(mahasiswa y);
int banding_tanggal(mahasiswa y);
int banding_alamat(mahasiswa y);
int banding_ipk(mahasiswa y);
float banding_rata(mahasiswa y);
int banding_cari1(mahasiswa y);
int banding_cari2(mahasiswa y);
};
void mahasiswa::tambah()
{
cout<
cout<<"Nim :";
cin.getline(nim,sizeof(nim));
cout<<"Nama :";
cin.getline(nama,sizeof(nama));
cout<<"Alamat :";
cin.getline(alamat,sizeof(alamat));
cout<<"Tanggal Lahir:";
cin.getline(tanggal,sizeof(tanggal));
cout<<"IPK :";
cin>>ipk;
strupr(nama);
}
void mahasiswa:: tampil()
{
cout<<" Nim :"<<
cout<<" Nama :"<<
cout<<" Alamat :"<<
cout<<" Tanggal Lahir :"<<
cout<<" IPK :"<<
}
void simpan(mahasiswa x[])
{
ifstream file_mhs("mhs.txt");
i=0;
while(!file_mhs.eof())
{
file_mhs.read((char *)&x[i],sizeof(x[i]));
i++; n=i-1;
}
file_mhs.close();
}
int mahasiswa ::banding_nama(mahasiswa y)
{
int banding=strcmp(y.nama,nama);
if(banding<0) return(0);
else return(1);
}
int mahasiswa::banding_alamat(mahasiswa y)
{
int banding=strcmp(y.alamat,alamat);
if(banding<0) return(0);
else return(1);
}
int mahasiswa::banding_nim(mahasiswa y)
{
int banding=strcmp(y.nim,nim);
if(banding<0) return(0);
else return(1);
}
int mahasiswa::banding_tanggal(mahasiswa y)
{
int banding=strcmp(y.tanggal,tanggal);
if(banding<0) return(0);
else return(1);
}
int mahasiswa::banding_ipk(mahasiswa y)
{
if(ipk
else return(1);
}
float mahasiswa::banding_rata(mahasiswa y)
{return (y.ipk);}
void mahasiswa::edit(mahasiswa y)
{
strcpy(nim,y.nim);
strcpy(nama,y.nama);
ipk=y.ipk;
strcpy(alamat,y.alamat);
strcpy(tanggal,y.tanggal);
}
void main()
{
mahasiswa data[100],b;
int C,c;
int p=0;
while(p<10)
{ clrscr();
cout<<"1.Menambahkan data mahasiswa"<
cout<<"2.Menampilkan data mahasiswa"<
cout<<"3.Mengurutkan data berdasarkan nim (1-9)"<
cout<<"4.Mengurutkan data berdasarkan nama (a-z)"<
cout<<"5.Edit data mahasiswa"<
cout<<"6.Rata-rata ipk"<
cout<<"7.Mengurutkan data berdasarkan nim (9-1)"<
cout<<"8.Mengurutkan data berdasarkan nama (z-a)"<
cout<<"9.searching nama"<
cout<<"10.serching alamat"<
cout<<"11.exit"<
cout<<"Masukkan pilihan !";
cin>>p;
if(p==1)
{ clrscr();
cout<<"\n\nBanyak data mahasiswa : ";
cin>>c;
char key[5]; //tipuan(?)
cout<<"\n\n\tINPUT DATA\n";
for(i=0;i
{
cin.getline(key,sizeof(key));
data[i].tambah();
}
ofstream file_mhs("mhs.txt",ios::app);
for(i=0;i
{
file_mhs.write((char *)&data[i],sizeof(data[i]));
cout<
}
file_mhs.close();
getch();
}
if(p==2)
{ clrscr();
simpan(data);
for(i=0;i
data[i].tampil();
getch();
}
if(p==3)
{ clrscr();
simpan(data); //back to awal
cout<<"\n\n\t\t Data urut berdasarkan NIM (1-9)\n\n";
for(int j=n-1;j>1;j--)
{
for(i=0;i
{
C=data[i].banding_nim(data[i+1]);
if(C==0)
{
b=data[i];
data[i]=data[i+1];
data[i+1]=b;
}
}
}
for(i=0;i
data[i].tampil() ;
getch();
}
if(p==4)
{
clrscr();
simpan(data); //back to awal
cout<<"\n\n\t\t Data urut berdasarkan IPK\n\n";
for(int j=n;j>0;j--)
{
for(i=0;i
{
C=data[i].banding_ipk(data[i+1]);
if(C==0)
{
b=data[i];
data[i]=data[i+1];
data[i+1]=b;
}
}
}
for(i=0;i
data[i].tampil();
getch();
}
if(p==5)
{
mahasiswa d;
clrscr();
simpan(data);
for(i=0;i
data[i].tampil();
cout<<"\n\nNomor data yang diubah : "; cin>>C;
char key[5]; cin.getline(key,sizeof(key));
d.tambah();
data[C-1].edit(d);
ofstream file_mhs("mhs.txt");
for(i=0;i
file_mhs.write((char *)&data[i],sizeof(data[i]));
file_mhs.close();
clrscr();
for(i=0;i
data[i].tampil();
getch();
}
if(p==6)
{ simpan(data);
clrscr();
float sum=0;
float rata;
for(i=0;i
{sum=sum+data[i].banding_rata(data[i]);
}
rata=sum/n;
cout<<"Rata-rata IPK = "<
getch();
}
if(p==7)
{
clrscr();
simpan(data); //back to awal
cout<<"\n\n\t\t Data urut berdasarkan NIM (9-1)\n\n";
for(int j=n-1;j>1;j--)
{
for(i=0;i
{
C=data[i+1].banding_nim(data[i]);
if(C==0)
{
b=data[i];
data[i]=data[i+1];
data[i+1]=b;
}
}
}
for(i=0;i
data[i].tampil() ;
getch();
}
if(p==8)
{
clrscr();
simpan(data); //back to awal
cout<<"\n\n\t\t Data urut berdasarkan ipk (9-1)\n\n";
for(int j=n-1;j>0;j--)
{
for(i=0;i
{
C=data[i].banding_ipk(data[i+1]);
if(C==0)
{
b=data[i];
data[i]=data[i+1];
data[i+1]=b;
}
}
}
for(i=0;i
data[i].tampil() ;
getch();
}
if(p==9)
{ simpan(data);
clrscr();
int cari;
cout<<"Masukkan nama yang akan dicari ";
cin>>cari;
for(i=0;i
{if (cari=data[i].banding_rata(data[i]))
break;
data[i].tampil();
getch();
}
}
}
getch();
}Sumber: http://kampungilmukita.blogspot.com/2010/08/program-pengelolaan-mahasiswa-dengan.html
0 komentar:
Posting Komentar