QuestionQuestion

The Wizard Spellbook Catalog
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 are provided on the command line and 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 wizards.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
Command Line Arguments:
When starting the program, the user will provide two command line arguments. The first command line argument will be the name of the file that holds the information about the wizards. The second command line argument will be the name of the 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. You can assume that the user always provides these two command line arguments in the correct order.
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 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
Sorting and Printing:
Once the user has logged in they should be prompted with a list of different ways to display the sorted spellbook 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.
Available Options (after successful login):
Sort spellbooks by number of pages: If the user picks this option the books must be sorted in ascending order by number of pages. 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). Once they are sorted, you should print/write to file the title of the book and the number of pages it has.
Sort spells by effect: There are five types of spells: fire, bubble, memory_loss, death, poison.
Remember that students cannot see spells that have the type death or poison. The spells with bubbles as the effect should be listed first, followed by memory_loss, fire, poison, and death. Once they are sorted, you should print/write to file the spell name and its effect.
Sort by average success rate of spells: You must create a list of books sorted by the average success rate 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 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.
Your program should continue sorting and printing/writing until the user chooses to quit.

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.
The wizard struct will be used when you read in entries from the wizard.txt 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;
};
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;
};
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 Functions:
You must implement the following functions in your program. You are not allowed to modify these required function declarations in any way. Note: it is acceptable if you choose to add additional functions (but you must still include the required functions).

This function will dynamically allocate an array of spellBooks (of the requested size):
spellbook * create_spellbooks(int);

This function will fill a spellbook struct with information that is read in from spellbooks.txt. Hint: “ifstream &” is a reference to a filestream object. You will need to create one and pass it into this function to read from the spellbooks.txt file.
void get_spellbook_data(spellbook *, int, ifstream &);
This function will dynamically allocate an array of spells (of the requested size):
spell * create_spells(int);
This function will fill a spell struct with information that is read in from spellbooks.txt.
void get_spell_data(spell *, int, ifstream &);
You need to implement a function that will delete all the memory that was dynamically allocated. You can choose the prototype. Possible examples include the following:
void delete_info(wizard **, int, spellbook **, int);
void delete_info(wizard **, spellbook **, int);

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/******************************************************
** Program: catalog.cpp
** Author:
** Date:
** Description:
** Input:
** Output:
******************************************************/

#include <fstream>
#include <iostream>
#include <string>
using namespace std;
#include "catalog.h"

/**
* This function will dynamically allocate an array of
* spellBooks (of the requested size):
* @param size
* @return
*/
spellbook * create_spellbooks(int size) {
    spellbook * book = (spellbook *) new spellbook[size];
    return book;
}

/**
* This function will fill a spellbook struct with information that
* is read in from spellbooks.txt. Hint: “ifstream&” is a reference to
* a filestream object. You will need to create one and pass
* it into this function to read from the spellbooks.txt file.
* @param book
* @param size
* @param stream
*/
void get_spellbook_data(spellbook * books, int size, ifstream & stream) {
    spellbook * book;
    for (int i = 0; i < size; i++) {
       book = books + i;
       stream >> book->title >> book->author
                >> book->num_pages >> book->edition
                >> book->num_spells;
       book->s = create_spells(book->num_spells);
       get_spell_data(book->s, book->num_spells, stream);
       float rate = 0;
       for (int j = 0; j < book->num_spells; j++) {
            rate += book->s[j].success_rate;
       }
       book->avg_success_rate = rate / book->num_spells;
    }
}

/**
* create an array of spell
* @param size size of the array
* @return array of spells
*/
spell * create_spells(int size) {
    spell * sp = new spell[size];
    return sp;
}

/**
* rerad spell from file
* @param spells array of speel
* @param size size of the array
* @param stream input stream
*/
void get_spell_data(spell * spells, int size, ifstream & stream) {
    spell * sp;
    for (int i = 0; i < size; i++) {
       sp = spells + i;
       stream >> sp->name >> sp->success_rate >> sp->effect;
    }
}

/**
* delete allocated memory
* @param warr array of wizard
* @param wsize size of the array
* @param barr array of book
* @param bsize size of the array
*/
void delete_info(wizard ** warr, int wsize, spellbook ** barr, int bsize) {
    if (*warr != 0) {
       delete [] (*warr);
    }
    if (*barr != 0) {
       spellbook * sp = *barr;
       spellbook * book;
       for (int i = 0; i < bsize; i++) {
            book = sp + i;
            delete [] book->s;
       }
       delete [] (*barr);
    }
}


//******************************************************
// Note: it is acceptable if you choose to add additional functions
// (but you must still include the required functions).
//******************************************************

/**
* read wizard from file
* @param path path to the file
* @param size size of the array
* @return the array
*/
wizard * readWizard(char * path, int &size...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$68.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Computer Science - Other Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats