Question
2D Arrays and C-type Strings Design, write, and test a program for the following. Function : This program reads in information about books and prints
2D Arrays and C-type Strings
Design, write, and test a program for the following.
Function: This program reads in information about books and prints out tables containing that information formatted in different ways. For each book, it reads in the title and authors name. It gives the user a choice of how the table should be ordered: by title or by author. It will print out the requested table, and then ask again for a choice. This should continue until the user enters the signal to quit.
Input: The input will be from the keyboard (standard input) and consists of two parts. The first part starts out with an integer giving the number of books to be input. This is followed by input of one line for each book: the line consists of the first and last name of the author followed by the title of the book. (See sample run below.) The second part of the input simply consists of the user entering one of the following letters: A, T, or Q. The letter A will mean that the table will be sorted by the authors last name, the letter T will mean it will be sorted by the title, and the letter Q will mean the program is to halt.
Output: After the information is entered the program should print out well-formatted tables showing information about each book. Depending on the users input, the data in the table will be sorted in different ways.
Sample run: (You may change the wording and format, but all information asked for should be present and easily read. The user input is in bold type.)
Welcome to CS library program.
Please enter the number of books: 2
For each book, please enter one line consisting the first and last names of the author follwoed by the title of the book.
Ernest Hemingway For Whom the Bell Tolls
Stephen Crane The Red Badge of Courage
The program will display all books sorted according to your choice.
Please enter your one letter choice as follows:
A: sort the books by the last names of the authors
T: sort the books by the titles
Q: quit this program
A
Crane, Stephen, The Red Badge of Courage
Hemingway, Ernest, For Whom the Bells Tolls
The program will display all books sorted according to your choice.
Please enter your one letter choice as follows:
A: sort the books by the last names of the authors
T: sort the books by the titles
Q: quit this program
T
For Whom the Bells Tolls, Hemingway, Ernest
The Red Badge of Courage, Crane, Stephen
The program will display all books sorted according to your choice.
Please enter your one letter choice as follows:
A: sort the books by the last names of the authors
T: sort the books by the titles
Q: quit this program
Programming requirements: For this and all subsequent programs, use functions! In particular, most, if not all, tasks identified in Level 0 of your pseudocode should be functions. The exception would be if the body of a function would consist of only one or two non-compound statements. For this assignment you are required to use arrays and functions and C-type strings, i.e. character arrays, and their standard functions. (This means you will need to include a header file
You should have at least the following arrays:
nameTitle - array of strings containing: lastName, firstName, title
titleName- array of strings containing: title, lastName, firstName
You should use at least the following C++(actually C) functions:
strcpy // to copy strings
strcat // to concatenate strings
strcmp // needs to be used in sorting
For a sorting algorithm, use insertion sort, selection sort, or quicksort, not bubble sort.
Assumptions: You may assume again that all entries are correct. You may further make assumptions about the lengths of names and titles if you wish; if you do, you need to document it. You may assume that all books have just one author and only the first and last names of the authors are entered
Testing: You should perform your own tests to make sure that each component of your program is working. At the end, run your program using the input as outlined in the file books.txt . If you like, it is possible to type in the input into a text file using Notepad, and then have your executable file act on it. If you like, you can also capture the output in a text file. To do this, open up a MS DOS window, and then type in
C:\WINDOWS:> FileName.exe < TextFileName.txt > OutFileName
where you can fill in the correct filenames for "FileName.exe", "TextFileName.txt" and "OutFileName". All file names should include the full path unless you are in the same directory (folder). You may need to rename the files to be 8 characters long.
book.txt
11
Ernest Hemingway For Whom the Bell Tolls
Stephen Crane The Red Badge of Courage
Samuel Clemens The Adventures of Huckelberry Finn
Joseph Heller Catch-22
William Faulkner The Sound and the Fury
Herman Melville Moby
Thomas Pynchon Gravity's Rainbow
Thomas Wolfe Look Homeward, Angel
Richard Wright Native Son
John Steinbeck Of Mice and Men
Toni Morrison Beloved
A
T
A
T
Q
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started