Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program is to be written in C++. There are 3 files main.cpp, arena.h and arena.cpp. Sample output is included in the screenshots. The bubble

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

The program is to be written in C++. There are 3 files main.cpp, arena.h and arena.cpp. Sample output is included in the screenshots. The bubble sort and insertion sort method screenshots are also attached.

- o monsters (2) - Notepad File Edit Format View Help KCARD Blue-Eyes White Dragon 3000 2500 Dark Magician 2500 2100 Exodia The Forbidden One 5000 5000 Celtic Guardian 1400 1200 Copycat O O Time Wizard 500 400 Unix (LF) In 1, Col 1 100% 12:32 PM 4 Type here to search Et 9 e @ $ of ^ () ENG 2020-02-17 22 - x monsters (2) - Notepad File Edit Format View 400 Help Blue-Eyes White Dragon 3000 2500 Baby Dragon 1200 700 Kuriboh 300 200 Summoned Skull 2500 1200 Blue-Eyes White Dragon 3000 2500 Red-Eyes B. Dragon 2400 Unix (LF) In 1, Col 1 100% rue of ^ () ENG 12:32 PM O Type here to search 2020-02-17 22 - x monsters (2) - Notepad File Edit Format View Help Blue-Eyes White Dragon 3000 2500 Baby Dragon 1200 700 Kuriboh 300200 Summoned Skull 2500 1200 Blue-Eyes White Dragon 3000 2500 Red-Eyes B. Dragon 2400 200 Unix (LF) In 1, Col 1 100% 12:32 PM 4 Type here to search Et 9 e @ $ of ^ () ENG 2020-02-17 22 Write a program that, after a list of structures is read into an array from the file monsters.txt, does the following operations: 1. Prompts the user with which sorting algorithm (bubble sort algorithm or insertion sort algorithm) the array should be sorted a. bubble sort algorithm defined in bubble_sort_pseudocode.txt b. insertion sort algorithm defined in the CS115 Lab Webpage 2. Prompts the user for which feature (attack or defence) the array should be sorted 3. Sort the array and display it 4. Prompts the user for a value of the considered feature and return the position of a monster in the array a. If more than one monster has that value, you only have to show the position of only one of them b. You should use here the binary search procedure defined in the CS115 Lab Webpage TIER 1 90% marks BASE + Apply the Program Organization Principles: Separation Of Interface And Implementation Apply the Program Organization Principles: Separation Of Interface And Implementation TIER 2 100% marks BASE + TIER 1 + 1. Keep searching (MUST USE binary search procedure) for the given feature while the user wants to continue 2. If more than one monster has the given feature, display all of them bubble_sort_pseudocode (2) - Notepad File Edit Format View Help procedure bubbleSort(A : list of sortable items) n := length(A) repeat swapped = false for i:=1 to n - 1 inclusive do /* if this pair is out of order */ if A[i - 1] > A[i] then /* swap them and remember something changed */ swap(A[i - 1], A[i]) swapped := true end if end for until not swapped end procedure procedure insertionSort(A : list of sortable items) // Sorts a given array by insertion sort // Input: An array A[@,...,n-1] of n orderable elements // Output: Array A[0,...,n-1] sorted in ascending order for i:=1 to n - 1 inclusive do key := A[i] j :- i - 1 while j>e and A[j] > key then A[j+1] := A[j] j - j - 1 end while A[j+1] := key end for end procedure - 0 Untitled - Notepad File Edit Format View #include "arena.h" Help int main() card deck[SIZE_DECK]; printHeader(); getCards (deck); cout > THE CARDS: "; printCards (deck); // ADD YOUR CODE HERE return 0; Windows (CRLF) Ln 16, Col 2 100% 11:02 PM O Type here to search 3 gp ^ *) ENG 2020-02-16 22 - o Untitled - Notepad File Edit Format View #include "arena.h" Help // ADD BUBLE SORT ALGORITHM HERE // ADD INSERTION SORT ALGORITHM HERE // ADD BINARY SEARCH ALGORITHM HERE void printHeader() cout ", "","", "", "KATK>", "", "", "".}: Windows (CRLF) Ln 153, Col 2 O 100% 11:02 PM ol ^) ENG 2020-02-16 C Type here to search 22 - x Untitled - Notepad File Edit Format View Help string temp_string = "NOT FOUND"; string tags[] = {"", "","", "", "KATK>", "", "", "", }; string tag_end_name = ""; int index = 0; while( inData) getline( inData, temp_string); // FIND THE CARD int start_card = temp_string.find(tags[0]); if(start_card>-1) // FIND THE NAME int start_of_tag = temp_string.find(tags [2]); while(start_of_tag == -1) getline(inData, temp_string); start_of_tag = temp_string.find(tags[2]); // cout #include #include #include using namespace std; const int SIZE_DECK = 12; struct card string name; int atack; int defence; // ADD BUBLE SORT ALGORITHM PROTOTYPE HERE // ADD INSERTION SORT ALGORITHM PROTOTYPE HERE // ADD BINARY SEARCH ALGORITHM PROTOTYPE HERE void printHeader(); void getCards (card[]); string remove_tag(string, string[], int, int); void printCards (card[]); #endif Windows (CRLF) Ln 29, Col 7 100% ol ^1ENG 2020-02-16 11:07 PM O Type here to search 22 ***** .... YU-GI-0000000000OOOH! **************** **** >> THE CARDS: # 3 Blue-Eyes White Dragon ATK/3000 DEF/2500 # 2 Dark Magician ATK/2500 DEF/2100 1 Exodia The Forbidden One ATK/5000 DEF/5000 Celtic Guardian ATK/1400 DEE/1200 Copycat ATK/O DEF/0 Time Wizard ATK/500 DEF/400 19 # 7 Blue-Eyes White Dragon ATK/3000 DEE/2500 # B Baby Dragon A TK/1200 DEF/700 IL Kur boh ATK/300 DEF/200 #10 Summoned Skull ATK/2500 DEF/1200 11 L #11 Blue-Eyes White Dragon A TK/3000 DEF/2500 #12 Red-Eyes B. Dragon A TK/2400 DEF/200 L >> CHOOSE THE SORTING ALGORITHM: 1 - BUBBLE SORT ALGORITHM 2 - INSERTION SORT ALGORITHM ki >> SORT BY: 1 - ATK 2 - DEF ki >> BUBBLE SORT ALGORITHM SORTED BY ATK: 3/5 ATK/3000 DEF/2500 ATK/1200 DEF/700 ATK/300 DEF/200 #10 Summoned Skull ATK/2500 DEF/1200 #11 Blue-Eyes White Dragon ATK/3000 DEF/2500 #12 Red-Eyes B. Dragon ATK/2400 DEF/200 >> CHOOSE THE SORTING ALGORITHM: 1 - BUBBLE SORT ALGORITHM 2 - INSERTION SORT ALGORITHM ki >> SORT BY: 1 - ATK 2 - DEF ki >> BUBBLE SORT ALGORITHM SORTED BY ATK: # 1 Copycat ATK/O DEF/0 2 Kuriboh ATK/300 DEF/200 # 3 Time Wizard ATK/500 DEF/400 Baby Dragon ATK/1200 DEF/700 # 5 Celtic Guardian ATK/1400 DEF/1200 # 6 Red-Eyes B. Dragon ATK/2400 DEF/200 # 7 Summoned Skull ATK/2500 DEF/1200 # 8 Dark Magician ATK/2500 DEF/2100 # 9 Blue-Eyes White Dragon A TK/3000 DEF/2500 L #10 Blue-Eyes White Dragon ATK/3000 DEF/2500 II L #11 Blue-Eyes White Dragon ATK/3000 DEE/2500 #12 Exodia The Forbidden One A TK/5000 DEF/5000, T L ATK/2500 DEF/1200 TL ATK/2500 DEF/2100 T ATK/3000 DEF/2500 #10 Blue-Eyes White Dragon ATK/3000 DEF/2500 II L #11 Blue-Eyes White Dragon A TK/3000 DEF/2500 #12 | Exodia The Forbidden One ATK/5000 DEF/5000 L BEEBBE to IEEE >> ENTER THE ATK TO SEARCH: >> ATK 2500 IS FOUND AT POSITION(S) >>> #7 #8 **************** DO YOU WANT TO CONTINUE (Y/N) ******** KY >> ENTER THE ATK TO SEARCH: > NUMBER 55 DOES NOT EXIST AS ATK IN THE DECK ************* DO YOU WANT TO CONTINUE (Y/N) ******* Blue-Eyes White Dragon 3000 2500 Dark Magician 2500 2100 Exodia The Forbidden One 5000 5000 Celtic Guardian 1400 1200 Copycat O O Time Wizard 500 400 Unix (LF) In 1, Col 1 100% 12:32 PM 4 Type here to search Et 9 e @ $ of ^ () ENG 2020-02-17 22 - x monsters (2) - Notepad File Edit Format View 400 Help Blue-Eyes White Dragon 3000 2500 Baby Dragon 1200 700 Kuriboh 300 200 Summoned Skull 2500 1200 Blue-Eyes White Dragon 3000 2500 Red-Eyes B. Dragon 2400 Unix (LF) In 1, Col 1 100% rue of ^ () ENG 12:32 PM O Type here to search 2020-02-17 22 - x monsters (2) - Notepad File Edit Format View Help Blue-Eyes White Dragon 3000 2500 Baby Dragon 1200 700 Kuriboh 300200 Summoned Skull 2500 1200 Blue-Eyes White Dragon 3000 2500 Red-Eyes B. Dragon 2400 200 Unix (LF) In 1, Col 1 100% 12:32 PM 4 Type here to search Et 9 e @ $ of ^ () ENG 2020-02-17 22 Write a program that, after a list of structures is read into an array from the file monsters.txt, does the following operations: 1. Prompts the user with which sorting algorithm (bubble sort algorithm or insertion sort algorithm) the array should be sorted a. bubble sort algorithm defined in bubble_sort_pseudocode.txt b. insertion sort algorithm defined in the CS115 Lab Webpage 2. Prompts the user for which feature (attack or defence) the array should be sorted 3. Sort the array and display it 4. Prompts the user for a value of the considered feature and return the position of a monster in the array a. If more than one monster has that value, you only have to show the position of only one of them b. You should use here the binary search procedure defined in the CS115 Lab Webpage TIER 1 90% marks BASE + Apply the Program Organization Principles: Separation Of Interface And Implementation Apply the Program Organization Principles: Separation Of Interface And Implementation TIER 2 100% marks BASE + TIER 1 + 1. Keep searching (MUST USE binary search procedure) for the given feature while the user wants to continue 2. If more than one monster has the given feature, display all of them bubble_sort_pseudocode (2) - Notepad File Edit Format View Help procedure bubbleSort(A : list of sortable items) n := length(A) repeat swapped = false for i:=1 to n - 1 inclusive do /* if this pair is out of order */ if A[i - 1] > A[i] then /* swap them and remember something changed */ swap(A[i - 1], A[i]) swapped := true end if end for until not swapped end procedure procedure insertionSort(A : list of sortable items) // Sorts a given array by insertion sort // Input: An array A[@,...,n-1] of n orderable elements // Output: Array A[0,...,n-1] sorted in ascending order for i:=1 to n - 1 inclusive do key := A[i] j :- i - 1 while j>e and A[j] > key then A[j+1] := A[j] j - j - 1 end while A[j+1] := key end for end procedure - 0 Untitled - Notepad File Edit Format View #include "arena.h" Help int main() card deck[SIZE_DECK]; printHeader(); getCards (deck); cout > THE CARDS: "; printCards (deck); // ADD YOUR CODE HERE return 0; Windows (CRLF) Ln 16, Col 2 100% 11:02 PM O Type here to search 3 gp ^ *) ENG 2020-02-16 22 - o Untitled - Notepad File Edit Format View #include "arena.h" Help // ADD BUBLE SORT ALGORITHM HERE // ADD INSERTION SORT ALGORITHM HERE // ADD BINARY SEARCH ALGORITHM HERE void printHeader() cout ", "","", "", "KATK>", "", "", "".}: Windows (CRLF) Ln 153, Col 2 O 100% 11:02 PM ol ^) ENG 2020-02-16 C Type here to search 22 - x Untitled - Notepad File Edit Format View Help string temp_string = "NOT FOUND"; string tags[] = {"", "","", "", "KATK>", "", "", "", }; string tag_end_name = ""; int index = 0; while( inData) getline( inData, temp_string); // FIND THE CARD int start_card = temp_string.find(tags[0]); if(start_card>-1) // FIND THE NAME int start_of_tag = temp_string.find(tags [2]); while(start_of_tag == -1) getline(inData, temp_string); start_of_tag = temp_string.find(tags[2]); // cout #include #include #include using namespace std; const int SIZE_DECK = 12; struct card string name; int atack; int defence; // ADD BUBLE SORT ALGORITHM PROTOTYPE HERE // ADD INSERTION SORT ALGORITHM PROTOTYPE HERE // ADD BINARY SEARCH ALGORITHM PROTOTYPE HERE void printHeader(); void getCards (card[]); string remove_tag(string, string[], int, int); void printCards (card[]); #endif Windows (CRLF) Ln 29, Col 7 100% ol ^1ENG 2020-02-16 11:07 PM O Type here to search 22 ***** .... YU-GI-0000000000OOOH! **************** **** >> THE CARDS: # 3 Blue-Eyes White Dragon ATK/3000 DEF/2500 # 2 Dark Magician ATK/2500 DEF/2100 1 Exodia The Forbidden One ATK/5000 DEF/5000 Celtic Guardian ATK/1400 DEE/1200 Copycat ATK/O DEF/0 Time Wizard ATK/500 DEF/400 19 # 7 Blue-Eyes White Dragon ATK/3000 DEE/2500 # B Baby Dragon A TK/1200 DEF/700 IL Kur boh ATK/300 DEF/200 #10 Summoned Skull ATK/2500 DEF/1200 11 L #11 Blue-Eyes White Dragon A TK/3000 DEF/2500 #12 Red-Eyes B. Dragon A TK/2400 DEF/200 L >> CHOOSE THE SORTING ALGORITHM: 1 - BUBBLE SORT ALGORITHM 2 - INSERTION SORT ALGORITHM ki >> SORT BY: 1 - ATK 2 - DEF ki >> BUBBLE SORT ALGORITHM SORTED BY ATK: 3/5 ATK/3000 DEF/2500 ATK/1200 DEF/700 ATK/300 DEF/200 #10 Summoned Skull ATK/2500 DEF/1200 #11 Blue-Eyes White Dragon ATK/3000 DEF/2500 #12 Red-Eyes B. Dragon ATK/2400 DEF/200 >> CHOOSE THE SORTING ALGORITHM: 1 - BUBBLE SORT ALGORITHM 2 - INSERTION SORT ALGORITHM ki >> SORT BY: 1 - ATK 2 - DEF ki >> BUBBLE SORT ALGORITHM SORTED BY ATK: # 1 Copycat ATK/O DEF/0 2 Kuriboh ATK/300 DEF/200 # 3 Time Wizard ATK/500 DEF/400 Baby Dragon ATK/1200 DEF/700 # 5 Celtic Guardian ATK/1400 DEF/1200 # 6 Red-Eyes B. Dragon ATK/2400 DEF/200 # 7 Summoned Skull ATK/2500 DEF/1200 # 8 Dark Magician ATK/2500 DEF/2100 # 9 Blue-Eyes White Dragon A TK/3000 DEF/2500 L #10 Blue-Eyes White Dragon ATK/3000 DEF/2500 II L #11 Blue-Eyes White Dragon ATK/3000 DEE/2500 #12 Exodia The Forbidden One A TK/5000 DEF/5000, T L ATK/2500 DEF/1200 TL ATK/2500 DEF/2100 T ATK/3000 DEF/2500 #10 Blue-Eyes White Dragon ATK/3000 DEF/2500 II L #11 Blue-Eyes White Dragon A TK/3000 DEF/2500 #12 | Exodia The Forbidden One ATK/5000 DEF/5000 L BEEBBE to IEEE >> ENTER THE ATK TO SEARCH: >> ATK 2500 IS FOUND AT POSITION(S) >>> #7 #8 **************** DO YOU WANT TO CONTINUE (Y/N) ******** KY >> ENTER THE ATK TO SEARCH: > NUMBER 55 DOES NOT EXIST AS ATK IN THE DECK ************* DO YOU WANT TO CONTINUE (Y/N) *******

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

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

Explain the concept of shear force and bending moment in beams.

Answered: 1 week ago