Last active
September 19, 2017 16:13
-
-
Save myusufid/34b9c7270ed669209c6a8783d6a0b807 to your computer and use it in GitHub Desktop.
Basic CRUD Array C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main(){ | |
| int jumlaharray = 6; | |
| int array[jumlaharray] = {5,2,1,6,8,2}; | |
| int index, nilai; | |
| //menampilkan array | |
| for(int i=0;i<jumlaharray;i++){ | |
| cout<<array[i]<<" "; | |
| } | |
| cout<<endl; | |
| //edit array | |
| cout<<"Edit Array "<<endl; | |
| cout<<"Index Ke Berapa : ";cin>>index; | |
| cout<<"Masukkan Nilainya : ";cin>>nilai; | |
| array[index] = nilai; | |
| //tampilkan | |
| for(int i=0;i<jumlaharray;i++){ | |
| cout<<array[i]<<" "; | |
| } | |
| cout<<endl; | |
| //hapus array | |
| cout<<"Hapus Array"<<endl; | |
| cout<<"Index ke Berapa : ";cin>>index; | |
| for(int i=index;i<jumlaharray-1;i++){ | |
| array[i] = array[i+1]; | |
| } | |
| //tampilkan kembali | |
| for(int i=0;i<jumlaharray-1;i++){ | |
| cout<<array[i]<<" "; | |
| } | |
| cout<<endl; | |
| //cari array | |
| for(int i=0;i<jumlaharray-1;i++){ | |
| cout<<array[i]<<" "; | |
| } | |
| cout<<"\n Cari Angka Berapa : "; | |
| cin>>nilai; | |
| for(int i=0;i<jumlaharray-1;i++){ | |
| if(array[i]==nilai){ | |
| cout<<"Data Ditemukan di Index ke - "<<i; | |
| break; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main(){ | |
| int jml, i; | |
| char nama[100][100]; | |
| float tugas[5],ujian[5],nilaiakhir[5]; | |
| cout<<"Masukkan Jumlah Mahasiswa yang ingin diinputkan : "; | |
| cin>>jml; | |
| for(i=0;i<jml;i++){ | |
| cout<<"Data Mahasiswa Ke - "<<i<<endl; | |
| cout<<"Masukkan Nama : ";cin>>nama[i]; | |
| cout<<"Masukkan Nilai Tugas : ";cin>>tugas[i]; | |
| cout<<"Masukkan Nilai Ujian : ";cin>>ujian[i]; | |
| nilaiakhir[i] = (tugas[i] + ujian[i])/2; | |
| } | |
| for(i=0;i<jml;i++){ | |
| cout<<"Nama : "<<nama[i]<<endl; | |
| cout<<"Nilai Tugas : "<<tugas[i]<<endl; | |
| cout<<"Nilai Ujian : "<<ujian[i]<<endl; | |
| cout<<"Nilai Akhir : "<<nilaiakhir[i]<<endl; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment