Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help correcting and finishing the following program given the following information. Hey, Hopefully you guys can help me out with this one its

I need help correcting and finishing the following program given the following information.

Hey, Hopefully you guys can help me out with this one its supper long but we have some time. We will be using C++ language on this prog,not Java.Hopefully there is enough info.

Thanks

Description:

Your assignment is to write a program for a Magical Creatures Zookeeper. The zoo can house up to 100 magical creatures. Information about each creature needs will be kept and manipulated in this program. The user should be able to load magical creature informationfrom any file he or she chooses, add creatures manually, delete a creature, print creature information to either a file or to the screen, or print a cost analysis of each creature and then the total cost to house and take care of these creatures.

PROGRAM SPECIFICATIONS

Structures: (define all structures in Prog5.h) You will need to create two structures. One is called Cost. Cost will have the following members:

The number of hours it takes to take care of a specific creature.

The cost (per hour) of taking care of this creature.

The cost of food to feed this creature for one week.

The cost of materials/supplies (grooming, medical) for this creature for one week

The second structure is called Creatures. Creatures will have the following members:

The name of the creature

The description of the creature

The average length of the creature (in feet)

The average height of the creature (in feet)

The location of the creature (example: its origin or where they are commonly found)

If the creature is dangerous (Boolean variable) Yes or No

A variable to hold the Cost structure members

There are four seperate files: prog5.cpp(main function file), prog5.h(header file), functions.cpp(functions file), and creatures.txt (textfile which I can do).

***DO NOT WORRY ABOUT THE SEPERATE FILES I CAN SEPERATE OR MAKE THEM ONCE THE PROGRAM IS FINISHED.***

The Main Function: (define main function in Prog5.cpp) You will need to create an array of 100 elements of the Creatures data type. You will also need to create a variable that will keep up with the current number of creatures.

The main menu function will display a menu of five options and will look similar to this:

What would you like to do?

1.Enter some Magical Creatures.

2.Delete a Magical Creature

3.List/Print Creatures.

4.Print Creature Costs.

5.End Program.

Enter 1, 2 , 3 , 4 ,or 5.

Choice:

Make sure you always validate all user choices in the whole program before proceeding to do what the user wants. Each menu choice will call a function that you will create. (I would use a do-while loop to keep the user in the menu until they choose 5, whichends the program).

If the user chooses option 1, then your program will call the enterCreatures function. If the user chooses option 2, then your program will call the deleteCreature function. If the user chooses option 3, then your program will call the printCreatures function.If the user chooses option 4, then your program will call the printStatistics function. If the user chooses option 5, then your program will ask the user if they wish to save their creature list to a file. If they choose yes, then your program should callthe saveCreaturesToFile function and then end. If they choose no, then your program should just end.

ALL OTHER FUNCTIONS SHOULD BE DEFINED IN functions.cpp

Main Menu Choice 1 : enterCreatures function

The enterCreatures() function takes two parameters: the number of creatures currently loaded in the Creatures array and the Creatures array. The function will return the new number of creatures. Before trying to add any creatures, this function should firstcheck to make sure the number of creatures isnt already 100. Because if it is, then your program should not add any creatures, but should instead tell the user that their zoo is at full capacity and that they are not able to add creatures. Then the functionshould end.

Otherwise, your program will display a menu asking the user if they would like to do one of the following:

1.Load my creatures from a file.

2.Enter one creature manually.

Validate the users choice.

Example Output:

----------------------------------------------------------------

What do you want to do?

1. Load my creatures from a file.

2. Enter one creature manually.

Choose 1 or 2.

---------------------------------------------------------

If the user chooses option 1, then ask the user what the name of the file is that they would like to load the creatures from. Then open their file. Check if the file could open before reading from it.

Read each creature from the file and place them in the Creatures array, making sure that you increment the number of creatures each time a creature is added. When you are reading from the file, everything read in will have to be read in as a string. Some ofthe Creature members are strings, so that wont be a problem. However, some of the Creature members are floats. So, this function will have to call the convertToFloat() function (provided later) in order to convert the string to a float and then placed inthe Creatures array. Then return the number of creatures at the end of the function.

If the user chooses option 2, then you will want to start a loop so that the user can add multiple creatures manually without returning to the main menu. Ask the user for the following: (make sure you place each bit of information in the correct place in theCreatures array)

NAME:

DESCRIPTION:

AVERAGE LENGTH (in feet):

AVERAGE HEIGHT (in feet):

LOCATION:

IS IT A DANGEROUS CREATURE? (y or n)

How many hours do you spend caring for the [insert creature name here]?

NUM HOURS:

What is the cost per hour for caring for the [insert creature name here]?

COST PER HOUR:

How much money do you spend on food for the [insert creature name here]?

FOOD COST:

How much money do you spend on grooming and medical supplies for the [insert creature name here]?

SUPPLY COST:

Then after the user fulfills choice 2, increment the number of creatures by one. Then, ask the user if they want to add another creature. If they do, then repeat this option. If not, then just return the number of creatures.

Main Menu Choice 2: deleteCreature function

The deleteCreature() function has two parameters: the current number of creatures in the Creatures array and the Creatures array. This function returns the new number of creatures.

First, this function will say The following is a list of all the creatures you take care of: and then it will say the name of each creature. Then, your program will ask the user What creature do you wish to remove? CREATURE NAME:

