I need help with the following C++ program:
Write a complete C++ program called inventory.cpp as described below. Documentation is required; see next page. Write an interactive program for processing inventory information for a parts warehouse. When started, the program should read in from a text file used for storing information between sessions. It is possible that the text file is empty. The program user is then given five choices in the main menu: enter a new part to the system, find and print data for a part when given the part ID number, find and modify data for a part when given the part ID number, copy all information to a binary archive file, and quit. These choices will be explained more fully below. While the program is running, all parts information should be in the main memory for fast response. You may assume that there will always be enough space in memory to do this. Specifications: For each part, you need to store its ID (an integer), a short text description, its price, and a count of how many of that part the warehouse currently has. You are given two files Part.h and Part.cpp that hold the declarations and definitions for a simple Part class that holds just the ID, and the text description. You can revise the files as needed for this assignment. When the program first starts, it reads in the information is stored in a text file called textSave.txt. You may assume that such a file always exists, but may be empty. The program should now print a menu and ask the user to enter one of the following letters corresponding to the 4 choices below. The program will do the appropriate task, and keep repeating (get choice, do task) until the option Q is chosen, N: this stands for a new part. The program should ask the user to enter the part ID and the rest of the part information. The program will then enter the new part information into the system. F: this stands for finding a particular part. The program will ask for a part ID number, and search the system for a part with that ID. If it is found, the program will display the ID and all other information about the part to the screen. If it is not found, the program will print a message to the screen, telling the user that it could not be found. A: This stands for archiving the information. Everything is output to a binary file called binarySave.dat. Any previous file of that name will be overwritten. Q: this stands for quit. The program will write all the current parts information into the text file textSave.txt, overwriting any previous data before quitting. Design considerations: You do not need to be concerned with speed when reading from or writing to the files. However, you should try to make the other tasks run quickly. You may choose any format for the two save files, as long as they contain all the information and can be read and written by your program as text (for textSave.txt) and written as binary (for binarySave.dat). Resources: In addition to the two files Part.h and Part.cpp, you are given files containing templates for a Stack class, a Queue class, and a Tree class (this implements a binary search tree). For each of the three data structures, you are also provided with a test program. All function bodies are given. You may use none, any, or all of them if it will help you. You are also free to revise any of these files if you wish. You should rename your file inventory.cpp and turn it in through the class Titanium site. Remember to put in your name and ID at the start of the file. 7 Please also turn in all additional files, old, new, or revised, that your program uses, to the file names. Required documentation: Your name and ID at the top for each file you write or revise. Pseudocode for your inventory.cpp. This can be turned in as a separate file (Word or plain text) or as a long comment at the beginning of the C++ file. If any variable name does not make it immediately clear what its role is, that variable must have documentation whenever it is used. All functions, including the main, must have a brief documentation that states what the function does, and the roles played by each of the parameters, if any. Other documentation is optional. Any unusual or tricky code should be documented, but please do not just repeat the code. For example, you do not need to say “for loop” because the code will say “for ( …)
Expert Answer
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include “part.cpp”
int main()
{
char t;
Part p;
fstream testfile;
top:
clrscr();
cout<<“Press N: for enter new partn”;
cout<<“Press F: for Finding partn”;
cout<<“Press A: for Archive to binaryn”;
cout<<“Press Q: for enter new partn”;
cin>>t;
switch(t)
{
case ‘N’:
case ‘n’:
if (!testfile)
{
cout << “Error opening file, creating a new filen”;
testfile.open(“textSave.txt”, ios::out);
}
else
testfile.open(“textSave.txt”, ios::app);
p.getPart();
testfile.write((char *)&p,sizeof(p));
testfile.close();
goto top;
case ‘f’:
case ‘F’:
int pid,t=0;
cout<<“Please Enter part Id “;
cin>>pid;
testfile.open(“textSave.txt”, ios::in);
while(testfile.read((char *)&p,sizeof(p)))
{
if(p.ID==pid)
{
t++;
break;
}
}
if(t==1)
{
cout<<“Item Foundn”;
p.print();
}
else
cout<<“No Item Foundn”;
getch();
testfile.close();
goto top;
case ‘a’:
case ‘A’:
testfile.open(“textSave.txt”, ios::in);
ofstream testbin;
testbin.open(“binarysave.dat”,ios::out|ios::binary);
while(testfile.read((char *)&p,sizeof(p)))
{
testbin.write((char *)&p,sizeof(p));
}
goto top;
case ‘q’:
case ‘Q’:
break;
}
return 0;
}