首页 > > 详细

辅导Program语言编程、data程序辅导、辅导C/C++编程辅导SPSS|辅导Web开发

Due Sunday by 11:59pm Points 90 Submitting a file upload File Types tar
Available until Apr 16 at 11:59pm
Start Assignment
The Magician Spellbook Catalog
Problem Statement
The great magic university of Fakebills has been adding a lot of new spellbooks to their library lately.
The school administration has hired you to create a spellbook catalog program that will make
searching for spellbooks easier.
To simplify your task, the school has provided you with their spellbook information. These come in the
form of a text file that file contains a list of Fakebill's spellbooks and their included spells, all of the
information that your program will display.
Requirements
Command Line Argument:
When starting the program, the user will provide one command line argument. The 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 the name of an existing file the program should print out an error
message and quit.
Sorting and Printing:
Once the program begins, the user should be prompted with a list of different ways to display the
spellbook and spell information. 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.
Available Options:
Sort spellbooks by number of pages: If the user picks this option the books must be sorted in
ascending order by number of pages. 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. The
spells with bubble 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.

2021/4/7 Program 1
https://canvas.oregonstate.edu/courses/1810763/assignments/8376088 2/8
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.
Quit: The program will exit.
Your program should continue sorting and printing/writing until the user chooses to quit. For the
sorting functionality, you can write your own sorting function, or consider using C++'s built in sort
function.
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.
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", "bubble", "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). Note2: You must write the dynamic
memory allocation functionality yourself (i.e. no using vectors).
This function will dynamically allocate an array of spellbooks (of the requested size):
spellbook* create_spellbooks(int);

2021/4/7 Program 1
https://canvas.oregonstate.edu/courses/1810763/assignments/8376088 3/8
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. A possible example prototype includes the following:
void delete_spellbook_data(spellbook*, int);
Required Input File Format
Your program must accommodate the file formats as specified in this section. The spellbooks.txt file
has the following 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, and an example can be found here
(https://canvas.oregonstate.edu/courses/1810763/files/85698756/download?download_frd=1) :

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!