For this assignment you have been hired to design a program to manage a fish sto
ID: 3565935 • Letter: F
Question
For this assignment you have been hired to design a program to manage a fish store. As with Programming Assignment 1 your program will be menu driven. Here is your menu:
1. View Fish Inventory
2. Read Fish Inventory from a File
3.Write Fish Inventory to a File
4. Add Fish to Inventory
5. Remove Fish from Inventory
6.Search for Fish
7.Update Quantity
8.Update Tank/Location
9.Exit
You will be using a structured data (struct) to represent your fish. The Tag for this struct is Fish. Here is the data members for this struct (along with the data types):
Fish Name (string) [remember that this can have spaces in it!]
Tank (int) [represents what tank the fish are in]
Quantity (int)
Price (double)
Since you will have multiple fish at your business I want you to store all of your fish in an array. Notice that this will be an array of Fish (i.e. Fish myInventory[size]). You will use a partially filled array with a MAX_SIZE declared as a local constant of size 100. Don't forget that since it is a partially filled array you need to keep track of something else as well! For the menu options, here is what I would like you to do:
View Fish Inventory: Display all of the fish in an easy to read format. I want you to display all of the fish's member data (i.e. name, location, quantity, price).
Read Fish Inventory from a File: The user will provide a file name and you will add the contents to your array. Remember that your array could already have some fish in it, so you need to add the new fish to the end. See the attached .dat file for the format that you will be using for your data files. You will then you will sort the entire array by fish name.
Write Fish Inventory to a File: The user will provide a file name and if it already exists you will overwrite it. You will then write out the entire array to a .dat file using the same format that is used for reading the file.
Add Fish to Inventory: You will ask the user for all of the fish's information (name, location, price, quantity) and then add that fish to array (at the end), then you will sort the array by fish name.
Remove Fish from Inventory: You will display the inventory, then ask the user for the index number (remember off-by one errors) that they wish to remove from the array.
Search for Fish: You will ask the user for the name of the fish they want to search for, then if found you will provide them with the location [tank number], quantity, and price. If not found you will display an appropriate error message.
Update Quantity: You will display the inventory, then ask for the index. Then display just that fish, and ask what to do. This implies a sub-menu. If they select the new total quantity you will read in an int and ensure it is a positive number, if decrease or increase you will decrement (ensuring you don't go negative) or increment.
1.New total quantity,
2.Decrease by one [i.e. one was sold]
3.Increase by one [i.e. one was returned].
Update Tank/Location: You will display the inventory, then ask for the index. Once that is inputted you will display the current tank location and then ask for the new location.
Exit: Before exiting you will sort the array and write it to a file [following the requirements in option 3].
This is a function based system, so I want to see you reusing your functions as much as possible. Each function will take exactly 3 parameters: the array, the max size, and the current array size. All of the work will be done in the individual functions. This means that main will simply:
Display the menu (again a function),
Read the choice,
Enter a switch/if-else-if loop,
and Call the functions that correspond to the actions selected.
For example:
int main ( )
{
... // all of your local variables are declared here
displayMenu( );
cout << " Please select an option: ";
cin >> choice;
switch (choice)
{
case 1: displayInventory(myArray, MAX_SIZE, currentSize);
break;
case 2: readInventory(myArray, MAX_SIZE, currentSize);
break;
...
}
return 0;
}
Explanation / Answer
#include <iostream>
#include <ctime>
#include <fstream>
#include <string>
using namespace std;
int size;
#define Maxsize 100;
struct Fish
{
string fishName;
int tank;
int quantity;
double price;
};
void ReadFish(struct Fish myInventory[])
void WriteFish(struct Fish myInventory[])
void ViewFish(struct Fish myInventory[])
void AddFish(struct Fish myInventory[])
void RemoveFish(struct Fish myInventory[])
void searchFish(struct Fish myInventory[])
int main()
{
size = 0;
struct Fish myInventory[Maxsize];
ReadFish( myInventory[])
WriteFish( myInventory[])
ViewFish( myInventory[])
AddFish( myInventory[])
RemoveFish( myInventory[])
searchFish( myInventory[])
}
void ReadFish(struct Fish myInventory[])
{
ifstream in_stream;
in_stream.open("");
while(!in_stream.eof())
{
in_stream >> myInventory[i].fishName >> myInventory[i].tank >> myInventory[i].quantity >> myInventory[i].price;
cout << myInventory[i].fishName << myInventory[i].tank << myInventory[i].quantity << myInventory[i].price;
size ++;
}
in_stream.close();
}
void WriteFish(struct Fish myInventory[])
{
int i=0;
ofstream out_stream;
out_stream.open("output.txt");
while(i<size)
{
out_stream >> myInventory[i].fishName >> myInventory[i].tank >> myInventory[i].quantity >> myInventory[i].price;
i++;
}
out_stream.close();
}
void ViewFish(struct Fish myInventory[])
{
int i=0;
while(i<size)
{
cout << myInventory[i].fishName << myInventory[i].tank << myInventory[i].quantity << myInventory[i].price;
i++;
}
}
void AddFish(struct Fish myInventory[])
{
size ++;
cout << "Enter Fish Name";
MyInventory[size].fishName;
cout << "Enter the tank";
MyInventory[size].tank;
cout << "Enter the quantity";
MyInventory[size].quantity;
cout << "Enter the price";
MyInventory[size].price;
}
void RemoveFish(struct Fish myInventory[])
{
int i;
cout <<"Enter the index";
cin >> i;
myInventory[i] = NULL;
}
void searchFish(struct Fish myInventory[])
{
int i=0;
cout << "Enter the name";
string str;
cin >> str;
while(i<size)
{
if(str.equals(myInventory[i].fishName))
cout << myInventory[i].fishName << myInventory[i].tank << myInventory[i].quantity << myInventory[i].price;
i++;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.