-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct_array.cpp
More file actions
36 lines (28 loc) · 873 Bytes
/
Copy pathstruct_array.cpp
File metadata and controls
36 lines (28 loc) · 873 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
34
35
36
#include <iostream>
#include <string>
// Menggunakan namespace std
using namespace std;
// Mendefinisikan struktur "Person" dengan anggota "name" dan "age"
struct Person {
string name;
int age;
};
int main() {
// Mendeklarasikan array of structure "Person"
const int numberOfPeople = 3;
Person people[numberOfPeople];
// Mengisi nilai anggota struktur untuk setiap elemen dalam array
people[0].name = "John";
people[0].age = 25;
people[1].name = "Alice";
people[1].age = 30;
people[2].name = "Bob";
people[2].age = 28;
// Menampilkan nilai anggota struktur untuk setiap elemen dalam array
for (int i = 0; i < numberOfPeople; ++i) {
cout << "Person " << i + 1 << ":\n";
cout << "Name: " << people[i].name << endl;
cout << "Age: " << people[i].age << endl << endl;
}
return 0;
}