Tham khảo tài liệu 'c++ programming for games module i phần 6', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | int main Our main array pointer and a variable to keep track of the array size. int array 0 int arraySize 0 Boolean variable to let us know when the user wants to quit so that we can terminate the loop. bool done false while done Every loop cycle print the array. PrintArray array arraySize Print a menu giving the user a list of options. cout 1 Set Element 2 Resize Array 3 Quit Input the users selection. int selection 1 cin selection Some variables that will receive additional input depending on the users selection. int index -1 int value 0 int newSize 0 Find out what menu option the user selected. switch selection Case 1 Set Element case 1 Ask for the index of the element the user wants to set. cout Index cin index Make sure index is in array bounds. if index 0 index arraySize cout Bad Index endl else Ask the user to input the value the user wants to assign to element index . cout index cin value Set the value the user entered to the index the user specified. array index value 130 break Case 2 Resize Array case 2 Ask the user to enter the size of the new array. cout Size cin newSize Call the resize function. Recall that this function returns a pointer to the newly resized array. array ResizeArray array arraySize newSize Update the array size. arraySize newSize break Quit. default Cause the loop to terminate. done true break delete array array 0 Program Output NULL Array 1 Set Element 2 Resize Array 3 Quit 2 Size 4 -842150451 -842150451 -842150451 -842150451 1 Set Element 2 Resize Array 3 Quit 1 Index 3 3 4 -842150451 -842150451 -842150451 4 1 Set Element 2 Resize Array 3 Quit 1 Index 2 2 3 -842150451 -842150451 3 4 1 Set Element 2 Resize Array 3 Quit 1 Index 0 0 1 1 -842150451 3 4 1 Set Element 2 Resize Array 3 Quit 1 Index 1 1 2 1 2 3 4 1 Set Element 2 Resize Array 3 Quit 2 Size 7 1 2 3 4 -842150451 -842150451 -842150451 1 Set Element 2 Resize Array 3 Quit 1 131 Index 4 4 5 1 2 3 4 5 -842150451 -842150451 1 Set Element 2 Resize Array 3 Quit 2 Size 5 1 2 3 4 5