Created
March 4, 2019 15:51
-
-
Save fahmifan/428e7748e06e313872a6180ba3722e78 to your computer and use it in GitHub Desktop.
Contoh Penggunaan Array of Record
This file contains 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
/** | |
* Muhammad Fahmi | |
* 1401810160028 | |
* Contoh Penggunaan Array of Record | |
* 11/03/2018 | |
* | |
* Compile using : g++ -c arrayOfRecord.cpp && g++ -o arrayOfRecord.exe arrayOfRecord.o && arrayOfRecord.exe | |
*/ | |
#include <iostream> | |
using namespace std; | |
struct mahasiswa { | |
char NPM[8]; | |
char nama[20]; | |
int nilai; | |
}; | |
typedef mahasiswa LarikMhs[10]; | |
void banyakData(int& n); | |
void inputMahasiswa(LarikMhs& Mhs, int n); | |
void cetakMahasiswa(LarikMhs Mhs, int n); | |
int main() { | |
LarikMhs Mhs; | |
int n; | |
banyakData(n); | |
inputMahasiswa(Mhs, n); | |
cetakMahasiswa(Mhs, n); | |
} | |
// Input banyak data | |
void banyakData(int& n) { | |
cout << "Banyak data : "; cin >> n; | |
} | |
void inputMahasiswa(LarikMhs& Mhs, int n) { | |
for(int i = 0; i < n; i++) { | |
cout << "Masukkan data mahasiswa ke-" << i + 1 << endl; | |
cout << "NPM : "; cin >> Mhs[i].NPM; | |
cout << "Nama : "; cin >> Mhs[i].nama; | |
cout << "Nilai : "; cin >> Mhs[i].nilai; | |
cout << endl; | |
} | |
} | |
void cetakMahasiswa(LarikMhs Mhs, int n) { | |
printf("\nPencetakan Data Mahasiswa\n"); | |
printf("--------------------------\n"); | |
for(int i = 0; i < n; i++) { | |
printf("%s\n%s\n%d\n\n", Mhs[i].NPM, Mhs[i].nama, Mhs[i].nilai); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment