Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Just need help in completing the second task in order to display the elements for the separate text files in order to get the sample

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

Just need help in completing the second task in order to display the elements for the separate text files in order to get the sample output below. I had constructed a C++ program, up to the second task; however, I had gotten an error message from the complier.

My Code:

#include #include #include #include using namespace std; void printFauna (); struct dimensions { double length; double width; double height; }; struct Fauna { int id; string texture; int color; double health; dimensions fauna_dimensions; bool hostile; int f_array[10]; };

struct character { int id; string first_name; string last_name; double health; dimensions character_dimens; int c_array[7]; };

struct structure { int struct_id; string structure_texture; dimensions structure_dimensions; int s_array[8]; }; int main() { cout

void printFauna () { string line; ifstream input ("fauna.txt"); Fauna.f_array = 0 while (input >> line) { ++Fauna.f_array; cout

}

Fauna.txt

10 0 rabbit brown 10 .3 .1 .1 0 1 rabbit brown 10 .4 .1 .1 0 2 rabbit grey 10 .2 .1 .1 0 3 deer brown 25 2 .3 .7 0 4 deer brown 25 1.5 3 .9 0 5 fox orange 16 1.1 .2 .4 0 6 fox orange 16 .9 .3 .3 0 7 rat black 9 .2 .1 .05 1 8 rat black 6 .1 .08 .05 1 9 pigeon grey 1 .03 .01 .02 0 Structures.txt: 
8 0 rock 4.0 6.2 3.9 1 rock 3.9 1.3 0.9 2 rock 15 12 8.0 3 tree 1.5 1.9 10.0 4 tree 1.4 1.6 9.8 5 flower .01 .01 .02 6 house 7 8 9 7 house 15 13 15 

Characters.txt:

8 0 rock 4.0 6.2 3.9 1 rock 3.9 1.3 0.9 2 rock 15 12 8.0 3 tree 1.5 1.9 10.0 4 tree 1.4 1.6 9.8 5 flower .01 .01 .02 6 house 7 8 9 7 house 15 13 15 

Sample Output:

image text in transcribed

Program Description: You have just started working in a video-game company. The designers are experimenting with different maps, which consist of various elements (characters, animals, rocks, trees, etc.). The various elements have been grouped in three separate files ("fauna.txt", "characters.txt", and "structures.txt"). The program allows the user, to load elements and their attributes from provided files, and print them on the screen for closer inspection before experimenting with the map. The elements belong to one of three categories. Fauna: 1. id (integer) - identifies the element 2. texture (string) - specifies the appearance of the element (rabbit, fox, etc.) 3. color (integer) 4. health (double) 5. Dimensions - length, width and height. All three values are doubles 6. Hostile (Boolean) - determines if the animal is hostile (1) or peaceful (0) Character: 1. Id 2. First name 3. Last name 4. Health (double) 5. Dimensions Structure: 1. ID 2. Texture 3. Dimensions Dimension 1. Length 2. Width 3. Height Task 1 While the element categories have many similarities in terms of attributes, each category has a different bundle of attributes. Create four structs, Structure, Character, Fauna, and Dimension (to be utilized be the first three structs). Each struct should have the attributes mentioned above. Task 2 Create three arrays with the following types: Fauna, Structure. Character, and populate them by reading the respective file. Then print the arrays, as they appear in the file. The first line in all three files, is a number indicating the number of elements in the file. Task 3 Calculate the average length, width and height of all elements in each category. Then display the average for metric for each category, in the following manner. Fauna Structures Characters Length Width Height Task 4 Create a function "PrintHealthRange" that prompts the user to insert a maximum and minimum value for a character's health attribute. Proceed to print all character's whose health falls in that range. The function must not allow the minimum value to be larger than the maximum. Task 5 Create a Menu function that allows the user to select which category of elements to print. The menu options should be the following: 0. Exit 1. Print Fauna 2. Print Characters 3. Print Structures 4. Print Averages 5. Print Health in Range The main() function should only contain the Menu() function, which must display the available options. The program must only terminate upon the user's command. The rest of the functionality should be invoked through functions from within Menu). Sample output of Menu: Menu Print Fauna: Print Characters: Print Structures: Print Averages: Print Characters with Health in range: Exit: HNmin Action: ID TEXTURE COLOR HEALTH LENGTH WIDTH HEIGHT HOSTILE O le 0.1 0.1 0.1 0.7 rabbit rabbit rabbit deer deer fox fox rat rat brown brown grey brown brown orange orange black black 0.3 0.4 0.2 2 1.5 1.1 0.9 0.2 0.1 0.1 0.1 0.1 0.3 3 0.2 0.3 0.1 0.08 0.9 0.4 0.3 0.05 0.05 Program Description: You have just started working in a video-game company. The designers are experimenting with different maps, which consist of various elements (characters, animals, rocks, trees, etc.). The various elements have been grouped in three separate files ("fauna.txt", "characters.txt", and "structures.txt"). The program allows the user, to load elements and their attributes from provided files, and print them on the screen for closer inspection before experimenting with the map. The elements belong to one of three categories. Fauna: 1. id (integer) - identifies the element 2. texture (string) - specifies the appearance of the element (rabbit, fox, etc.) 3. color (integer) 4. health (double) 5. Dimensions - length, width and height. All three values are doubles 6. Hostile (Boolean) - determines if the animal is hostile (1) or peaceful (0) Character: 1. Id 2. First name 3. Last name 4. Health (double) 5. Dimensions Structure: 1. ID 2. Texture 3. Dimensions Dimension 1. Length 2. Width 3. Height Task 1 While the element categories have many similarities in terms of attributes, each category has a different bundle of attributes. Create four structs, Structure, Character, Fauna, and Dimension (to be utilized be the first three structs). Each struct should have the attributes mentioned above. Task 2 Create three arrays with the following types: Fauna, Structure. Character, and populate them by reading the respective file. Then print the arrays, as they appear in the file. The first line in all three files, is a number indicating the number of elements in the file. Task 3 Calculate the average length, width and height of all elements in each category. Then display the average for metric for each category, in the following manner. Fauna Structures Characters Length Width Height Task 4 Create a function "PrintHealthRange" that prompts the user to insert a maximum and minimum value for a character's health attribute. Proceed to print all character's whose health falls in that range. The function must not allow the minimum value to be larger than the maximum. Task 5 Create a Menu function that allows the user to select which category of elements to print. The menu options should be the following: 0. Exit 1. Print Fauna 2. Print Characters 3. Print Structures 4. Print Averages 5. Print Health in Range The main() function should only contain the Menu() function, which must display the available options. The program must only terminate upon the user's command. The rest of the functionality should be invoked through functions from within Menu). Sample output of Menu: Menu Print Fauna: Print Characters: Print Structures: Print Averages: Print Characters with Health in range: Exit: HNmin Action: ID TEXTURE COLOR HEALTH LENGTH WIDTH HEIGHT HOSTILE O le 0.1 0.1 0.1 0.7 rabbit rabbit rabbit deer deer fox fox rat rat brown brown grey brown brown orange orange black black 0.3 0.4 0.2 2 1.5 1.1 0.9 0.2 0.1 0.1 0.1 0.1 0.3 3 0.2 0.3 0.1 0.08 0.9 0.4 0.3 0.05 0.05

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

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

What factors infl uence our perceptions?

Answered: 1 week ago