Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem Statement: The great wizard school of Pogwarts has been adding a lot of new spellbooks to their library lately. As a result of all
Problem Statement: The great wizard school of Pogwarts has been adding a lot of new spellbooks to their library lately. As a result of all the new literature, some mischievous students have been learning spells that are dangerous. In addition, it has become increasingly difficult for the staff to find specific spells they want to teach in class. In order to alleviate these issues, the school administration has hired you to create a spellbook catalog program that will allow for access restriction and make searching for spellbooks easier. To simplify your task, the school has provided you with their spellbook and wizard profile information. These come in the form of two textfiles: wizards.txt and spellbooks. txt. (NOTE: The two filenames provided from the user inputs should not be hardcoded in your program!) The spellbooks .txt file contains a list of Pogwarts's spellbooks and their included spells. This file will give you the spellbook and spell information that your program will organize and display. The wi zards .txt file contains a listing of all wizards associated with Pogwarts. This file will give your program the information needed to control which spellbooks users can access. Requirements: 1. User inputs: When starting the program, the user will be prompted for two inputs. The first input will be the name of the file that holds the information about the wizards. The second input will be the name of the 1 file that contains the information about spellbooks and included spells. If the user does not provide two names of existing files, the program should print out an error message and quit. 2. Wizard Login: Before the user can get information from the program, they must login. You must prompt the user for an ID and password. The ID of the must be all ints. If it isn't, you must re-prompt the user for an ID that is only ints. You will then prompt the user for the password. The password will be a string that could contain any number of characters and numbers. You do not need to do any error handling on the password. You will then need to check this information against the wizard_info.txt (or the equivalent) file contents to determine which wizard is logging in. If there is no match, you must reprompt for both username and password again. If the user fails to login after three attempts, you must provide an error message and quit out of the program. (Note: If the user provides an ID that is not all integers that should not count as an error towards the three attempts that they have to login). After a user logs in, you must display the corresponding name, ID, school position, and beard length. 3. Searching and Printing: Once the user has logged in, they should be prompted with a list of different ways to display the spellbook after the search and spell information. Wizards with student status cannot view any spell that has an effect of death or poison and cannot view any spellbook with a spell that has an effect of death or poison. After the user has chosen an option, they should be asked if they want the information printed to the screen or written to a file. If they choose to write to a file, they should be prompted for a file name. If the file name already exists, the information should be appended to the file. If the file name does not exist, a file should be created, and the information should be written to the file. For your sorting, you CANNOT use the built-in sort function. 4. Available Options (after successful Iogin): - Search spellbook by its name: If the user picks this option, the user will then be prompted for a valid book name. If found, the book that has the exact same name will be displayed. Books with a spell that have an effect of death or poison should not be displayed when a student is logged in (i.e. hide those books from the results when a student is logged in). When they are displayed, you should print/write to file the entire information of the book and its spells. - Search spellbooks by number of pages: If the user picks this option, the user will then be prompted for a valid upper limit of number of pages. The books that have less or equal amount of pages will be displayed. Books with a spell that have an effect of death or poison should not be displayed when a student is logged in (i.e. hide those books from the results when a student is logged in). When they are displayed, you should print/write to file the title of the book and the number of pages it has. Search spells by effect: There are five types of spells: fire, bubble, memory_loss, death, poison. If the user picks this option, the user will then be prompted for a valid spell effect. The spells that have the chosen effect will be displayed. Remember that students cannot see spells that have the type death or poison. Once they are displayed, you should print/write to file the spell name and its effect. (Extra credit:) Sort by average success rate of spells: You must create a list of books sorted by the average success rate, in ascending order, of all the spells contained within the book. Once calculated, you should print/write to file the title of each applicable book and the corresponding 2 average success rate. Books with a spell that have an effect of death or poison should not be displayed when a student is logged in (i.e. hide those books from the results when a student is logged in). - Quit: The program will exit. 5. Your program should continue sorting and printing/writing until the user chooses to quit. Required Structs: The following structs are required in your program. They will help organize the information that will be read in (or derived) from the files. You cannot modify, add, or take away any part of the struct. 1. The wizard struct will be used when you read in entries from the wizard.txt (or equivalent) file. There are three options for position_title: "Headmaster", "Teacher", or "Student". struct wizard \{ string name; int id; string password; string position_title; float beard_length; \}; 2. The spellbook struct will be used to hold information from the spellbooks .txt file. This struct holds information about a spellbook. struct Spellbook \{ string title; string author; int num_pages; int edition; int num_spells; float avg_success_rate; struct Spell *s; ;; 3. The spell struct will also be used to read in information from the spellbooks .txt file. This struct holds information about a spell. There are five options for effect: "fire", "poison", "bubbles", "death", or "memory_loss". struct Spell \{ string name; float success_rate; string effect; ;; Required Input File Format: 1. Your program must accommodate the file formats as specified in this section. The wi zards .txt file will have the following pattern: An example wizards.txt file is provided here . 2. The spellbooks .txt file has a slightly different structure. The file information will be provided in sets (corresponding to each spellbook). Each spellbook will be accompanied by a listing of the spells inside. The spellbooks . txt file will have the following pattern: An example spellbooks.txt file is provided here Required files: You are expected to modularize your code into a header file (.h), an implementation file (.cpp), and a driver file (.cpp). 1. cata logh : This header file contains all struct declarations and function prototypes 2. catalog.cpp: This implementation file contains all function definitions 3. run_wizard. cpp: This driver file contains the main function 4. A Makefile is required Example Operation The following snippet of text shows an example implementation of the spellbook program. Note that this example does not illustrate all required behavior. You must read this entire document to ensure that you meet all of the program requirements. (User inputs are highlighted) $./catalog prog Enter the wizard info file name: wizards.txt Enter the spellbook info file name: spellbooks.txt Please enter your id: 123456 Please enter your password: gr\#ywiz Incorrect id or password Please enter your id: 123456 Please enter your password: gr 3 ywiz Welcome Gandalf ID: 123456 Status: Teacher Beard Length: 9001 Which option would you like to choose? 1. Search spellbook by its name 2. Search spellbooks by number of pages 3. Search spells by their effect 4. Quit Your Choice: 2 How would you like the information displayed? 1. Print to screen (Press 1) 2. Print to file (Press 2) Your Choice: 1 Enter the name of the upper limit: 2000 Spells_for_Dummies 303 Wacky_Witch_Handbook 1344 Necronomicon 1890 Forbidden_Tome 1938 Which option would you like to choose? 1. Search spellbook by its name 2. Search spellbooks by number of pages 3. Search spells by their effect 4. Quit Your Choice: 1 How would you like the information displayed? 1. Print to screen (Press 1) 2. Print to file (Press 2) Your Choice: 2 Please provide desired filename: bookname.txt Enter the spellbook name: Necronomicon Appended requested information to file. Which option would you like to choose? 1. Search spellbook by its name 2. Search spellbooks by number of pages 3. Search spells by their effect 4. Quit Your Choice: 3 How would you like the information displayed? 1. Print to screen (Press 1) 2. Print to file (Press 2) Your Choice: 1 Enter the spell effect: fire fire Blasto_Strike fire Beginning_Blast Which option would you like to choose? 1. Search spellbook by its name 2. Search spellbooks by number of pages 3. Search spells by their effect 4. Quit Your Choice: 4 Bye ! Additional Implementation Requirements: - Your user interface must provide clear instructions for the user and information about the data being presented - Use of dynamic array is required. - Use of structs is required. - Your program must catch all required errors and recover from them. - You are not allowed to use libraries that are not introduced in class. - Your program should be properly decomposed into tasks and subtasks using functions, including main(). To help you with this, use the following: - Make each function do one thing and one thing only. - No more than 15 lines inside the curly braces of any function, including main(). Whitespace, variable declarations, single curly braces, vertical spacing, comments, and function headers do not count. - Functions over 15 lines need justification in comments. - Do not put multiple statements into one line. - No global variables allowed (those declared outside of many or any other function, global constants are allowed). - No goto function allowed - You must not have any memory leaks or memory errors - You program should not have any runtime error, e.g. segmentation fault - Make sure you follow the style guidelines, have a program header and function headers with appropriate comments, and be consistent
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