Your program should then read in the name and place it in a variable. Then, this function will call the moveArrayElements function, which will take care of removing the creature. The moveArrayElements function returns a Boolean value to tell if the creaturewas removed of not. Check to see if the creature was removed. If it was, then decrement the number of creatures and print out You have removed [insert creature name here]. Then return the new number of creatures.

Main Menu Choice 2 second function: moveArrayElements function

The moveArrayElements() function has the following parameters: a string with the name of the creature that the user wishes to remove, the current number of creatures in the Creature array, and the Creatures array. This function returns a Boolean variable thatis true if the creature was removed and false if it was not removed.

This function should first find the subscript number of the creature that needs to be removed. Once that is found, then you know there is a creature in the Creatures array by that name and that your program will be able to remove it. If your program cannotfind the creature in the array, then you return false from this function. Otherwise, this function should now overwrite the element with the creature to delete (x) with the next element in the array (x+1), moving each element after the deleted element to theleft. Then return true that the creature was found & removed.

Main Menu Choice 3: printCreatures function

The printCreatures() function is a void function and contains the following parameters: number of creatures currently in the Creatures array and the Creatures array. The printCreatures() function will first display a menu to the user containing the followingoptions:

Print Creatures to the Screen.

Print Creatures to a File.

Validate the users choice. If the user chooses option 1, then you will print out all the creatures in the Creatures array to the screen in the following formatAfter the user Chooses 3 in the main menu:

Example Output:

-----------------------------------------------------------------

What would you like to do?

1.Print Creatures to the screen.

2.Print Creatures to a file.

Choose 1 or 2.

Choice: 1

-------------------------------------------------------------------------------------------------------------

Creature 1:

Name: Jabba's Rancor

Description: Rancor is a giant with sharp teeth and claws, seen in Starwars 6 Returrn of the Jedi.

Length: 20 feet

Height: 25 feet

Location: Tantoine

Dangerous: Yes

Number of Hours to Care for the creature: 4

Cost per hour to care for the creature : $9.6

Cost to feed creature: $350

Grooming & Supplies: $300

--------------------------------------------------------------------------------------------

Creature 2:

Name: Ewok

Description: A small bear type creature, that weilds spears and rocks that lives on the moons of Endor

Length: 1 feet

Height: 2 feet

Location: Moons of Endor

Dangerous: no

Number of hours to care for the creature: 1

Cost per hour for the creature $ 10

Cost to feed creature $ 20

Grooming and Supplies: $11

--------------------------------------------------------------------------------

Notice that the description does word wrapping. In other words, each word is not split up they are kept together.

If the user selects option 2, then your program should ask the user what is the name of the file that they wish to print the creatures to. Then, open this file. You do not have to check for errors for this file because it probably will not yet exist. Then,write all the information to the file like you did to the screen if the user had chosen option.

Then, your program should write Your creatures have been written to [insert filename here].

Main Menu Choice 4: printStatistics function

The printStatistics() function is a void function and it contains two parameters: the current number of creatures in the Creatures array and the Creatures array. This function should print out the total cost of each creature in a table. To figure out the cost of a creature, use the formula:

Cost = numHours * costPerHour + foodCost + materialCost Then, this function should also keep a running total of the total cost of all the creatures. The table printed should look like thisafterchoosing4 in the main menu:

Example:

--------------------------------------------------------------------------

Cost of each creature for one week:

Creature Cost:

Rancor $ 659.60

Ewok $ 41.00

Total Cost $ 700.60

-----------------------------------------------------------------------------------

saveCreaturesToFile function

The saveCreaturesToFile() function is a void function and it contains two parameters: the current number of creatures in the Creatures array and the Creatures array. The function should ask the user what the name of the file that they wish to save their creaturesto. The function should then open that file and write out all the creature data in the following order:

Name

Description

Avg. Length

Avg. Height

Location

Dangerous

numHours

costPerHour

foodCost

MaterialCost

There should be no newlines or endlines in the file. All data should be separated by a pound sign (#) instead of a space.

After printing all data from the Creatures array to the file, this function should print out a message to standard output saying Your creatures were successfully saved to the [insert filename here] file.

convertToFloat function

The convertToFloat() function will need to be used when reading data from a file and inputting the data into the Creatures array (so this function will be called from the enterCreatures function). I am providing this function for you. You just need to insertit into your program so you can use it.

float convertToFloat(string s)

{

istringstream i(s);

float x;

if(!(i >> x))

x=0;

return x;

}

You will need to insert the following header file to use the convertToFloat function:

#include < sstream >

Hope you can help.

#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;

}

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

Advances In Spatial And Temporal Databases 8th International Symposium Sstd 2003 Santorini Island Greece July 2003 Proceedings Lncs 2750

Authors: Thanasis Hadzilacos ,Yannis Manolopoulos ,John F. Roddick ,Yannis Theodoridis

2003rd Edition

3540405356, 978-3540405351

More Books

Students also viewed these Databases questions

Question

Describe the project budgeting process.

Answered: 1 week ago

Question

Explain Coulomb's law with an example

Answered: 1 week ago

Question

What is operating system?

Answered: 1 week ago

Question

What is Ohm's law and also tell about Snell's law?

Answered: 1 week ago

Question

9. Describe the characteristics of power.

Answered: 1 week ago