GUYS IF YOU CANT HELP JUST ASK ME A QUESTION, DONT POST WHAT YOU HAVE THEN LEAVE
ID: 3761406 • Letter: G
Question
GUYS IF YOU CANT HELP JUST ASK ME A QUESTION, DONT POST WHAT YOU HAVE THEN LEAVE. THE LAST GUY ONLY PUT ONE OR TWO FUNCTIONS THEN LEFT, IM ALMOST OUT OF QUESTIONS. TAKE YOUR TIME. NO HURRY.
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 information from 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:
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. FOCUS ON THE MAIN AND OTHER FUNCTIONS ***
The Main Function:
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, which ends 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 call the saveCreaturesToFile function and then end. If they choose no, then your program should just end.
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 first check to make sure the number of creatures isn’t 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 function should 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 user’s 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 of the Creature members are strings, so that won’t 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 in the 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 the Creatures 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 creature was 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 that is 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 cannot find 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 the left. 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 following options:
Print Creatures to the Screen.
Print Creatures to a File.
Validate the user’s 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 format After 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 Episode 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 this after choosing 4 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 creatures to. 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 insert it 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. Take your time.
Explanation / Answer
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
#include<sstream>
using namespace std;
void enterCreatures(struct Creatures, struct Cost);
void printCreatures();
void printStatistics();
void saveCreaturesToFile();
struct Cost
{
float numHours[50];
double costPerHour[50];
float foodCost[50];
float supplyCost[50];
};
struct Creatures
{
string name[50];
string description[50];
float avgLength[50];
float avgHeight[50];
string location[50];
bool dangerous[50];
}
Cost;
int main()
{
bool goAgain = true;
int choice;
cout << "Welcome to the Magical Creature Zoo Management Program! ";
while (goAgain == true)
{
cout << "What would you like to do?" << endl;
cout << " 1. Enter some Magical Creatures." << endl;
cout << " 2. List/Print Creatures." << endl;
cout << " 3. Print Statistics on Creature Cost." << endl;
cout << " 4. End Program." << endl;
cout << " Enter 1,2,3 or 4." << endl;
cout << "Choice: ";
cin >> choice;
cout << endl;
if (choice == 1)
{
enterCreatures(Creatures, Cost);
}
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)
{
int choice;
fstream file;
char fileName[26];
cout << "What do you want to do?" << endl;
cout << " 1. Load my creatures from a file." << endl;
cout << " 2. 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 << " could not be opened." << endl << endl;
}
else
{
cout << "All creatures from " << fileName << " have been added to the program." << endl << endl;
}
}
bool addAnother = true;
Creatures creatureInfo;
Cost a;
int x =0;
while (addAnother == true)
{
if (choice == 2)
{
cout << endl << endl;
cin.ignore();
cout << "Name: ";
cin.getline(creatureInfo.name[x], 50);
cout << endl << endl;
cout << "Description: ";
cin.getline(creatureInfo.description[x], 2500);
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();
cin.getline(creatureInfo.location[x], 50);
cout << endl << endl;
cout << "Is it a dangerous creature? (y or n): ";
cin >> creatureInfo.dangerous[x];
cout << endl << endl;
cout << "How many hours do you spend caring for the " << creatureInfo.name[x] << " ?" << endl;
cout << "Number of hours: ";
cin >> a.numHours[x];
cout << endl << endl;
cout << "What is the cost per hour for caring for the " << creatureInfo.name[x] << " ?" << endl;
cout << "Cost per hour: ";
cin >> a.costPerHour[x];
cout << endl << endl;
cout << "How much money do you spend on food for the " << creatureInfo.name[x] << " ?" << endl;
cout << "Food cost: ";
cin >> a.foodCost[x];
cout << endl << endl;
cout << "How much money do you spend on grooming and medical supplies for the " << creatureInfo.name[x] << " ?" << endl;
cout << "Supply Cost: ";
cin >> a.supplyCost[x];
}
}
}
void printCreatures()
{
}
void printStatistics()
{
}
void saveCreaturesToFile()
{
}
float convertToFloat (string s)
{
istringstream i(s);
float x;
if (!(i >> x))
x = 0;
return x;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.