Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Having a bit of trouble of reading and printing out the given text file onto my C++ program so that the result output would look

Having a bit of trouble of reading and printing out the given text file onto my C++ program so that the result output would look like the example down below. How will I restructure the code so that I am able to read the name values within the text file as well as the numbers. I have also left my current code down below.

My Code:

#include #include #include #include using namespace std;

struct dimensions { double length; double width; double height; }; struct Fauna { int id; string texture; int color; double health; dimensions fauna_dimensions; bool hostile; };

struct character { int id; string first_name; string last_name; double health; dimensions character_dimens; };

struct structure { int struct_id; string structure_texture; dimensions structure_dimensions; };

void getFaunaData(ifstream& inf, Fauna list[], int length); void printFauna(Fauna list[], int length);

int main() { Fauna giant[10]; int numberOfElements_f = 10; ifstream input; ofstream output;

getFaunaData(input, giant, numberOfElements_f); printFauna(giant, numberOfElements_f);

return 0; }

void getFaunaData(ifstream& inf, Fauna list[], int length) { for (int i = 0; i > list[i].id >> list[i].texture >> list[i].color >> list[i].health >> list[i].fauna_dimensions.length >> list[i].fauna_dimensions.width >> list[i].fauna_dimensions.height >> list[i].hostile; }

void printFauna(Fauna list[], int length) { cout

for (int i = 0; i

Fauna.txt:

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

Sample Output:

image text in transcribed

ID TEXTURE COLOR HEALTH LENGTH WIDTH HEIGHT HOSTILE 10 1 le 0.3 0.4 0.2 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 1.5 0.1 0.1 0.1 0.3 3 0.2 0.3 0.1 0.08 16 1.1 0.9 0.4 0.3 0.9 12 0.2 0.85 0.1 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

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions