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;
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:
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