Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help fixing and finishing the following program in c++, thank you. I posted another question with all the program details and example outputs.

I need help fixing and finishing the following program in c++, thank you.

I posted another question with all the program details and example outputs. You should be able to find it by searching Magical Creatures Zookeeper.

#include

#include

#include

#include

#include

#include

#include

using namespace std;

struct Creatures

{

string name[50];

string description[50];

float avgLength[50];

float avgHeight[50];

string location[50];

char dangerous[50];

//doublecost = 0;

}Cost;

struct Cost

{

float numHours[50];

double costPerHour[50];

float foodCost[50];

float supplyCost[50];

};

void enterCreatures(struct Creatures, struct Cost);

void printCreatures();

void printStatistics();

void saveCreaturesToFile();

const int Num_Max_Creatures[100] = {0};

int Num_Creatures[x]=0

double COST[x] = {0};

int x=0;

int main()

{

struct Creatures c;

struct Cost C;

bool goAgain = true;

//booladdAnother= true;

int choice;

char answer;

cout << "Welcome to the Magical Creature Zoo Management Program! ";

while (goAgain == true)

{

Main_Menu:

cout << "What would you like to do?" << endl;

cout << "\t1. Enter new magical creatures or load from file." << endl;

cout << "\t2. Print all creatures." << endl;

cout << "\t3. Print statistics on creature cost." << endl;

cout << "\t4. End Program." << endl;

cout << "\tEnter 1,2,3 or 4." << endl;

cout << "Choice: ";

cin >> choice;

cout << endl;

if (choice == 1)

{

enterCreatures(c,C);

}

else if (choice == 2)

{

printCreatures();

}

else if (choice == 3)

{

printStatistics();

}

else if (choice == 4)

{

saveCreaturesToFile();

cout << "Thanks for using the Magical Creature Zoo Management Program!" << endl << endl;

goAgain = false;

}

else

{

cout << "You did not enter a valid choice." << endl;

cout << "Please enter 1,2,3 or 4." << endl << endl;

}

}

system("PAUSE");

return 0;

}

void enterCreatures(struct Creatures, struct Cost)

{

double COST[x] = {0};

bool addAnother = true;

struct Creatures creatureInfo;

struct Cost a;

int x =0;

int Number = 0; // Number = number of creatures in zoo

int choice;

char temp;

fstream file;

char fileName[26];

cout << "What do you want to do?" << endl;

cout << "\t1. Load my creatures from a file." << endl;

cout << "\t2. Enter one creature manually." << endl;

cout << "Choice: ";

cin >> choice;

cout << endl;

if (choice == 1)

{

cin.ignore();

cout << "What is the name of the file with your list of creatures? (ex: filename.txt)" << endl;

cout << "File name: ";

cin.getline(fileName,26);

cout << endl << endl;

file.open(fileName, ios::in);

if(!file)

{

cout << fileName << " does not exist or is corrupt. Sorry. Can't load creatures. " << endl << endl;

//gotoMain_Menu;

}

else

{

cout << "All creatures from " << fileName << " have been added to the program." << endl << endl;

//gotoMain_Menu;

}

}

while (addAnother == true)

{

if (choice == 2)

{

cout << endl << endl;

cin.ignore();

cout << "Name: ";

getline(cin,creatureInfo.name[x]);

cout << endl << endl;

cout << "Description: ";

getline(cin,creatureInfo.description[x]);

cout << endl << endl;

cout << "Average length (in feet): ";

cin >> creatureInfo.avgLength[x];

cout << endl << endl;

cout << "Average height (in feet): ";

cin >> creatureInfo.avgHeight[x];

cout << endl << endl;

cout << "Location: ";

cin.ignore();

getline(cin,creatureInfo.location[x]);

cout << endl << endl;

cout << "Is it a dangerous creature? (y or n): ";

//getline(cin,creatureInfo.dangerous[x]);

cin >> creatureInfo.dangerous[x];

cout << endl << endl;

cout << "How many hours do you spend caring for the " <

cout << "Number of hours: ";

cin >> a.numHours[x];

cout << endl << endl;

cout << "What is the cost per hour for caring for the " <

cout << "Cost per hour: ";

cin >> a.costPerHour[x];

cout << endl << endl;

cout << "How much money do you spend on food for the " <

cout << "Food cost: ";

cin >> a.foodCost[x];

cout << endl << endl;

cout << "How much money do you spend on grooming and medical supplies for the " <

cout << "Supply Cost: ";

cin >> a.supplyCost[x];

cout << endl;

Number ++ ;

x++;

COST[x] = a.numHours[x] * a.costPerHour[x] + a.foodCost[x] + a.supplyCost[x];

cout << " Would you like to add another creature, y or n? " ;

cin >> temp;

cout << endl << endl;

if(temp == 'y'){

addAnother = true;

}

else {

addAnother = false;

}

//??

//cout<< endl;

//gotoMain_Menu;

}

}

}

// choice 2

void printCreatures(Number,Num_Creatures[x])

{

if ( Number > 0 && Number < 101){

//printcreatures

ifstream infile1;

infile1.open("my_creatures.txt");

if (infile1.fail())

{

cout << "File failed to open./n";

exit(1);

}

cout << infile1;

infile1.close();

cout << endl;

}

else {

cout << "THERE ARE NO CREATURES AT YOUR ZOO!";

}

}

// choice 3

void printStatistics(Number,Num_Creatures[x])

{

cout << "COST OF EACH CREATURE FOR ONE WEEK:" << endl << endl;

cout << "CREATURE COST" << endl;

cout <

cout << " $ "; << endl;

cout << COST[x];

cout << endl;

}

// choice 4

void saveCreaturesToFile(Number,Num_Creatures[x])

{

char answer;

bool goAgain = false;

cout << "Would you like to save your creature list to a file? (y or n) " ;

cin >> answer;

if ( answer == 'y' ) {

//saveCreaturesToFile();

cout << "What is the name of the file you want to save your creatures to?" << endl;

cout << "FILENAME: "

cin << Filename;

// open file

// send creature data to file

// close file

cout << endl;

cout << "Your creatures were successfully saved to the my_creatures.txt file.";

cout << endl << endl;

cout << "GOODBYE!" << endl << endl;

goAgain = false;

}

else if ( answer == 'n' ) {

cout << endl << endl;

cout << "GOODBYE!" << endl << endl;

goAgain = false;

}

else {

cout << "Choose y or n to continue.";

//gotoSave_Creature;

}

}

float convertToFloat (string s)

{

istringstream i(s);

float x;

if (!(i >> x))

x = 0;

return x;

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

More Books

Students also viewed these Databases questions