Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Princess Guinevere, daughter of King Leodegrance, was a beautiful lady, the betrothed wife of the divine King Arthur. Rumors of her beauty had crossed the

Princess Guinevere, daughter of King Leodegrance, was a beautiful lady, the betrothed wife of the divine King Arthur. Rumors of her beauty had crossed the borders of England, reaching the ears of the ferocious dragon Bowser that reigned in the distant kingdom of Koopa. Bowser kidnaps Guinevere and brings her back to Koopa to force her to be his wife. At this point, Arthur had just defeated Cedric and ascended the throne of England. Hearing that his lover was kidnapped, King Arthur first wanted to go and rescue Guinevere. But leaving England at this time would mean once again the kingdom fell into chaos and chaos, the stability and peace that Arthur had worked so hard to build could very well be dissipated. The Knights of the Round Table, led by the knight Lancelot, asked King Arthur to continue stabilizing Englands interior. The rescue of Princess Guinevere will be handled by the Knights of the Round Table. Whether King Arthur will abandon his kingdom for love, whether the Knights of the Round Table can defeat the formidable dragon Bowser to rescue Princess Guinevere, all will be answered in this great exercise. In this assignment, you will be provided with a file containing input data, including information about the knight of the Round Table who rescued Guinevere and data about the journey to the kingdom of Koopa. The program will print to the screen the results of the Guinevere rescue process (more detailed in the section 4). Input data: Input data The programs input is contained in a file, the filename will be passed in when the program is run. This file will contain the following information: Information about the Knight of the Round Table, for example, is as follows: image text in transcribed

The itinerary to Koopa, for example, is as follows: image text in transcribed

Additional data file names, for example, are as follows: image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

Requirements:

Attached are 4 files main.cpp, main.h, knight.h, knight.cpp (The contents of 4 files are at the end of the post) You will only submit 2 files, knight.h and knight.cpp. Therefore, you are not allowed to modify the main.h file when testing the program Use the following command to compile: g++ -o main main.cpp knight.cpp -I . -std=c++11 Use the following command to run the program: ./main tc1 input The above command is used in the command prompt/terminal to compile the program. If use an IDE to run the program, should pay attention: add all the files to the IDE's project/workspace; change the IDE's compile command accordingly.

IDEs usually provide buttons for compiling (Build) and running the program (Run). When you click Build, the IDE will run a corresponding compile statement, normally, only main.cpp should be compiled. You need to find a way to configure the IDE to change the compilation command, namely: add the file knight.cpp, add the option -std=c++11, -I .

image text in transcribed

Contents of the code of the attached files:

main.cpp

#include "knight.h"

int main(int argc, char ** argv) {

string file_input(argv[1]);

int HP, level, remedy, maidenkiss, phoenixdown, rescue;

adventureToKoopa(file_input, HP, level, remedy, maidenkiss, phoenixdown, rescue);

return 0;

}

main.h

#ifndef __MAIN_H__

#define __MAIN_H__

#include

#include

#include

#include

#include

using namespace std;

#endif

knight.h

#ifndef __KNIGHT_H__

#define __KNIGHT_H__

#include "main.h"

void display(int HP, int level, int remedy, int maidenkiss, int phoenixdown, int rescue);

void adventureToKoopa(string file_input, int & HP, int & level, int & remedy, int & maidenkiss, int & phoenixdown, int & rescue);

#endif // __KNIGHT_H__

knight.cpp

#include "knight.h"

void display(int HP, int level, int remedy, int maidenkiss, int phoenixdown, int rescue) {

cout

}

void adventureToKoopa(string file_input, int & HP, int & level, int & remedy, int & maidenkiss, int & phoenixdown, int & rescue) {

cout

}

1722011 1291899 mush_ghost, , merlin_pack Thus the input file will consist of 3 lines. The first line will describe the information of the knight participating in the rescue of Guinevere in the following format: HPlevelremedy maidenkiss pheonixdown In which: - HP : knight's health stat, which is an integer between 1 and 999 . This value is also the knight's maximum health value MaxHP. - level: knight's level, is an integer between 1 and 10. - remedy: The number of Remedy potions the knight carries, is an integer with a value between 0 and 99 . - maidenkiss: The number of MaidenKiss potions the knight carries, is an integer with a value between 0 and 99 . - phoenixdown: The number of PhoenixDown tears a knight has, is an integer with a value between 0 and 99. The second line of the input file will describe the journey to Koopa. The trip to Koopa will include multiple events, each of which will be indexed starting at 1 . Each event will be represented by a numeric value called an event code. The corresponding meaning of each event is described in Table 1. The number of events is not fixed and can change depending on the test case. An event can happen multiple times. The third line of the input file will include the names of the files used in some events, the third line has the following format: file_mush_ghost,file_asclepius_pack,file_merlin_pack In which: - > is the file name used in the event 13. - > is the file name used in the event 19. - is the file name used in the event 18. Details of each event are given in Section 4. 3 file names are separated by 1 comma. If the journey to Koopa does not have an event to use the corresponding file, the filename can be an empty string, the knight doesn't need to care about this file name. The Knight of the Round Table participating in the rescue of the princess will have HP of 172, level 2, no Remedy, 1 MaidenKiss, and 1 PhoenixDown. On the way to Koopa, the knight will encounter the following events in turn: - Event 1: meet MadBear. - Event 2: meet Bandit. - Event 3: encounter another Bandit. - Event 4: meet Merlin the wizard. - Event 5: encounter the dragon Bowser. Also, the knight's MaxHP is also 172 (meaning the knight's HP will never exceed 172 during the journey). During events processing, the functions must update the appropriate values for the 5 stats HP, level, remedy, maidenkiss, phoenixdown. The rescue stat indicates whether the knight successfully rescued Princess Guinevere or not. rescue needs to be updated to the appropriate value after handling the events so that: rescue =1 if the journey is not over, rescue =1 if the journey is over and the rescue is successful, rescue =0 if the princess can't be rescued (e.g. knight's HP is less than 0 after fighting an opponent). Table 1: Events on the journey to Koopa With input as: The Knights of the Round Table met with only one event: the dragon Bowser surrendered and returned the princess. The stats remain the same and have the following values: - HP=172 - level =2 - remedy =0 - maidenkiss =1 - phoenixdown =0 - rescue =1 Depending on the events taking place along the way, the knight's HP, level, remedy, naidenkiss, and phoenixdown stats will be changed. Specifically, it is described as follows: 1. If the event has code 0 is encountered, the knight successfully rescues the princess, and the knight's journey ends immediately, although there are still events else occur after this event in the input data. Example 4.2 With input as 17220100105152199 The stat values will be: - HP=172 - level =2 - remedy =0 - maidenkiss =1 - phoenixdown =0 - rescue =1 If an event with codes 1 to 5 is encountered, the knight must engage the corresponding opponent. Each opponent will also have their own levelO level. If an opponent is encountered at the i event (the first event corresponds to i=1 ), the opponent's corresponding levelO will be calculated as follows: b=i%10levelO=i>6?(b>5?b:5):b If the knight's level is higher than the opponent's levelO, the knight wins. On victory, the knight's level will be increased by 1. However, if the knight's level is already 10 then level cannot be increased. If the knight's level is equal to levelO, the match is drawn, and the knight continues his journey but the level stats are not increased. If the knight's level is less than the opponent's levelO, the knight's HP will be recalculated as follows: damage=baseDamagelevelO10 HP=HPdamage Which, baseDamage will depend on the opponent, described in Table 2. Note that HP will always be an integer when calculated using the formula 3 and 4 . If HP is less than or equal to 0 after calculating with Equation 3 and the knight does not have the PhoenixDown phoenix tear, the knight will not be able to proceed to subsequent events, if any. Consequently, the program ends and the knight is not able to save the princess. In case the knight has PhoenixDown, this item will be automatically used (the phoenixdown will be reduced by 1), the knight's HP will be restored to the original MaxHP value and the knight continues his journey. Table 2: baseDamage stats of opponents With input as: [(]) In event 1 , the knight encounters the troll with levelO of 1 . Since the knight's level is currently 1, the match is drawn and the knight moves on to the next event. In event 2, the knight meets Bandit with levelo of 2. Since the knight's level is only 1 , the knight lost, and the knight's HP will be left at 1721.5210=142. At this point, since there are no more events to follow, the knight reaches Koopa and successfully rescues the princess, the stats are: - HP=142 - level =1 - remedy =0 - maidenkiss =1 - phoenixdown =0 - rescue =1 With input as: After a draw with LordLupin in event 1, the knight in event 2 fought Troll with levelO of 2 and lost due to having lower level, the knight's HP will therefore become 1529.5210=38=1 ), the knight will automatically use this potion and return to the normal state, which HP is not changed, then the stat's remedy is reduced by 1 . If the knight's HP drops to or below zero while the knight is in the tiny state, and the knight has PhoenixDown to use, the knight will be released from the tiny state, the knight's HP also will be restored to MaxHP. With input as: After a draw with Elf in event 1, the knight in event 2 fought Shaman with levelO of 2 and become tiny due to lower level, the knight's HP will then be reduced to 30. In event 3, the knight fought Troll with levelO of 3 and lost. The knight's HP is then reduced to 309.5310=2551. If HP=1, this stat is not changed. A Fibonacci number is a number in the Fibonacci sequence. This is an infinite sequence of natural numbers starting with 1 and 1 , then the next numbers will be the sum of the 2 preceding numbers. 7. If a knight picks up a ghost mushroom MushGhost (event code starts with 13 followed by the string ), the knight may encounter one or more ghost mushrooms varies based on the string. For example: - If the event code is 131, is 1 , the knight encounters the Type 1 ghost mush- room. - If the event code is 1342, is 42 , the knight encounters Type 4 ghost mushrooms and then Type 2 ghost mushrooms. Immediately after encountering each type of ghost mushroom, the knight's HP needs to be updated for matching before meeting the next ghost mushroom. If HP exceeds MaxHP, it also needs to be reinstalled HP with MaxHP before encountering the next ghost mushroom. If HP goes below 0 ; if potion phoenixdown >0 then potion will be automatically used, HP is restored to MaxHP, the knight will meet next ghost mushroom; if there are no more potions phoenixdown, the program will stop, the knight does not meet the next ghost mushroom. When encountering ghost mushrooms, it is necessary to manipulate a sequence of numbers stored in a file named >. The file name is on line 3 of the input file (See item description 3). The file has a 2-line format: line 1 contains a positive integer n2, line 2 contains n2 integers separated by a comma, n2b) where a and b are 2 consecutive values in the array. The mountain shape accepts the top of the mountain on the first or last element. Let mtx and mti be the value and position of the mountain peak, respectively. If the sequence has no mountain shape, then mtx=2,mti=3. HP=HP(mtx+mti) - Ghost mushroom type 3 (code 3): For each integer xi in the sequence in line 2 of the file, perform the transformation: xi=xiifxi is the file name used in the event 13. - > is the file name used in the event 19. - is the file name used in the event 18. Details of each event are given in Section 4. 3 file names are separated by 1 comma. If the journey to Koopa does not have an event to use the corresponding file, the filename can be an empty string, the knight doesn't need to care about this file name. The Knight of the Round Table participating in the rescue of the princess will have HP of 172, level 2, no Remedy, 1 MaidenKiss, and 1 PhoenixDown. On the way to Koopa, the knight will encounter the following events in turn: - Event 1: meet MadBear. - Event 2: meet Bandit. - Event 3: encounter another Bandit. - Event 4: meet Merlin the wizard. - Event 5: encounter the dragon Bowser. Also, the knight's MaxHP is also 172 (meaning the knight's HP will never exceed 172 during the journey). During events processing, the functions must update the appropriate values for the 5 stats HP, level, remedy, maidenkiss, phoenixdown. The rescue stat indicates whether the knight successfully rescued Princess Guinevere or not. rescue needs to be updated to the appropriate value after handling the events so that: rescue =1 if the journey is not over, rescue =1 if the journey is over and the rescue is successful, rescue =0 if the princess can't be rescued (e.g. knight's HP is less than 0 after fighting an opponent). Table 1: Events on the journey to Koopa With input as: The Knights of the Round Table met with only one event: the dragon Bowser surrendered and returned the princess. The stats remain the same and have the following values: - HP=172 - level =2 - remedy =0 - maidenkiss =1 - phoenixdown =0 - rescue =1 Depending on the events taking place along the way, the knight's HP, level, remedy, naidenkiss, and phoenixdown stats will be changed. Specifically, it is described as follows: 1. If the event has code 0 is encountered, the knight successfully rescues the princess, and the knight's journey ends immediately, although there are still events else occur after this event in the input data. Example 4.2 With input as 17220100105152199 The stat values will be: - HP=172 - level =2 - remedy =0 - maidenkiss =1 - phoenixdown =0 - rescue =1 If an event with codes 1 to 5 is encountered, the knight must engage the corresponding opponent. Each opponent will also have their own levelO level. If an opponent is encountered at the i event (the first event corresponds to i=1 ), the opponent's corresponding levelO will be calculated as follows: b=i%10levelO=i>6?(b>5?b:5):b If the knight's level is higher than the opponent's levelO, the knight wins. On victory, the knight's level will be increased by 1. However, if the knight's level is already 10 then level cannot be increased. If the knight's level is equal to levelO, the match is drawn, and the knight continues his journey but the level stats are not increased. If the knight's level is less than the opponent's levelO, the knight's HP will be recalculated as follows: damage=baseDamagelevelO10 HP=HPdamage Which, baseDamage will depend on the opponent, described in Table 2. Note that HP will always be an integer when calculated using the formula 3 and 4 . If HP is less than or equal to 0 after calculating with Equation 3 and the knight does not have the PhoenixDown phoenix tear, the knight will not be able to proceed to subsequent events, if any. Consequently, the program ends and the knight is not able to save the princess. In case the knight has PhoenixDown, this item will be automatically used (the phoenixdown will be reduced by 1), the knight's HP will be restored to the original MaxHP value and the knight continues his journey. Table 2: baseDamage stats of opponents With input as: [(]) In event 1 , the knight encounters the troll with levelO of 1 . Since the knight's level is currently 1, the match is drawn and the knight moves on to the next event. In event 2, the knight meets Bandit with levelo of 2. Since the knight's level is only 1 , the knight lost, and the knight's HP will be left at 1721.5210=142. At this point, since there are no more events to follow, the knight reaches Koopa and successfully rescues the princess, the stats are: - HP=142 - level =1 - remedy =0 - maidenkiss =1 - phoenixdown =0 - rescue =1 With input as: After a draw with LordLupin in event 1, the knight in event 2 fought Troll with levelO of 2 and lost due to having lower level, the knight's HP will therefore become 1529.5210=38=1 ), the knight will automatically use this potion and return to the normal state, which HP is not changed, then the stat's remedy is reduced by 1 . If the knight's HP drops to or below zero while the knight is in the tiny state, and the knight has PhoenixDown to use, the knight will be released from the tiny state, the knight's HP also will be restored to MaxHP. With input as: After a draw with Elf in event 1, the knight in event 2 fought Shaman with levelO of 2 and become tiny due to lower level, the knight's HP will then be reduced to 30. In event 3, the knight fought Troll with levelO of 3 and lost. The knight's HP is then reduced to 309.5310=2551. If HP=1, this stat is not changed. A Fibonacci number is a number in the Fibonacci sequence. This is an infinite sequence of natural numbers starting with 1 and 1 , then the next numbers will be the sum of the 2 preceding numbers. 7. If a knight picks up a ghost mushroom MushGhost (event code starts with 13 followed by the string ), the knight may encounter one or more ghost mushrooms varies based on the string. For example: - If the event code is 131, is 1 , the knight encounters the Type 1 ghost mush- room. - If the event code is 1342, is 42 , the knight encounters Type 4 ghost mushrooms and then Type 2 ghost mushrooms. Immediately after encountering each type of ghost mushroom, the knight's HP needs to be updated for matching before meeting the next ghost mushroom. If HP exceeds MaxHP, it also needs to be reinstalled HP with MaxHP before encountering the next ghost mushroom. If HP goes below 0 ; if potion phoenixdown >0 then potion will be automatically used, HP is restored to MaxHP, the knight will meet next ghost mushroom; if there are no more potions phoenixdown, the program will stop, the knight does not meet the next ghost mushroom. When encountering ghost mushrooms, it is necessary to manipulate a sequence of numbers stored in a file named >. The file name is on line 3 of the input file (See item description 3). The file has a 2-line format: line 1 contains a positive integer n2, line 2 contains n2 integers separated by a comma, n2b) where a and b are 2 consecutive values in the array. The mountain shape accepts the top of the mountain on the first or last element. Let mtx and mti be the value and position of the mountain peak, respectively. If the sequence has no mountain shape, then mtx=2,mti=3. HP=HP(mtx+mti) - Ghost mushroom type 3 (code 3): For each integer xi in the sequence in line 2 of the file, perform the transformation: xi=xiifxi

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logic In Databases International Workshop Lid 96 San Miniato Italy July 1 2 1996 Proceedings Lncs 1154

Authors: Dino Pedreschi ,Carlo Zaniolo

1st Edition

3540618147, 978-3540618140

More Books

Students also viewed these Databases questions