C++ Write a program that keeps track of inventory The data is located in the file Inventory.txt. While the program is running, the information should be stored in a linked list.
The information for each item needs be stored in a struct
The definition will be in a separate file called items.h
The total inventory will be stored in a linked list
The definition of the list class will be in a file called linkList.h
The program should be able to perform the following functions
Display the inventory in alphabetical order by name
Display the inventory in reverse alphabetical order
Add an item
Delete an item from inventory
Change any info for an item
Which means you have to be able to search for a particular item
The program will run until the user chooses an option to exit
The list is not in alphabetical order, so you will need to put it in order.
Whenever you change a name or if you add an item, the list must stay in order.
When you are done, the list will be output to a file called list.txt
Inventory.txt *************************************************************************************************************************************************************************************************** Telephoto-Pocket-Camera 54.95 15 20#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
const int SIZE=50;
struct CamLibrary
{
string cameraName;
int price1;
int price2;
int price3;
CamLibrary *next;
CamLibrary(string, int, int, int,CamLibrary*);
};
CamLibrary::CamLibrary(string tempcameraName,int tempprice1,int tempprice2,int tempprice3,CamLibrary* tempNext):cameraName(tempcameraName), price1(tempprice1), price2(tempprice2), price3(tempprice3), next(tempNext){}
typedef CamLibrary* CamLibraryPtr;
void getline(istream &stream, string &str, char
delimiter)
{ char temp[500];
stream.get(temp, 500, delimiter);
stream.ignore(500, delimiter);
str = temp;
}
void getline(istream &stream, int &num, char
delimiter)
{ int temp;
stream >> temp;
stream.ignore(500, delimiter);
num= temp;
}
CamLibraryPtr locatecamera(CamLibraryPtr temp, string
camName);
void readFile(CamLibraryPtr &root);
void insert(CamLibraryPtr &root);
void delCamera(CamLibraryPtr &root);
void searchCamera(CamLibraryPtr temp);
void saveFile(CamLibraryPtr temp);
int countNodes(CamLibraryPtr temp);
void insertionSort(struct CamLibrary **head_ref);
void printList(CamLibraryPtr temp);
int main()
{
int choice;
CamLibraryPtr root = NULL;
readFile(root);
printList(root);
do
{
cout << "Menu: Select your
option\n\n";
cout << "(1) Add a camera to
the list\n";
cout << "(2) Delete a camera
based on camera name\n";
cout << "(3) Search for a
camera by camera name.\n";
cout << "(4) List all cameras
in alphabetical order.\n";
cout << "(5)
Quit.\n\n";
cout << "Enter your choice
---> ";
cin >> choice;
if (1 <= choice &&
choice <= 5)
{
switch
(choice)
{
case 1:
insert(root);
printList(root);
break;
case 2:
delCamera(root);
printList(root);
break;
case 3:
searchCamera(root);
printList(root);
break;
case 4:
insertionSort(&root);
printList(root);
break;
default:
cout << "Invalid choice. Enter
again.\n\n";
break;
}
}
}
while (choice != 5);
saveFile(root);
return 0;
}
void readFile(CamLibraryPtr &root)
{
int numCameras;
string camName;
int price1,price2,price3;
ifstream infile("Inventory.txt", ios::in);
infile >> numCameras;
infile.ignore(500,'\n');
for (int count = 0; count < numCameras;
count++)
{
getline(infile, camName,
'\n');
getline(infile, price1,
'\n');
getline(infile,price2, '\n');
getline(infile,price3, '\n');
root = new
CamLibrary(camName,price1,price2,price3,root);
}
}
void insert(CamLibraryPtr &root)
{
string camName;
int price1,price2,price3;
cout << "Camera Name:\t\t\t";
cin.ignore(500,'\n');
getline(cin, camName, '\n');
cout << "Price 1:\t\t\t";
getline(cin, price1, '\n');
cout << "Price 2:\t\t";
getline(cin,price2, '\n');
cout << "Price 3:\t\t\t";
getline(cin,price3, '\n');
root = new CamLibrary
(camName,price1,price2,price3, root);
}
void delCamera(CamLibraryPtr &root)
{
string camName;
cout << "Camera Name:\t\t\t";
cin.ignore(500,'\n');
getline(cin, camName, '\n');
CamLibraryPtr p = locatecamera(root, camName);
if (p == NULL)
cout << "\nDeletion cannot be
done.\n\n";
else if (root == p)
root = p->next;
else
{
CamLibraryPtr q = root;
while (q->next != p)
q =
q->next;
q->next = p->next;
}
delete p;
}
CamLibraryPtr locatecamera(CamLibraryPtr temp, string
camName)
{
while (temp != NULL)
{
if (temp->cameraName ==
camName)
{
return
temp;
}
temp = temp->next;
}
return NULL;
}
void searchCamera(CamLibraryPtr temp)
{
string camName;
cout << "Camera Name:\t\t\t";
cin.ignore(500,'\n');
getline(cin, camName, '\n');
while (temp != NULL)
{
if (camName ==
temp->cameraName)
{
cout <<
temp->cameraName << "\n";
cout <<
temp->price1 << "\n";
cout <<
temp->price2 << "\n";
cout <<
temp->price3 << "\n\n";
}
temp = temp->next;
}
cout << "\n";
}
void sortedInsert(struct CamLibrary** head_ref, struct CamLibrary*
new_node)
{
struct CamLibrary* current;
/* Special case for the head end */
if (*head_ref == NULL || (*head_ref)->cameraName >=
new_node->cameraName)
{
new_node->next = *head_ref;
*head_ref = new_node;
}
else
{
/* Locate the node before the point of insertion */
current = *head_ref;
while (current->next!=NULL &&
current->next->cameraName < new_node->cameraName)
{
current = current->next;
}
new_node->next = current->next;
current->next = new_node;
}
}
void saveFile(CamLibraryPtr temp)
{
int count = countNodes(temp);
ofstream outFile("list.txt",ios::out);
outFile << count << "\n";
while (temp != NULL)
{
outFile <<
temp->cameraName << "\n";
outFile << temp->price1
<< "\n";
outFile << temp->price2
<< "\n";
outFile << temp->price3
<< "\n";
temp = temp->next;
}
cout << "\n";
}
int countNodes(CamLibraryPtr temp)
{
int countB = 0;
while (temp != NULL)
{
countB++;
temp = temp->next;
}
return countB;
}
void insertionSort(struct CamLibrary **head_ref)
{
// Initialize sorted linked list
struct CamLibrary *sorted = NULL;
// Traverse the given linked list and insert every
// node to sorted
struct CamLibrary *current = *head_ref;
while (current != NULL)
{
// Store next for next iteration
struct CamLibrary *next = current->next;
// insert current in sorted linked list
sortedInsert(&sorted, current);
// Update current
current = next;
}
// Update head_ref to point to sorted linked list
*head_ref = sorted;
}
void printList(CamLibraryPtr temp)
{
while (temp != NULL)
{
cout << temp->cameraName
<< "\n";
cout << temp->price1
<< "\n";
cout << temp->price2
<< "\n";
cout << temp->price3
<< "\n";
temp = temp->next;
}
cout << "\n";
}
C++ Write a program that keeps track of inventory The data is located in the file Inventory.txt. ...
In C++ General Description: For this project, you will write a program that keeps track of inventory for a camera store. The data is located in the file Inventory.txt on the S:\ drive. While the program is running, the information should be stored in a linked list. 1. The information for each item will be stored in a struct a. The definition will be in a separate file called item.h 2. The total inventory will be stored in a linked...
Use C++
For this week’s lab you will write a program to read a data file
containing numerical values, one per line. The program should
compute average of the numbers and also find the smallest and the
largest value in the file. You may assume that the data file will
have EXACTLY 100 integer values in it. Process all the values out
of the data file. Show the average, smallest, largest, and the name
of the data file in the...
Accounting Question (Fringe Benefits) You are the Tax Director of a large public company. The CFO is very frugal and is looking for fringe benefits that will be viewed favorably and provide incentives to employees and executives, but perhaps not cost the company very much. A consultant has provided the CFO a list of the following possible employee fringe benefits, and has claimed that all the benefits are tax free to the employee and deductible to the company. (He does...
Write a C program for:
One technique for dealing with deadlock is called “detect and
recover.” In this scheme, some procedure is used
to identify when a deadlock occurs, and then another procedure
is used to deal with the blocked processes. One technique to
identify a deadlock is to maintain a resource graph that identifies
all processes, all resources, and the relationships between them
(that is, which processes exclusively own which resources, and
which processes are blocked waiting for which...
Write a c++ program: Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX_ROWS = 10; const int MAX_COLS = 10; class MatrixType { public: MatrixType(); void MakeEmpty(); void SetSize(int rowsSize, int colSize); void StoreItem(int item, int row, int col); void Add(MatrixType otherOperand, MatrixType& result); void Sub(MatrixType otherOperand, MatrixType& result); void Mult(MatrixType otherOperand, MatrixType& result); void Print(ofstream& outfile); bool AddSubCompatible(MatrixType otherOperand); bool MultCompatible(MatrixType otherOperand);...
Digital world is a retail store that sells cameras and photography
supplies the firms credit purchases and purchases returns and
allowance transactions for June 2019 appear below along with the
general ledger account used to record these transactions the
balance shown in accounts payable is for the beginning of June.
what amount is owed to nano glass on June 30?
Digital World is a retail store that sells cameras and photography supplies. The firm's credit purchases and purchases returns and...
Digital world is a retail store that sells cameras in photography
supplies the firms credit purchases and purchases returns and
allowances transactions for June 2019 appear below along with the
general ledger account used to record these transactions the
balance shown in the accounts payable is for the beginning of
June
Digital World is a retail store that sells cameras and photography supplies. The firm's credit purchases and purchases returns and allowances transactions for June 2019 appear below, along with...
Please use own words. Thank you.
CASE QUESTIONS AND DISCUSSION > Analyze and discuss the questions listed below in specific detail. A minimum of 4 pages is required; ensure that you answer all questions completely Case Questions Who are the main players (name and position)? What business (es) and industry or industries is the company in? What are the issues and problems facing the company? (Sort them by importance and urgency.) What are the characteristics of the environment in which...