Rabu, 05 Desember 2012

Menghitung IPK (Struct)


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

struct mhs
{ int npm[15];
char nama [35]
int terhapus;
}mhs[3];

void main()

{ int i, cari, ketemu;

cout<<"\t\t\tSTMIK AMIKOM YOGYAKARTA";
cout<<endl<<endl;

cout<<"\n\nMasukan Data";

for(i=0;i<3;i++)

{ cout<<"Nama = ";cin>>mhs[i].nama);
cout<<"NIM = ";cin>>mhs[i].nim);
data[i].terhapus = 0;
};

cout<<"Isi data\n";
for(i=0;i<3;i++)
{ if (data[i].terhapus == 0) //tampilkan data yg belum terhapus
printf("Nama = %d\tIPK = %f\n", data[i].npm, data[i].ipk);

};

printf("Cari Nama = "); scanf("%d", &cari); ketemu = 0;
for(i=0;i<3;i++)
{ if (cari == data[i].npm)
ketemu = 1;
}
if (ketemu == 1)
cout<<"\nNama ditemukan";
else
cout<<"\nNama tidak ada";

      printf("Cari Nama hapus = "); scanf("%d", &cari);
for(i=0;i<3;i++)
{ if ((cari == data[i].npm) && (data[i].terhapus == 0))
{ data[i].terhapus = 1; break;

}
}

cout<<"\nIsi data";
for(i=0;i<3;i++)
{ if (data[i].terhapus == 0)
printf("Nama = %d\tIPK = %f\n", data[i].npm, data[i].ipk);
};

printf("Cari Nama yang akan di edit = "); scanf("%d", &cari);
for(i=0;i<3;i++)
{ if (cari == data[i].npm && (data[i].terhapus == 0))
{ cout<<"Masukkan data baru:\n";

printf("Nama = "); scanf("%d", &data[i].npm);
printf("IPK = "); scanf("%f", &data[i].ipk);
data[i].terhapus = 0;
}
}

cout<<"\nIsi data";
for(i=0;i<3;i++)
{ if ((data[i].terhapus == 0))
printf("Nama = %d\tIPK = %f\n", data[i].npm, data[i].ipk);
};

}

0 komentar:

Posting Komentar