Senin, 30 April 2012

program data menggunakan c++


#include <iostream.h>
#include <conio.h>
#include <string.h>

int i,j;
int nilMhs1[90],nilMhs2[90];
char nmMhs[90][10];

void garis(){
       cout<<"======================================"<<endl;
}
int inpNil(){
       cout<<"Masukkan Nilai UTS : ";
       cin>>nilMhs1[j];
       cout<<"Masukkan Nilai UAS : ";
       cin>>nilMhs2[j];
       j=j+1;
       return j;
}
char inpNama(){
       char nama[10];
       cout<<"Masukkan Nama Mahasiswa    : ";
       cin>>nama;
       strcpy(nmMhs[j],nama);
       j=inpNil();
       return 0;
}
void lihatData(){
       cout<<"Nama \tUTS "<<"\tUAS"<<endl;
       garis();
       for (i=0;i<j;i++){
              cout<<nmMhs[i]<<"\t"<<nilMhs1[i]<<"\t"<<nilMhs2[i]<<endl;
       }
}
void ratarata(){
       int rata[90];
       cout<<"Nama \tRata-rata"<<endl;
       garis();
       for (i=0;i<j;i++){
              rata[i]=(nilMhs1[i]+nilMhs2[i])/2;
              cout<<nmMhs[i]<<"\t"<<rata[i]<<endl;
       }
}
void hapusData(){
       int hps;
       cout<<"Hapus Data Mahasiswa "<<endl;
       garis();
       cout<<"Inputkan Index yang akan dihapus (>0) : ";
       cin>>hps;
       hps=hps-1;
       cout<<"Data dengan Index "<<(hps+1)<<" telah dihapus "<<nmMhs[hps]<<endl;

       for(i=hps;i<j;i++){
              strcpy(nmMhs[i],nmMhs[i+1]);
              nilMhs1[i]=nilMhs1[i+1];
              nilMhs2[i]=nilMhs2[i+1];
       }
       j=j-1;
}
void cariData(){
       char hrf;
       char bnt[10];
       int ct;
       ct=0;
       cout<<"Cari Data Mahasiswa"<<endl;
       garis();
       cout<<"Inputkan huruf awal : ";
       cin>>hrf;
       cout<<endl;
       for(i=0;i<j;i++){
              strcpy(bnt,nmMhs[i]);
              if(bnt[0]==hrf){
                     cout<<nmMhs[i]<<"\tIndeks Ke-"<<(i+1)<<endl;
                     ct+=1;
              }

       }
       if(ct==0){
                     cout<<"Data tidak ditemukan"<<endl;
       }
}
void updateData(){
       int inp,jaw;
       jaw=j;

       cout<<"Update Data Mahasiswa"<<endl;
       garis();
       cout<<"Inputkan Indeks : ";
       cin>>inp;
       j=inp-1;
       inpNama();
       cout<<"Data telah terupdate.."<<endl;
       j=jaw;
}
void dataLulus(){
       int rata[90];
       cout<<"Nama \tRata-rata \tLulus"<<endl;
       garis();
       for (i=0;i<j;i++){
              rata[i]=(nilMhs1[i]+nilMhs2[i])/2;
              cout<<nmMhs[i]<<"\t"<<rata[i];
              if (rata[i]<56){
                     cout<<"\t\tTidak Lulus"<<endl;
              }else{
                     cout<<"\t\tLulus"<<endl;
              }
       }
}
void main(){
int pil;
j=0;

do{
cout<<"Program Data Mahasiswa"<<endl;
garis();
cout<<"1. Input Data Mahasiswa"<<endl;
cout<<"2. Lihat Data Mahasiswa"<<endl;
cout<<"3. Lihat Nilai Rata-rata"<<endl;
cout<<"4. Hapus Data Mahasiswa "<<endl;
cout<<"5. Cari Data Mahasiswa "<<endl;
cout<<"6. Update Data Mahasiswa "<<endl;
cout<<"7. Lihat Kelulusan Mahasiswa "<<endl;
cout<<"8. Keluar "<<endl;
garis();
cout<<"Masukkan Pilihan anda = ";
cin>>pil;
garis();

switch(pil)
{
       case 1:
              inpNama();
              garis();
              break;
       case 2:
              lihatData();
              garis();
              break;
       case 3:
              ratarata();
              garis();
              break;
       case 4:
              hapusData();
              garis();
              break;
       case 5:
              cariData();
              garis();
              break;
       case 6:
              updateData();
              garis();
              break;
       case 7:
              dataLulus();
              garis();
              break;
       case 8:
              cout<<"Terima Kasih..."<<endl;
              garis();
              break;

}
}while(pil!=8);
}

Tidak ada komentar:

Posting Komentar