Reference no: EM132356514
Question
· Define a function called printMenu that prints the following choices :
o List all (L)
o Add (A)
o Number of books (N)
o Remove (R)
o Insert (I)
o Quit (Q)
· Define a function called printList that takes in a list as a parameter and prints the entries in the list one entry per line. If the list is empty, have the program print «No titles in the list »
· In the program do the following :
1. Create a list called readingList with two books : « Catch 22 » and « Time Machine »
2. Print a greeting message to the user
3. Call the printMenu function above to display the menu
4. Get user's choice.
5. Do the following according to user input :
o If the user chooses «L » or « l », call the printList function with readingList as the argument and go back to step 3.
o If the user chooses « A » or « a », ask the user the title of the book, add it to the end of the readingList and go back to step 3.
o If the user chooses « N » or « n », print the number of books in readingList and go back to step 3.
o If the user chooses « R » or « r », the program asks the user for a book title ; and removes it from the list if it is in the list. If it is not in the list, then the program says «The given book title is not in the reading list ».
o If the user chooses « I » or « i », the program asks the user for a book title. If the title is in the list, it says « The title is already in the list », otherwise, it asks for the index to insert the title at. If the index is invalid (lees than zero or greater than the length of the list), then the program says « Invalid index. Enter index again ». It continues this process until the user enters a valid index. Once the user enters a valid index, it inserts the title at the given index.
o If the user chooses « Q » or « q », print « Bye » and go to step 6.
o If the user chooses anyhting else, tell the user to enter their choice again and go back to step 3.
6. Print « End of program » on the screen