fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int CAP = 10;
  5.  
  6. int main()
  7. {
  8. int size;
  9. int list[CAP] = { 12, 34, 45, 2, 8, 10, 16, 180, 182, 22 };
  10. size = CAP;
  11. int i, delIndex, addIndex, newInt = 0;
  12.  
  13. cout << "Your list is: " << endl;
  14. for (i = 0; i < size; i++)
  15. {
  16. cout << list[i] << endl;
  17. }
  18.  
  19. //Deleting an index
  20.  
  21. cout << "\nPlease enter index to delete from: ";
  22. cin >> delIndex;
  23.  
  24. for (i = delIndex; i < size; i++)
  25. {
  26. list[i] = list[i + 1];
  27. }
  28. size--;
  29. cout << "The index position you specified has been deleted." << endl;
  30. cout << "The new array is: " << endl;
  31. for (i = 0; i < size; i++)
  32. {
  33. cout << list[i] << endl;
  34. }
  35.  
  36. //Adding an index
  37.  
  38. cout << "\nNow, please enter the index position to add to: " << endl;
  39. cin >> addIndex;
  40. cout << "\nEnter the number to add to the index: " << endl;
  41. cin >> newInt;
  42.  
  43. for (i = size - 1; i >= addIndex; i--)
  44. {
  45. list[i + 1] = list[i];
  46. }
  47. list[addIndex] = newInt;
  48. size++;
  49.  
  50. cout << "The number has been added at the specified index position." <<endl;
  51. cout << "The new array is: " << endl;
  52. for (i = 0; i < size; i++)
  53. {
  54. cout << list[i] << endl;
  55. }
  56. return 0;
  57. }
Success #stdin #stdout 0s 4400KB
stdin
3
5
678
stdout
Your list is: 
12
34
45
2
8
10
16
180
182
22

Please enter index to delete from: The index position you specified has been deleted.
The new array is: 
12
34
45
8
10
16
180
182
22

Now, please enter the index position to add to: 

Enter the number to add to the index: 
The number has been added at the specified index position.
The new array is: 
12
34
45
8
10
678
16
180
182
22