-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8-struct.cpp
More file actions
35 lines (29 loc) · 820 Bytes
/
8-struct.cpp
File metadata and controls
35 lines (29 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
using namespace std;
// membuat struct
struct Mahasiswa {
string nama;
string alamat;
int usia;
};
int main(){
// menggunakan struct
Mahasiswa mhs1;
// mengisi nilai ke struct cara ke-1
mhs1.nama = "Septi";
mhs1.alamat = "Bandung";
mhs1.usia = 22;
// mengisi nilai ke struct cara ke-2
Mahasiswa mhs2 = {"Fariz", "Jakarta", 23};
// mencetak isi struct
cout << "## Mahasiswa 1 ##\n";
cout << "Nama: " << mhs1.nama << endl;
cout << "Alamat: " << mhs1.alamat << endl;
cout << "Umur: " << mhs1.usia << endl;
cout << "=========================="<<endl;
cout << "## Mahasiswa 2 ##\n";
cout << "Nama: " << mhs2.nama << endl;
cout << "Alamat: " << mhs2.alamat << endl;
cout << "Umur: " << mhs2.usia << endl;
return 0;
}