联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codehelp

您当前位置:首页 >> Java程序Java程序

日期:2021-04-11 10:47

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) :

<author> <number of pages> <edition> <number of spells in book><br><title of spell> <success rate> <effect><br><title of spell> <success rate> <effect><br><title of spell> <success rate> <effect><br>...<br><title of second spellbook> <author> <number of pages> <edition> <number of spells in book><br><title of spell> <success rate> <effect><br><title of spell> <success rate> <effect><br><title of spell> <success rate> <effect><br><title of spell> <success rate> <effect><br>...<br><title of third spellbook> <author> <number of pages> <edition> <number of spells in book><br><title of spell> <success rate> <effect><br><title of spell> <success rate> <effect><br>Example Operation<br>The following snippet of text shows an example implementation of the spellbook program. Note that<br>this example does not illustrate all required behavior. You must read this entire document to ensure<br>that you meet all of the program requirements.<br>?<br>2021/4/7 Program 1<br>https://canvas.oregonstate.edu/courses/1810763/assignments/8376088 4/8<br>$ ./catalog_prog spellbooks.txt<br>Which option would you like to choose?<br>Sort spellbooks by number of pages (Press 1):<br>Group spells by their effect (Press 2):<br>Sort spellbooks by average success rate (Press 3):<br>Quit (Press 4):<br>1<br>How would you like the information displayed?<br>Print to screen (Press 1)<br>Print to file (Press 2)<br>1<br>Spells_for_Dummies 303<br>Wacky_Witch_Handbook 1344<br>Necronomicon 1890<br>Forbidden_Tome 1938<br>Enchiridion 2090<br>The_Uses_of_Excalibur 3322<br>Charming_Charms 4460<br>Dorian 50000<br>Which option would you like to choose?<br>Sort spellbooks by number of pages (Press 1):<br>Group spells by their effect (Press 2):<br>Sort spellbooks by average success rate (Press 3):<br>Quit (Press 4):<br>3<br>How would you like the information displayed?<br>Print to screen (Press 1)<br>Print to file (Press 2)<br>1<br><Note: This example output is only intended to illustrate the program operation. Your values will be diff<br>erent.><br>Wacky_Witch_Handbook 90.05<br>The_Uses_of_Excalibur 87.9<br>Forbidden_Tome 76.8<br>Necronomicon 72.34<br>Enchiridion 51.2<br>Dorian 48.64<br>Charming_Charms 37.8<br>Spells_for_Dummies 29.74<br>Which option would you like to choose?<br>Sort spellbooks by number of pages (Press 1):<br>Group spells by their effect (Press 2):<br>Sort spellbooks by average success rate (Press 3):<br>Quit (Press 4):<br>3<br>How would you like the information displayed?<br>Print to screen (Press 1)<br>Print to file (Press 2)<br>2<br>Please provide desired filename: success_rate_list.txt<br>Appended requested information to file.<br>Which option would you like to choose?<br>Sort spellbooks by number of pages (Press 1):<br>?<br>2021/4/7 Program 1<br>https://canvas.oregonstate.edu/courses/1810763/assignments/8376088 5/8<br>Group spells by their effect (Press 2):<br>Sort spellbooks by average success rate (Press 3):<br>Quit (Press 4):<br>2<br>How would you like the information displayed?<br>Print to screen (Press 1)<br>Print to file (Press 2)<br>1<br>bubble Bubble_Beam<br>bubble Exploratory_Maneuver<br>memory_loss Space_Out<br>memory_loss Preliminary_Black_out<br>memory_loss Wacky_Dreams<br>fire Blasto_Strike<br>fire Beginning_Blast<br>poison Cthulhu_Venom<br>death Deathrock<br>death Nightmare<br>death Deadly_Details<br>Which option would you like to choose?<br>Sort spellbooks by number of pages (Press 1):<br>Group spells by their effect (Press 2):<br>Sort spellbooks by average success rate (Press 3):<br>Quit (Press 4):<br>4<br>Programming Style/Comments<br>In your implementation, make sure that you include a program header. Also ensure that you use<br>proper indentation/spacing and include comments! Below is an example header to include. Make<br>sure you review the style guidelines<br>(https://canvas.oregonstate.edu/courses/1810763/files/85698962/download?download_frd=1) for this<br>class, and begin trying to follow them, i.e. don’t align everything on the left or put everything on one<br>line!<br>/******************************************************<br>** Program: catalog.cpp<br>** Author:<br>** Date:<br>** Description:<br>** Input:<br>** Output:<br>******************************************************/<br>When you compile your code, it is acceptable to use C++11 functionality in your program. In order to<br>support this, change your Makefile to include the proper flag.<br>For example, consider the following approach (note the inclusion of -std=c++11):<br>g++ -std=c++11 //other flags and parameters<br>?<br>2021/4/7 Program 1<br>https://canvas.oregonstate.edu/courses/1810763/assignments/8376088 6/8<br>Magician Spellbook Catalog<br>In order to submit your homework assignment, you must create a tarred archive that contains your .h,<br>.cpp, and Makefile files. This tar file will be submitted to Canvas. In order to create the tar file, use the<br>following command:<br>tar –cvf assign1.tar catalog.h catalog.cpp prog.cpp Makefile<br>Note that you are expected to modularize your code into a header file (.h), an implementation file<br>(.cpp), and a driver file (.cpp).<br>You do not need to submit the txt files. The TA’s will have their own for grading.<br>Grading<br>You are required to meet with a TA within two weeks of the assignment due date to demo and<br>receive a grade. You can schedule a demo with a TA online using the link provided on the TAs page.<br>You must use your OSU email to schedule (for FERPA reasons), or your appointment will be<br>cancelled.<br>Programming assignments that do not compile and run on the OSU ENGR servers will receive<br>a grade of zero, with no exceptions.<br>?<br>2021/4/7 Program 1<br>https://canvas.oregonstate.edu/courses/1810763/assignments/8376088 7/8<br>Criteria Ratings Pts<br>12 pts<br>10 pts<br>7 pts<br>6 pts<br>3 pts<br>3 pts<br>8 pts<br>4 pts<br>10 pts<br>6 pts<br>Program Header / Good indentation & Use of whitespace / Function Documentation<br>At a minimum, header should contain author's name (2pts) and a description of the<br>program. (2pts)<br>Is code easy for the TA to read? Conditional blocks of code should always be indented.<br>(5pts) Every function contains it's own initial block comment (or multiple lines of comments<br>prior to the function definition) that provides the reader with an explanation of the function's<br>purpose (5pts). -1 pt for each function that is missing a header (up to 5 point penalty).<br>All functions designed in a modular fashion / No global variables<br>-5 pts if there are any global variables used in the code. If functions are exceptionally long<br>(greater than about 20 lines of actual code) this is a potential indication of poor modularity.<br>-3 pts for each function that the TA concludes is poorly modularized.<br>Command Line Functionality<br>(3 pts) Program displays error and terminates gracefully if exactly one command line<br>parameter is not provided. (4pts) Program displays error and terminates gracefully if a nonexistent<br>file is specified.<br>Struct Usage<br>Code defines/uses the spellbook and spell structs exactly as specified. -3 pts for any<br>incorrect struct. It's okay if the code uses additional structs for other purposes.<br>Memory Cleanup<br>The Valgrind LEAK SUMMARY should report: "definitely lost: 0 bytes in 0 blocks". Each<br>"new" operation should have a corresponding delete operation.<br>Program Functionality<br>Program does not crash during testing (e.g. segmentation fault or similar abrupt halts)<br>Function prototypes<br>The following function prototypes are used (exactly as shown) and included in a .h file.<br>-2pts for any function that doesn't match.<br>spellbook * create_spellbooks(int); void get_spellbook_data(spellbook *, int, ifstream &);<br>spell * create_spells(int); void get_spell_data(spell *, int, ifstream &);<br>Correct TAR file<br>Program was submitted as a single TAR file that contains a working Makefile, an<br>application .cpp file, a header .h file, and an implementation .cpp file. Exact filenames do<br>not matter for the source code.<br>Dynamic arrays of structs<br>Dynamically allocated arrays of structs are used for the spellbooks.<br>Sort spellbooks by # pages<br>Program sorts and displays the spellbooks by number of pages.<br>?<br>2021/4/7 Program 1<br>https://canvas.oregonstate.edu/courses/1810763/assignments/8376088 8/8<br>Total Points: 90<br>Criteria Ratings Pts<br>6 pts<br>6 pts<br>6 pts<br>3 pts<br>Group spells by effect<br>Program displays spells in groups (bubble, memory_loss, fire, poison, death)<br>Display spellbooks (sorted by average success rate)<br>Program sorts spellbooks by the average success rate of the spells contained within. The<br>sorted list is displayed on screen.<br>Program writes requested output to file<br>The user is able to request that sorted output be redirected to a user-specified filename.<br>The correct information is appended to that particular file.<br>Program repeats<br>Program repeats until the user chooses to exit.<br>?<br><br></p> <div class="dy">【<a href="#top" target="_self">返回顶部</a>】【<a href="#" onclick="window.print();">打印本稿</a>】 <a href="javascript:window.close()">【关闭本页】</a> </div> </div> <div class="xgwz"> <h4> 相关文章 </h4> <div class="syp"><strong>【上一篇】:</strong><a href="/contents/9/4557.html">C++程序调试、辅导C++编程设计、讲解MCD4720程序 辅导留学生 Statistics统...</a></div> <div class="syp"><strong>【下一篇】:</strong><a href="/contents/9/4557.html">C++程序调试、辅导C++编程设计、讲解MCD4720程序 辅导留学生 Statistics统...</a></div> </div> </div> </div> <div id="bottom"> <h4> </h4> <p>版权所有:留学生编程辅导网 2021,All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com <br/> 免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 <span style="display:none"> <span> </div> </body> </html> <script type="text/javascript" language="javascript">document.ondblclick=function(x){location.href = '/sitefiles/services/cms/utils.aspx?type=StlTrigger&publishmentSystemID=2&channelID=9&contentID=4556&isRedirect=true';}</script> <!-- T_系统内容模板.html(内容模板) -->