My professor gave me an assignment and I am totally lost. It was due yesterday and she still is not answering any of my emails. If any one can help it would be greatly appreciated. I will copy the instructions below and I may have to put my code that I have on the comments if I don't have enough room.....
PROBLEM: The Apothecary Shop. (20 pts)
Write the Apothecary Shop program. The shop owner needs a program to read in the shops
inventory, display all the current items and display an index of the current items available. Create a
menu to allow the user to display the items, the index or exit. The menu should loop until user is
ready to exit.
The program must use the functions defined below under Constraints. See Pseudo code for how the
main function will run.
You must use the two input files provided for you by your instructor for this project.
Input Validation: The program must check to see if the user enters a valid menu option.
SAMPLE OUTPUT:
*****************************************************************
The Apothecary Shop
This program will read in the shop’s
Data and Display that data, along with its associated
index table.
Program Developed by: "Kendall"
*****************************************************************
Inventory Menu
-----------------------------
1. Display all inventory items
2. Display index of inventory items
3. Exit
<<<<<<<<<<<<< Inventory >>>>>>>>>>>>>
Inventory Menu
------------------
1. Display all inventory items
2. Display index of inventory items
3. Exit
*****************************************************************
The Apothecary Shop
This program will read in the shop’s
Data and Display that data, along with its associated
index table.
Program Developed by: "Kendall"
*****************************************************************
Inventory menu
-----------------
1. Display all inventory items
2. Display index of inventory items
3. Exit
A, A, B, B, C, C, E, E, F, F, G, G, G, G, G, M, M, S, S, V, W
Inventory menu
-----------------
1. Display all inventory items
2. Display index of inventory items
3. Exit
Inventory menu
-----------------
1. Display all inventory items
2. Display index of inventory items
3. Exit
Invalid menu item entered... Enter a value from 1-3 >>
Inventory menu
-----------------
1. Display all inventory items
2. Display index of inventory items
3. Exit
Thank you for visiting the Apothecary Shop...
Partial PSEUDO-CODE for main function - (one of many ways you can do your program)
Homework Assignment 6 Pool
COP2000 HOMEWORK ASSIGNMENT 7B 4
1. Declare and initialize your variables, this includes you arrays. Create your 1D arrays to store
your inventory names, inventory cost and the index of the inventory items. Create the 1D
arrays so that they will be able to store all the items in inventory. You will use a Boolean value
as a “flag” to indicate when you will exit the program whether it is because you did not read in
the file or the user wishes to exit.
2. Call the copyRightInfo() function
3. Call the readData() function – Do not forget to capture the returned value a bool, your flag
4. If flag is true call the mkIndex() function
5. Start While loop only if flag is true (Hint: the flag is the Boolean variable you declared, your flag)
i. Call the displayMenu function()
ii. Read in the menu input
iii. Validate the menu input using a switch or series of if statements for each case 1, 2 or 3
1. Case 1
a. Call the displayData() function
2. Case 2
a. display the index array with a for loop
3. Case 3
a. output an Exit Message
b. set bool flag to false
4. Default/Not 1-3
a. output an Error Message
6. End While Loop
CONSTRAINTS:
• NO GLOBAL VARIABLES ALLOWED. (Automatic -10)
- Note: This means that all your arrays must be declared inside of main.
• You must use: int main()
• The program must use local variables. (2 pts)
• All functions MUST be called by main. (3 pts)
• Output must be formatted properly and correct. (3 pts)
• Include a comment at the beginning of the program stating the purpose of the program,
your name, the date, and your class (1pt is for code organization and use of whitespace). (2
pts) This program MUST use the following functions: (10 pts)
NAME YOUR FUNCTIONS AS SHOWN BELOW (- 10 if not named correctly):
void displayMenu () - (1 pts) is passed no arguments and its only purpose is to display the
menu for the Apothecary shop program.
1. Display all inventory items
2. Display index of inventory items
3. Exit
Homework Assignment 6 Pool
COP2000 HOMEWORK ASSIGNMENT 7B 5
bool readData(string inventoryNames[], float inventoryCost[]) – (3 pts) is passed the 1D
array variables of the inventory items and the cost of the inventory items from main. The
read data function will open the Apothecary_Inventory.txt file and read in the inventory
data to the two 1D arrays respectively.
Note: Remember to close your file after you have read in all the data.
This function returns true or false to the main function after the it has completed if the file
was read in successfully or not. If the file was not read in successfully the program should
exit.
void displayData (string inventoryNames[], float inventoryCost[]) - (3 pts) is passed the 1D
array variables of the inventory items and the cost of the inventory items from main. The
displayData function must display all the inventory items available in a table format with
dollar signs and two decimal place precision for dollar values.
void mkIndex(string inventoryNames[], char index[])-(2 pts) ) is passed the 1D array
variables of the inventory items and the index from main. This function will pull the first
letter of each item from the inventoryNames array into the index array.
void copyRightInfo() - (1 pts) is NOT passed any values and returns no value. This function
outputs a description of the program and your information. Fill in your name as the
developer's name (i.e. replace "PUT YOUR NAME HERE" with your name).
*****************************************************************
The Apothecary Shop
This program will read in the shop’s
Data and Display that data, along with its associated
index table.
Program Developed by: "PUT YOUR NAME HERE"
*****************************************************************
WRITE THE PROGRAM:
Write the program according to your Algorithm or Pseudo Code for the Problem above.
HINTS:
Reading Data from a File – Pg 278- 284
Testing for File Open Errors – pg 285
Must include the <fstream> library
Homework Assignment 6 Pool
COP2000 HOMEWORK ASSIGNMENT 7B 6
Make sure you close your file using the .close() member function (pg 273). You should only do this
after you have finish process all the data from the file; i.e. at the end of the readData function.
To display the contents of a 1D array you will need one for loop. Look at program 7-2
Reading data from a File into an Array – Pg 392 – 393
readData() - Use the getline() function (see pg 171, program 3-19)
Ex: getline(cin, myString); //myString is the variable, cin is the input stream we are reading from
//you will use your file pointer instead of cin
displayData() - To format your data like a table use the <iomanip> library and the setw() function, for
example:
cout << setw(20) << Name << setw(5) << right <<"$" << Dollars << endl;
mkIndex() - To pull and individual letter from your string think of the string as a 2D char
array that each row is name of the item in inventory and the column represents each
letter. Use this fact to get just the first letter of the string and assign it to your character
index array.
CHECK THE PROGRAM:
• Does the program meet the Constraints stated above?
• Is the program displaying the output properly? Is the program formatted
correctly?
return 0;
}
//Definitions
void displayMenu()
{
//copy and paste menu from blackboard and output - fix with c++ syntax
}
bool readData(string inventoryNames[], float inventoryCost[]);
{
bool readFile = false;
//Finish all the code Program 7-7
//create and initailize your loop counter
//create your input file pointer - i.e. ifstream
//open the file - the file with strings
//test to see if file exists - if (fileName)
//if test is true then you want to loop and read in all values from file
//dont forget to use getline(filePointer, YourArray[index])
//close your file
//initialize your loop counter
//create your input file pointer - i.e. ifstream for your inventory costs
//open the file - the file with float values
//test to see if file exists - if (fileName)
//if test is true then you want to loop and read in all values from file
//using regulare >>
//close your file
return readFile;
}
void displayData(string inventoryNames[], float inventorCost[]);
{
//Display output title
//Print all the elements the inventoryNames and inventorCost - hint you only need the one for loop/one output line
//Can reference Program 7-2 "Display the contents of the array"
}
void mkIndex(string inventoryNames[], char index[]);
{
//creat a for loop to go through each element
//assign the index element kount to the first letter of inventory Names kount
}
void copyRightInfo();
{
//Copy info from Blackboard, update with your name and update with C++ syntax
}
The shop owner needs a program to read in the shops inventory, display all the current items and display an index of the current items available. Create a menu to allow the user to display the items, the index or exit. The menu should loop until user is ready to exit.
This is an important bit; it tells you exactly what the program should do. And with these more complex programs, they usually give you an outline of code to follow, as they have.
Don't try to tackle the whole program at once, you'll end up feeling like you have no idea where to even start. The section I quoted splits it up nicely and in the order to do them:
•Display current items/Display index of available items.
•Create a Menu that has the options: Display Items, Display Index, and Exit
•Loop The Menu
Now, to display the data, you have to take in the data - hence the readData() function. Once the data is saved in a string, you then make it accessible through the displayData() function. And the data should also be "indexed" through the index function.
This part describes how each function should behave:
void displayData (string inventoryNames[], float inventoryCost[]) - (3 pts) is passed the 1D
array variables of the inventory items and the cost of the inventory items from main. The
displayData function must display all the inventory items available in a table format with
dollar signs and two decimal place precision for dollar values.
void mkIndex(string inventoryNames[], char index[])-(2 pts) ) is passed the 1D array
variables of the inventory items and the index from main. This function will pull the first
letter of each item from the inventoryNames array into the index array.
void copyRightInfo() - (1 pts) is NOT passed any values and returns no value. This function
outputs a description of the program and your information. Fill in your name as the
developer's name (i.e. replace "PUT YOUR NAME HERE" with your name).
Just start coding it, that's the important part. Have your starting point and start doing. You have to make sure you do it the way the professor specifies - but I personally like coding it first and then altering it to their specifications afterwards; you should do what's more comfortable for you.
If when coding you find yourself stuck somewhere in particular, feel free to post another question.
EDIT: At the beginning of your code put [.code] and at the end put [./code] (Without The Periods). It'll make everyone's life easier.