Array/List

An array (or list) is a collection that contains multiple pieces of data. Generally, an array has indices (a sequence in the collection of data) that start from 0. To declare an array, you can add square brackets “[]” after the variable name and initialize it with curly braces “{},” separating each data element with a comma “,”.

Basic Example of Using an Array:

1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main() {
int iniList[] = {25, 50, 75, 100};
printf("%d", iniList[0]);
printf("%d", iniList[3]);

return 0;
}

Array/List Task

Create a list of names and implement a menu that can display, edit, and delete the list items, allowing the program to run repeatedly. Here is the expected output:

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Menu
1. Display
2. Edit
3. Delete
0. Exit
Enter Menu: 8 (User input)
Invalid Input

Menu
1. Display
2. Edit
3. Delete
0. Exit
Enter Menu: 1 (User input)
Index 0: Azhar
Index 1: Jordie
Index 2: Ridho
Index 3: Ardi
Index 4: Clementius
Index 5: Jasmine
Data Successfully Displayed

Menu
1. Display
2. Edit
3. Delete
0. Exit
Enter Menu: 2 (User input)
Enter the index you want to edit: 2 (User input)
Enter the new name: Dian (User input)
Data in the list has been successfully changed

Menu
1. Display
2. Edit
3. Delete
0. Exit
Enter Menu: 1 (User input)
Index 0: Azhar
Index 1: Jordie
Index 2: Dian
Index 3: Ardi
Index 4: Clementius
Index 5: Jasmine
Data Successfully Displayed

Menu
1. Display
2. Edit
3. Delete
0. Exit
Enter Menu: 3 (User input)
Enter the index you want to delete: 4 (User input)
Data Successfully Deleted

Menu
1. Display
2. Edit
3. Delete
0. Exit
Enter Menu: 1 (User input)
Index 0: Azhar
Index 1: Jordie
Index 2: Dian
Index 3: Ardi
Index 4:
Index 5: Jasmine
Data Successfully Displayed

Menu
1. Display
2. Edit
3. Delete
0. Exit
Enter Menu: 0 (User input)
Thank you for using my program